feat: Allow Setting email, share and print perms via User Type

- misc: Also hide email button if user does not have email perm on doctype (the btn in the menu is already taken care of)
This commit is contained in:
marination 2024-07-12 18:28:08 +02:00
parent f2f91d3067
commit cde3d0dfda
5 changed files with 58 additions and 12 deletions

View file

@ -16,7 +16,12 @@
"submit",
"cancel",
"amend",
"delete"
"delete",
"additional_permissions_section",
"email",
"column_break_fjuk",
"share",
"print"
],
"fields": [
{
@ -92,12 +97,39 @@
"fieldname": "delete",
"fieldtype": "Check",
"label": "Delete"
},
{
"fieldname": "additional_permissions_section",
"fieldtype": "Section Break",
"label": "Additional Permissions"
},
{
"default": "1",
"fieldname": "email",
"fieldtype": "Check",
"label": "Email"
},
{
"fieldname": "column_break_fjuk",
"fieldtype": "Column Break"
},
{
"default": "1",
"fieldname": "share",
"fieldtype": "Check",
"label": "Share"
},
{
"default": "1",
"fieldname": "print",
"fieldtype": "Check",
"label": "Print"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-03-23 16:04:00.313525",
"modified": "2024-07-12 17:32:15.721862",
"modified_by": "Administrator",
"module": "Core",
"name": "User Document Type",

View file

@ -19,11 +19,14 @@ class UserDocumentType(Document):
create: DF.Check
delete: DF.Check
document_type: DF.Link
email: DF.Check
is_custom: DF.Check
parent: DF.Data
parentfield: DF.Data
parenttype: DF.Data
print: DF.Check
read: DF.Check
share: DF.Check
submit: DF.Check
write: DF.Check
# end: auto-generated types

View file

@ -31,6 +31,18 @@ class TestUserType(FrappeTestCase):
for entry in link_fields:
self.assertTrue(entry.options in select_doctypes)
def test_print_share_email_default(self):
"""Test if print, share & email values default to 1. (for backward compatibility)"""
# create user type with read, write permissions
create_user_type("Test User Type")
# check if print, share & email values are set to 1
perm = frappe.get_all("Custom DocPerm", filters={"role": "_Test User Type"}, fields=["*"])[0]
self.assertTrue(perm.print == 1)
self.assertTrue(perm.share == 1)
self.assertTrue(perm.email == 1)
def tearDown(self):
frappe.db.rollback()

View file

@ -137,13 +137,10 @@ class UserType(Document):
user.set("block_modules", block_modules)
def add_role_permissions_for_user_doctypes(self):
perms = ["read", "write", "create", "submit", "cancel", "amend", "delete"]
perms = ["read", "write", "create", "submit", "cancel", "amend", "delete", "print", "email", "share"]
for row in self.user_doctypes:
docperm = add_role_permissions(row.document_type, self.role)
values = {perm: row.get(perm, default=0) for perm in perms}
for perm in ["print", "email", "share"]:
values[perm] = 1
frappe.db.set_value("Custom DocPerm", docperm, values)

View file

@ -22,12 +22,14 @@ class FormTimeline extends BaseTimeline {
}
setup_timeline_actions() {
this.add_action_button(
__("New Email"),
() => this.compose_mail(),
"es-line-add",
"btn-secondary"
);
if (frappe.model.can_email(null, this.frm)) {
this.add_action_button(
__("New Email"),
() => this.compose_mail(),
"es-line-add",
"btn-secondary"
);
}
this.setup_new_event_button();
}