diff --git a/frappe/core/doctype/doctype/doctype.js b/frappe/core/doctype/doctype/doctype.js index 2b06d86553..c8eae0073b 100644 --- a/frappe/core/doctype/doctype/doctype.js +++ b/frappe/core/doctype/doctype/doctype.js @@ -17,9 +17,7 @@ frappe.ui.form.on('DocType', { if (doc.custom && frappe.session.user != 'Administrator') { return { query: "frappe.core.doctype.role.role.role_query", - filters: { - name: ['not in', ['All']] - } + filters: [['Role', 'name', '!=', 'All']] }; } }); diff --git a/frappe/core/doctype/role/role.py b/frappe/core/doctype/role/role.py index bacd2e5274..a1523db0dd 100644 --- a/frappe/core/doctype/role/role.py +++ b/frappe/core/doctype/role/role.py @@ -33,7 +33,7 @@ class Role(Document): # set if desk_access is not allowed, unset all desk properties if self.name == 'Guest': self.desk_access = 0 - + if not self.desk_access: for key in desk_properties: self.set(key, 0) @@ -78,9 +78,9 @@ def get_users(role): @frappe.whitelist() @frappe.validate_and_sanitize_search_inputs def role_query(doctype, txt, searchfield, start, page_len, filters): - filters.update({ - 'is_custom': 0, 'name': ('like', '%{0}%'.format(txt)) - }) + report_filters = [['Role', 'name', 'like', '%{}%'.format(txt)], ['Role', 'is_custom', '=', 0]] + if filters and isinstance(filters, list): + report_filters.extend(filters) return frappe.get_all('Role', limit_start=start, limit_page_length=page_len, - filters=filters, as_list=1) \ No newline at end of file + filters=report_filters, as_list=1) \ No newline at end of file diff --git a/frappe/core/doctype/user_document_type/user_document_type.json b/frappe/core/doctype/user_document_type/user_document_type.json index 36257a21ef..0f4d2373fd 100644 --- a/frappe/core/doctype/user_document_type/user_document_type.json +++ b/frappe/core/doctype/user_document_type/user_document_type.json @@ -90,7 +90,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-01-28 15:37:47.759595", + "modified": "2021-03-12 12:51:51.775950", "modified_by": "Administrator", "module": "Core", "name": "User Document Type", diff --git a/frappe/core/doctype/user_type/user_type.js b/frappe/core/doctype/user_type/user_type.js index 74f351edbb..c8bd499b58 100644 --- a/frappe/core/doctype/user_type/user_type.js +++ b/frappe/core/doctype/user_type/user_type.js @@ -7,7 +7,7 @@ frappe.ui.form.on('User Type', { frm.set_df_property('is_standard', 'read_only', !frappe.boot.developer_mode); const fields = ['role', 'apply_user_permission_on', 'user_id_field', - 'user_doctypes', 'select_doctypes', 'user_type_modules']; + 'user_doctypes', 'user_type_modules']; frm.toggle_display(fields, !frm.doc.is_standard); @@ -27,6 +27,14 @@ frappe.ui.form.on('User Type', { }; }); + frm.set_query('document_type', 'custom_select_doctypes', function() { + return { + filters: { + istable: 0 + } + }; + }); + frm.set_query('role', function() { return { filters: { diff --git a/frappe/core/doctype/user_type/user_type.json b/frappe/core/doctype/user_type/user_type.json index 6b4a13b2e6..9ea5d5be71 100644 --- a/frappe/core/doctype/user_type/user_type.json +++ b/frappe/core/doctype/user_type/user_type.json @@ -14,6 +14,7 @@ "user_id_field", "section_break_6", "user_doctypes", + "custom_select_doctypes", "select_doctypes", "allowed_modules_section", "user_type_modules" @@ -36,7 +37,8 @@ "fieldtype": "Table", "label": "Document Types", "mandatory_depends_on": "eval: !doc.is_standard", - "options": "User Document Type" + "options": "User Document Type", + "read_only": 1 }, { "fieldname": "role", @@ -44,13 +46,16 @@ "in_list_view": 1, "label": "Role", "mandatory_depends_on": "eval: !doc.is_standard", - "options": "Role" + "options": "Role", + "read_only": 1 }, { "fieldname": "select_doctypes", "fieldtype": "Table", + "hidden": 1, "label": "Document Types (Select Permissions Only)", - "options": "User Select Document Type" + "options": "User Select Document Type", + "read_only": 1 }, { "fieldname": "column_break_4", @@ -62,7 +67,8 @@ "fieldtype": "Link", "label": "Apply User Permission On", "mandatory_depends_on": "eval: !doc.is_standard", - "options": "DocType" + "options": "DocType", + "read_only": 1 }, { "depends_on": "eval: !doc.is_standard", @@ -75,7 +81,8 @@ "fieldname": "user_id_field", "fieldtype": "Select", "label": "User Id Field", - "mandatory_depends_on": "eval: !doc.is_standard" + "mandatory_depends_on": "eval: !doc.is_standard", + "read_only": 1 }, { "depends_on": "eval: !doc.is_standard", @@ -90,11 +97,17 @@ "options": "User Type Module", "print_hide": 1, "read_only": 1 + }, + { + "fieldname": "custom_select_doctypes", + "fieldtype": "Table", + "label": "Custom Document Types (Select Permission)", + "options": "User Select Document Type" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-01-24 04:47:08.243320", + "modified": "2021-03-12 16:25:18.639050", "modified_by": "Administrator", "module": "Core", "name": "User Type", diff --git a/frappe/core/doctype/user_type/user_type.py b/frappe/core/doctype/user_type/user_type.py index 2176baa203..b97849bb4c 100644 --- a/frappe/core/doctype/user_type/user_type.py +++ b/frappe/core/doctype/user_type/user_type.py @@ -14,6 +14,7 @@ from frappe.model.document import Document class UserType(Document): def validate(self): self.set_modules() + self.add_select_perm_doctypes() def on_update(self): if self.is_standard: return @@ -98,17 +99,39 @@ class UserType(Document): for row in self.user_doctypes: docperm = add_role_permissions(row.document_type, self.role) - values = {perm:row.get(perm) for perm in perms} + values = {perm:row.get(perm) or 0 for perm in perms} for perm in ['print', 'email', 'share']: values[perm] = 1 frappe.db.set_value('Custom DocPerm', docperm, values) + def add_select_perm_doctypes(self): + if not frappe.flags.in_patch and not frappe.conf.developer_mode: return + + self.select_doctypes = [] + + select_doctypes = [] + user_doctypes = tuple([row.document_type for row in self.user_doctypes]) + + for doctype in user_doctypes: + doc = frappe.get_meta(doctype) + for field in doc.get_link_fields(): + if field.options not in user_doctypes: + select_doctypes.append(field.options) + + if select_doctypes: + select_doctypes = set(select_doctypes) + for select_doctype in select_doctypes: + self.append('select_doctypes', { + 'document_type': select_doctype + }) + def add_role_permissions_for_select_doctypes(self): - for row in self.select_doctypes: - docperm = add_role_permissions(row.document_type, self.role) - frappe.db.set_value('Custom DocPerm', docperm, - {'select': 1, 'read': 0, 'create': 0, 'write': 0}) + for doctype in ['select_doctypes', 'custom_select_doctypes']: + for row in self.get(doctype): + docperm = add_role_permissions(row.document_type, self.role) + frappe.db.set_value('Custom DocPerm', docperm, + {'select': 1, 'read': 0, 'create': 0, 'write': 0}) def add_role_permissions_for_file(self): docperm = add_role_permissions('File', self.role) @@ -121,8 +144,9 @@ class UserType(Document): # Do not remove the doc permission for the file doctype doctypes.append('File') - for dt in self.select_doctypes: - doctypes.append(dt.document_type) + for doctype in ['select_doctypes', 'custom_select_doctypes']: + for dt in self.get(doctype): + doctypes.append(dt.document_type) for perm in frappe.get_all('Custom DocPerm', filters = {'role': self.role, 'parent': ['not in', doctypes]}):