Merge pull request #25900 from akhilnarang/fix-accessing-report-without-roles

fix: allow accessing reports without roles
This commit is contained in:
Akhil Narang 2024-05-02 14:33:09 +05:30 committed by GitHub
commit 490fae768a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -164,7 +164,9 @@ def get_user_pages_or_reports(parent, cache=False):
page = DocType("Page")
report = DocType("Report")
if parent == "Report":
is_report = parent == "Report"
if is_report:
columns = (report.name.as_("title"), report.ref_doctype, report.report_type)
else:
columns = (page.title.as_("title"),)
@ -206,7 +208,7 @@ def get_user_pages_or_reports(parent, cache=False):
.distinct()
)
if parent == "Report":
if is_report:
pages_with_standard_roles = pages_with_standard_roles.where(report.disabled == 0)
pages_with_standard_roles = pages_with_standard_roles.run(as_dict=True)
@ -221,19 +223,20 @@ def get_user_pages_or_reports(parent, cache=False):
frappe.qb.from_(hasRole).select(Count("*")).where(hasRole.parent == parentTable.name)
)
# pages with no role are allowed
if parent == "Page":
pages_with_no_roles = (
frappe.qb.from_(parentTable)
.select(parentTable.name, parentTable.modified, *columns)
.where(no_of_roles == 0)
).run(as_dict=True)
# pages and reports with no role are allowed
rows_with_no_roles = (
frappe.qb.from_(parentTable)
.select(parentTable.name, parentTable.modified, *columns)
.where(no_of_roles == 0)
).run(as_dict=True)
for p in pages_with_no_roles:
if p.name not in has_role:
has_role[p.name] = {"modified": p.modified, "title": p.title}
for r in rows_with_no_roles:
if r.name not in has_role:
has_role[r.name] = {"modified": r.modified, "title": r.title}
if is_report:
has_role[r.name] |= {"ref_doctype": r.ref_doctype}
elif parent == "Report":
if is_report:
if not has_permission("Report", print_logs=False):
return {}