chore: Rename 'Exclude Descendants' to 'Hide Descendants'

- Rename 'Exclude Descendants' to 'Hide Descendants'
- Rename js trigger to 'toggle_hide_descendants'
This commit is contained in:
marination 2021-01-21 18:48:25 +05:30
parent 08b090ed73
commit 4887dd1d5a
6 changed files with 26 additions and 26 deletions

View file

@ -145,10 +145,10 @@ class TestUserPermission(unittest.TestCase):
self.assertTrue(has_user_permission(frappe.get_doc("Person", parent_record.name), user.name))
self.assertTrue(has_user_permission(frappe.get_doc("Person", child_record.name), user.name))
frappe.db.set_value("User Permission", {"allow": "Person", "for_value": parent_record.name}, "exclude_descendants", 1)
frappe.db.set_value("User Permission", {"allow": "Person", "for_value": parent_record.name}, "hide_descendants", 1)
frappe.cache().delete_value("user_permissions")
# check if adding perm on a group record with exclude_descendants enabled,
# check if adding perm on a group record with hide_descendants enabled,
# hides child records
self.assertTrue(has_user_permission(frappe.get_doc("Person", parent_record.name), user.name))
self.assertFalse(has_user_permission(frappe.get_doc("Person", child_record.name), user.name))
@ -164,7 +164,7 @@ def create_user(email, role="System Manager"):
user.add_roles(role)
return user
def get_params(user, doctype, docname, is_default=0, exclude_descendants=0, applicable=None):
def get_params(user, doctype, docname, is_default=0, hide_descendants=0, applicable=None):
''' Return param to insert '''
param = {
"user": user.name,
@ -173,7 +173,7 @@ def get_params(user, doctype, docname, is_default=0, exclude_descendants=0, appl
"is_default": is_default,
"apply_to_all_doctypes": 1,
"applicable_doctypes": [],
"exclude_descendants": exclude_descendants
"hide_descendants": hide_descendants
}
if applicable:
param.update({"apply_to_all_doctypes": 0})

View file

@ -26,7 +26,7 @@ frappe.ui.form.on('User Permission', {
() => frappe.set_route('query-report', 'Permitted Documents For User',
{ user: frm.doc.user }));
frm.trigger('set_applicable_for_constraint');
frm.trigger('show_exclude_descendants');
frm.trigger('toggle_hide_descendants');
},
allow: frm => {
@ -34,7 +34,7 @@ frappe.ui.form.on('User Permission', {
if (frm.doc.for_value) {
frm.set_value('for_value', null);
}
frm.trigger('show_exclude_descendants');
frm.trigger('toggle_hide_descendants');
}
},
@ -49,9 +49,9 @@ frappe.ui.form.on('User Permission', {
}
},
show_exclude_descendants: frm => {
toggle_hide_descendants: frm => {
let show = frappe.boot.nested_set_doctypes.includes(frm.doc.allow);
frm.toggle_display('exclude_descendants', show);
frm.toggle_display('hide_descendants', show);
}

View file

@ -15,7 +15,7 @@
"apply_to_all_doctypes",
"applicable_for",
"column_break_9",
"exclude_descendants"
"hide_descendants"
],
"fields": [
{
@ -83,14 +83,14 @@
{
"default": "0",
"description": "Hide descendant records of <b>For Value</b>.",
"fieldname": "exclude_descendants",
"fieldname": "hide_descendants",
"fieldtype": "Check",
"hidden": 1,
"label": "Exclude Descendants"
"label": "Hide Descendants"
}
],
"links": [],
"modified": "2021-01-13 19:31:05.618273",
"modified": "2021-01-21 18:14:10.839381",
"modified_by": "Administrator",
"module": "Core",
"name": "User Permission",

View file

@ -50,7 +50,7 @@ class UserPermission(Document):
}, or_filters={
'applicable_for': cstr(self.applicable_for),
'apply_to_all_doctypes': 1,
'exclude_descendants': cstr(self.exclude_descendants)
'hide_descendants': cstr(self.hide_descendants)
}, limit=1)
if overlap_exists:
ref_link = frappe.get_desk_link(self.doctype, overlap_exists[0].name)
@ -92,13 +92,13 @@ def get_user_permissions(user=None):
try:
for perm in frappe.get_all('User Permission',
fields=['allow', 'for_value', 'applicable_for', 'is_default', 'exclude_descendants'],
fields=['allow', 'for_value', 'applicable_for', 'is_default', 'hide_descendants'],
filters=dict(user=user)):
meta = frappe.get_meta(perm.allow)
add_doc_to_perm(perm, perm.for_value, perm.is_default)
if meta.is_nested_set() and not perm.exclude_descendants:
if meta.is_nested_set() and not perm.hide_descendants:
decendants = frappe.db.get_descendants(perm.allow, perm.for_value)
for doc in decendants:
add_doc_to_perm(perm, doc, False)
@ -195,7 +195,7 @@ def add_user_permissions(data):
data = json.loads(data)
data = frappe._dict(data)
# get all doctypes on whom this permission os applied
# get all doctypes on whom this permission is applied
perm_applied_docs = check_applicable_doc_perm(data.user, data.doctype, data.docname)
exists = frappe.db.exists("User Permission", {
"user": data.user,
@ -205,26 +205,26 @@ def add_user_permissions(data):
})
if data.apply_to_all_doctypes == 1 and not exists:
remove_applicable(perm_applied_docs, data.user, data.doctype, data.docname)
insert_user_perm(data.user, data.doctype, data.docname, data.is_default, data.exclude_descendants, apply_to_all=1)
insert_user_perm(data.user, data.doctype, data.docname, data.is_default, data.hide_descendants, apply_to_all=1)
return 1
elif len(data.applicable_doctypes) > 0 and data.apply_to_all_doctypes != 1:
remove_apply_to_all(data.user, data.doctype, data.docname)
update_applicable(perm_applied_docs, data.applicable_doctypes, data.user, data.doctype, data.docname)
for applicable in data.applicable_doctypes :
if applicable not in perm_applied_docs:
insert_user_perm(data.user, data.doctype, data.docname, data.is_default, data.exclude_descendants, applicable=applicable)
insert_user_perm(data.user, data.doctype, data.docname, data.is_default, data.hide_descendants, applicable=applicable)
elif exists:
insert_user_perm(data.user, data.doctype, data.docname, data.is_default, data.exclude_descendants, applicable=applicable)
insert_user_perm(data.user, data.doctype, data.docname, data.is_default, data.hide_descendants, applicable=applicable)
return 1
return 0
def insert_user_perm(user, doctype, docname, is_default=0, exclude_descendants=0, apply_to_all=None, applicable=None):
def insert_user_perm(user, doctype, docname, is_default=0, hide_descendants=0, apply_to_all=None, applicable=None):
user_perm = frappe.new_doc("User Permission")
user_perm.user = user
user_perm.allow = doctype
user_perm.for_value = docname
user_perm.is_default = is_default
user_perm.exclude_descendants = exclude_descendants
user_perm.hide_descendants = hide_descendants
if applicable:
user_perm.applicable_for = applicable
user_perm.apply_to_all_doctypes = 0

View file

@ -19,7 +19,7 @@ frappe.listview_settings['User Permission'] = {
dialog.set_df_property("is_default", "hidden", 1);
dialog.set_df_property("apply_to_all_doctypes", "hidden", 1);
dialog.set_df_property("applicable_doctypes", "hidden", 1);
dialog.set_df_property("exclude_descendants", "hidden", 1);
dialog.set_df_property("hide_descendants", "hidden", 1);
}
},
{
@ -83,7 +83,7 @@ frappe.listview_settings['User Permission'] = {
fieldtype: "Column Break"
},
{
fieldname: 'exclude_descendants',
fieldname: 'hide_descendants',
label: __('Exclude Descendants'),
fieldtype: 'Check',
hidden: 1
@ -233,7 +233,7 @@ frappe.listview_settings['User Permission'] = {
dialog.set_df_property("apply_to_all_doctypes", "hidden", 0);
dialog.set_value("apply_to_all_doctypes", "checked", 1);
let show = frappe.boot.nested_set_doctypes.includes(dialog.get_value("doctype"));
dialog.set_df_property("exclude_descendants", "hidden", !show);
dialog.set_df_property("hide_descendants", "hidden", !show);
dialog.refresh();
},

View file

@ -399,7 +399,7 @@ def set_user_permission_if_allowed(doctype, name, user, with_message=False):
add_user_permission(doctype, name, user)
def add_user_permission(doctype, name, user, ignore_permissions=False, applicable_for=None,
is_default=0, exclude_descendants=0):
is_default=0, hide_descendants=0):
'''Add user permission'''
from frappe.core.doctype.user_permission.user_permission import user_permission_exists
@ -414,7 +414,7 @@ def add_user_permission(doctype, name, user, ignore_permissions=False, applicabl
for_value=name,
is_default=is_default,
applicable_for=applicable_for,
exclude_descendants=exclude_descendants,
hide_descendants=hide_descendants,
)).insert(ignore_permissions=ignore_permissions)
def remove_user_permission(doctype, name, user):