From cd82fd7ec1654d082f78183102a5b4378358734a Mon Sep 17 00:00:00 2001 From: Zlash65 Date: Fri, 22 Dec 2017 15:05:57 +0530 Subject: [PATCH 1/3] doctypes will be visible based on enabled roles --- frappe/contacts/address_and_contact.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frappe/contacts/address_and_contact.py b/frappe/contacts/address_and_contact.py index 9ccffab996..1756b00d9b 100644 --- a/frappe/contacts/address_and_contact.py +++ b/frappe/contacts/address_and_contact.py @@ -146,4 +146,11 @@ def filter_dynamic_link_doctypes(doctype, txt, searchfield, start, page_len, fil order_by="dt asc", as_list=True) all_doctypes = doctypes + _doctypes - return sorted(all_doctypes, key=lambda item: item[0]) + + user_roles = frappe.db.get_all('Has Role', {'parent': frappe.session.user}, 'role', as_list=True) + valid_doctypes = frappe.db.get_all('DocPerm', { + 'parent': ('in', [ctype[0] for ctype in all_doctypes]), + 'role': ('in', [role[0] for role in user_roles]) + }, 'distinct parent', as_list=True) + + return sorted(valid_doctypes, key=lambda item: item[0]) From ac1586a9726483f8322c444285ce7f6bc50d6189 Mon Sep 17 00:00:00 2001 From: Zlash65 Date: Mon, 25 Dec 2017 18:11:47 +0530 Subject: [PATCH 2/3] check in custom docperm --- frappe/contacts/address_and_contact.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/frappe/contacts/address_and_contact.py b/frappe/contacts/address_and_contact.py index 1756b00d9b..eda35d61f9 100644 --- a/frappe/contacts/address_and_contact.py +++ b/frappe/contacts/address_and_contact.py @@ -147,10 +147,17 @@ def filter_dynamic_link_doctypes(doctype, txt, searchfield, start, page_len, fil all_doctypes = doctypes + _doctypes + valid_doctypes = [] user_roles = frappe.db.get_all('Has Role', {'parent': frappe.session.user}, 'role', as_list=True) - valid_doctypes = frappe.db.get_all('DocPerm', { - 'parent': ('in', [ctype[0] for ctype in all_doctypes]), + for ctype in all_doctypes: + if frappe.db.exists('Custom DocPerm', {"parent": ctype[0]}): + dtype = 'Custom DocPerm' + else: + dtype = 'DocPerm' + + valid_doctypes.append(frappe.db.get_all(dtype, { + 'parent': ctype[0], 'role': ('in', [role[0] for role in user_roles]) - }, 'distinct parent', as_list=True) + }, 'distinct parent', as_list=True)) return sorted(valid_doctypes, key=lambda item: item[0]) From 40ddb3c80db5b5019f5338b3678d3009b9cda1c5 Mon Sep 17 00:00:00 2001 From: Zlash65 Date: Tue, 26 Dec 2017 22:08:11 +0530 Subject: [PATCH 3/3] use frappe.get_roles --- frappe/contacts/address_and_contact.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frappe/contacts/address_and_contact.py b/frappe/contacts/address_and_contact.py index eda35d61f9..fc938244f7 100644 --- a/frappe/contacts/address_and_contact.py +++ b/frappe/contacts/address_and_contact.py @@ -148,7 +148,7 @@ def filter_dynamic_link_doctypes(doctype, txt, searchfield, start, page_len, fil all_doctypes = doctypes + _doctypes valid_doctypes = [] - user_roles = frappe.db.get_all('Has Role', {'parent': frappe.session.user}, 'role', as_list=True) + user_roles = frappe.get_roles() for ctype in all_doctypes: if frappe.db.exists('Custom DocPerm', {"parent": ctype[0]}): dtype = 'Custom DocPerm' @@ -157,7 +157,7 @@ def filter_dynamic_link_doctypes(doctype, txt, searchfield, start, page_len, fil valid_doctypes.append(frappe.db.get_all(dtype, { 'parent': ctype[0], - 'role': ('in', [role[0] for role in user_roles]) + 'role': ('in', user_roles) }, 'distinct parent', as_list=True)) return sorted(valid_doctypes, key=lambda item: item[0])