Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Role based permission for Dashboard Chart (backport #17634) #17655

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -14,7 +14,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 @@ -90,6 +90,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