Skip to content

Commit

Permalink
fix: filter select perm in get_doctypes_with_read
Browse files Browse the repository at this point in the history
closes frappe#26015

Extracted from frappe#26018
  • Loading branch information
ankush committed Apr 18, 2024
1 parent 1dcfadf commit a1bb734
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion frappe/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def has_controller_permissions(doc, ptype, user=None, debug=False) -> bool:


def get_doctypes_with_read():
return list({cstr(p.parent) for p in get_valid_perms() if p.parent})
return list({cstr(p.parent) for p in get_valid_perms() if p.parent and p.read})


def get_valid_perms(doctype=None, user=None):
Expand Down
9 changes: 9 additions & 0 deletions frappe/tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import frappe
import frappe.defaults
import frappe.model.meta
from frappe.core.doctype.doctype.test_doctype import new_doctype
from frappe.core.doctype.user_permission.user_permission import clear_user_permissions
from frappe.core.page.permission_manager.permission_manager import reset, update
from frappe.desk.form.load import getdoc
Expand All @@ -17,6 +18,7 @@
add_user_permission,
clear_user_permissions_for_doctype,
get_doc_permissions,
get_doctypes_with_read,
remove_user_permission,
update_permission_property,
)
Expand Down Expand Up @@ -736,3 +738,10 @@ def assertHasRole(*roles: str | tuple[str, ...]):
)
frappe.set_user(system_user)
assertHasRole(GUEST_ROLE, ALL_USER_ROLE, SYSTEM_USER_ROLE)

def test_get_doctypes_with_read(self):
with self.set_user("Administrator"):
doctype = new_doctype(permissions=[{"select": 1, "role": "_Test Role", "read": 0}]).insert().name

with self.set_user("test@example.com"):
self.assertNotIn(doctype, get_doctypes_with_read())

0 comments on commit a1bb734

Please sign in to comment.