-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new report LANDA Power Users (#270)
- Loading branch information
1 parent
7889333
commit a44f797
Showing
6 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
9 changes: 9 additions & 0 deletions
9
landa/organization_management/report/landa_power_users/landa_power_users.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) 2025, ALYF GmbH and contributors | ||
// For license information, please see license.txt | ||
/* eslint-disable */ | ||
|
||
frappe.query_reports["LANDA Power Users"] = { | ||
"filters": [ | ||
|
||
] | ||
}; |
30 changes: 30 additions & 0 deletions
30
landa/organization_management/report/landa_power_users/landa_power_users.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"add_total_row": 0, | ||
"columns": [], | ||
"creation": "2025-01-10 16:06:59.329435", | ||
"disable_prepared_report": 0, | ||
"disabled": 0, | ||
"docstatus": 0, | ||
"doctype": "Report", | ||
"filters": [], | ||
"idx": 0, | ||
"is_standard": "Yes", | ||
"letter_head": "Extended Information in Footer", | ||
"modified": "2025-01-10 16:06:59.329435", | ||
"modified_by": "Administrator", | ||
"module": "Organization Management", | ||
"name": "LANDA Power Users", | ||
"owner": "Administrator", | ||
"prepared_report": 0, | ||
"ref_doctype": "User", | ||
"report_name": "LANDA Power Users", | ||
"report_type": "Script Report", | ||
"roles": [ | ||
{ | ||
"role": "System Manager" | ||
}, | ||
{ | ||
"role": "LANDA State Organization Employee" | ||
} | ||
] | ||
} |
73 changes: 73 additions & 0 deletions
73
landa/organization_management/report/landa_power_users/landa_power_users.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright (c) 2025, ALYF GmbH and contributors | ||
# For license information, please see license.txt | ||
|
||
import frappe | ||
from frappe import _ | ||
from frappe.query_builder.functions import Substring | ||
from pypika.functions import Coalesce | ||
from pypika.terms import Not | ||
|
||
|
||
def execute(filters=None): | ||
return get_columns(), get_data() | ||
|
||
|
||
def get_data(): | ||
User = frappe.qb.DocType("User") | ||
UserPermission = frappe.qb.DocType("User Permission") | ||
|
||
org_permissions = ( | ||
frappe.qb.from_(UserPermission) | ||
.select(UserPermission.user, UserPermission.for_value) | ||
.where(UserPermission.allow == "Organization") | ||
.where(UserPermission.apply_to_all_doctypes == 1) | ||
) | ||
|
||
query = ( | ||
frappe.qb.from_(User) | ||
.left_join(org_permissions) | ||
.on(User.name == org_permissions.user) | ||
.select( | ||
User.name, | ||
User.organization, | ||
Coalesce(org_permissions.for_value, "All Organizations").as_("permissions_for"), | ||
) | ||
.where(User.name.notin(["Administrator", "Guest"])) | ||
.where(User.enabled == 1) | ||
.where( | ||
(Substring(org_permissions.for_value, 1, 7) != Substring(User.organization, 1, 7)) | ||
| (org_permissions.for_value.isnull()) | ||
) | ||
.where( | ||
# Exclude lines like "Member of AVL-000. Permissions for AVL" (regional org management) | ||
Not( | ||
(Substring(User.organization, 5, 7) == "000") | ||
& (Substring(User.organization, 1, 3) == org_permissions.for_value) | ||
) | ||
) | ||
.orderby(User.name) | ||
) | ||
|
||
return query.run() | ||
|
||
|
||
def get_columns(): | ||
return [ | ||
{ | ||
"fieldname": "user", | ||
"label": _("User"), | ||
"fieldtype": "Link", | ||
"options": "User", | ||
}, | ||
{ | ||
"fieldname": "member_of", | ||
"label": _("Member of"), | ||
"fieldtype": "Link", | ||
"options": "Organization", | ||
}, | ||
{ | ||
"fieldname": "permissions_for", | ||
"label": _("Permissions for"), | ||
"fieldtype": "Data", | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters