Get allowed reports with report type
This commit is contained in:
parent
d0318a78d4
commit
19b38ecaf9
1 changed files with 50 additions and 32 deletions
|
|
@ -100,44 +100,62 @@ def get_user_page_or_report(parent):
|
|||
roles = frappe.get_roles()
|
||||
has_role = {}
|
||||
column = get_column(parent)
|
||||
report_type_col = ""
|
||||
if parent == "Report":
|
||||
report_type_col = ", `tabCustom Role`.report_type"
|
||||
|
||||
# get pages or reports set on custom role
|
||||
for p in frappe.db.sql("""select `tabCustom Role`.{field} as name, `tabCustom Role`.modified, `tabCustom Role`.ref_doctype {report_type_col}
|
||||
from `tabCustom Role`, `tabHas Role` where
|
||||
`tabHas Role`.parent = `tabCustom Role`.name and
|
||||
`tabCustom Role`.{field} is not null and `tabHas Role`.role in ({roles})
|
||||
""".format(field=parent.lower(), roles = ', '.join(['%s']*len(roles))), roles, as_dict=1):
|
||||
|
||||
custom_roles = frappe.db.sql("""
|
||||
select
|
||||
`tabCustom Role`.{field} as name,
|
||||
`tabCustom Role`.modified,
|
||||
`tabCustom Role`.ref_doctype
|
||||
from `tabCustom Role`, `tabHas Role`
|
||||
where
|
||||
`tabHas Role`.parent = `tabCustom Role`.name
|
||||
and `tabCustom Role`.{field} is not null
|
||||
and `tabHas Role`.role in ({roles})
|
||||
""".format(field=parent.lower(), roles = ', '.join(['%s']*len(roles))), roles, as_dict=1)
|
||||
|
||||
for p in custom_roles:
|
||||
has_role[p.name] = {"modified":p.modified, "title": p.name, "ref_doctype": p.ref_doctype}
|
||||
if parent == "Report":
|
||||
has_role[p.name].update({'report_type': p.report_type})
|
||||
|
||||
for p in frappe.db.sql("""select distinct
|
||||
tab{parent}.name, tab{parent}.modified, {column}
|
||||
from `tabHas Role`, `tab{parent}`
|
||||
where `tabHas Role`.role in ({roles})
|
||||
and `tabHas Role`.parent = `tab{parent}`.name and tab{parent}.name not in
|
||||
(select `tabCustom Role`.{field} from `tabCustom Role` where `tabCustom Role`.{field} is not null)
|
||||
""".format(parent=parent, column=column, roles = ', '.join(['%s']*len(roles)), field=parent.lower()), roles, as_dict=True):
|
||||
if p.name not in has_role:
|
||||
has_role[p.name] = {"modified":p.modified, "title": p.title}
|
||||
if parent == "Report":
|
||||
has_role[p.name].update({'ref_doctype': p.ref_doctype})
|
||||
has_role[p.name].update({'report_type': p.report_type})
|
||||
standard_roles = frappe.db.sql("""
|
||||
select distinct
|
||||
tab{parent}.name,
|
||||
tab{parent}.modified,
|
||||
{column}
|
||||
from `tabHas Role`, `tab{parent}`
|
||||
where
|
||||
`tabHas Role`.role in ({roles})
|
||||
and `tabHas Role`.parent = `tab{parent}`.name
|
||||
and tab{parent}.name not in (
|
||||
select `tabCustom Role`.{field} from `tabCustom Role`
|
||||
where `tabCustom Role`.{field} is not null)
|
||||
""".format(parent=parent, column=column,
|
||||
roles = ', '.join(['%s']*len(roles)), field=parent.lower()), roles, as_dict=True)
|
||||
|
||||
for p in standard_roles:
|
||||
if p.name not in has_role:
|
||||
has_role[p.name] = {"modified":p.modified, "title": p.title}
|
||||
if parent == "Report":
|
||||
has_role[p.name].update({'ref_doctype': p.ref_doctype})
|
||||
|
||||
# pages or reports where role is not set are also allowed
|
||||
for p in frappe.db.sql("""select `tab{parent}`.name, `tab{parent}`.modified, {column}
|
||||
from `tab{parent}` where
|
||||
(select count(*) from `tabHas Role`
|
||||
where `tabHas Role`.parent=tab{parent}.name) = 0""".format(parent=parent, column=column), as_dict=1):
|
||||
# pages with no role are allowed
|
||||
if parent =="Page":
|
||||
pages_with_no_roles = frappe.db.sql("""
|
||||
select
|
||||
`tab{parent}`.name, `tab{parent}`.modified, {column}
|
||||
from `tab{parent}`
|
||||
where
|
||||
(select count(*) from `tabHas Role`
|
||||
where `tabHas Role`.parent=tab{parent}.name) = 0
|
||||
""".format(parent=parent, column=column), as_dict=1)
|
||||
|
||||
for p in pages_with_no_roles:
|
||||
if p.name not in has_role:
|
||||
has_role[p.name] = {"modified":p.modified, "title": p.title}
|
||||
if parent == "Report":
|
||||
has_role[p.name].update({'ref_doctype': p.ref_doctype})
|
||||
has_role[p.name].update({'report_type': p.report_type})
|
||||
has_role[p.name] = {"modified": p.modified, "title": p.title}
|
||||
|
||||
elif parent == "Report":
|
||||
for report_name in has_role:
|
||||
has_role[report_name]["report_type"] = frappe.db.get_value("Report", report_name, "report_type")
|
||||
|
||||
return has_role
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue