Переглянути джерело

Get allowed reports with report type

version-14
Nabin Hait 8 роки тому
джерело
коміт
19b38ecaf9
1 змінених файлів з 52 додано та 34 видалено
  1. +52
    -34
      frappe/boot.py

+ 52
- 34
frappe/boot.py Переглянути файл

@@ -100,44 +100,62 @@ def get_user_page_or_report(parent):
roles = frappe.get_roles() roles = frappe.get_roles()
has_role = {} has_role = {}
column = get_column(parent) 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 # 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} 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})

# 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):

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 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: 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 return has_role




Завантаження…
Відмінити
Зберегти