def test_not_allowed_to_remove_user_permissions(self): self.test_set_user_permissions() defname = get_permissions("*****@*****.**", "Blog Post", "-test-blog-post")[0].name frappe.set_user("*****@*****.**") # user cannot remove their own user permissions self.assertRaises(frappe.PermissionError, remove, "*****@*****.**", defname, "Blog Post", "-test-blog-post")
def test_not_allowed_to_remove_user_permissions(self): self.test_set_user_permissions() defname = get_permissions("*****@*****.**", "Blog Post", "_test-blog-post")[0].name frappe.set_user("*****@*****.**") # user cannot remove their own user permissions self.assertRaises(frappe.PermissionError, remove, "*****@*****.**", defname, "Blog Post", "_test-blog-post")
def user_emails_to_permissions(self, method=None): if frappe.session.user == "Administrator" or "System Manager" in frappe.get_roles(): from frappe.core.page.user_permissions.user_permissions import get_permissions permissions = set([x.defvalue for x in get_permissions(self.name, "Email Account")]) user_emails = set([x.email_account for x in self.user_emails]) # compare vs user emails add = user_emails - permissions remove = permissions - user_emails # set the difference for r in remove: frappe.permissions.remove_user_permission("Email Account", r, self.name) for a in add: frappe.permissions.add_user_permission("Email Account", a, self.name, with_message=True)