Skip to content

Commit

Permalink
feat: Role based permission for Dashboard Chart (#17634)
Browse files Browse the repository at this point in the history
  • Loading branch information
shariquerik committed Jul 28, 2022
1 parent 8fe4fa7 commit 4fadc21
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
13 changes: 11 additions & 2 deletions frappe/desk/doctype/dashboard_chart/dashboard_chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"column_break_2",
"color",
"section_break_10",
"last_synced_on"
"last_synced_on",
"roles"
],
"fields": [
{
Expand Down Expand Up @@ -277,13 +278,20 @@
"fieldtype": "Link",
"label": "Parent Document Type",
"options": "DocType"
},
{
"fieldname": "roles",
"fieldtype": "Table",
"label": "Roles",
"options": "Has Role"
}
],
"links": [],
"modified": "2021-11-09 17:18:11.456145",
"modified": "2022-07-27 11:09:09.203236",
"modified_by": "Administrator",
"module": "Desk",
"name": "Dashboard Chart",
"naming_rule": "By fieldname",
"owner": "Administrator",
"permissions": [
{
Expand Down Expand Up @@ -323,5 +331,6 @@
],
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
7 changes: 6 additions & 1 deletion frappe/desk/doctype/dashboard_chart/dashboard_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from frappe.model.document import Document
from frappe.model.naming import append_number_if_name_exists
from frappe.modules.export_file import export_to_files
from frappe.utils import cint, get_datetime, getdate, now_datetime, nowdate
from frappe.utils import cint, get_datetime, getdate, has_common, now_datetime, nowdate
from frappe.utils.dashboard import cache_source
from frappe.utils.data import format_date
from frappe.utils.dateutils import (
Expand Down Expand Up @@ -87,6 +87,11 @@ def has_permission(doc, ptype, user):
if doc.document_type in allowed_doctypes:
return True

if doc.roles:
allowed = [d.role for d in doc.roles]
if has_common(roles, allowed):
return True

return False


Expand Down

0 comments on commit 4fadc21

Please sign in to comment.