Skip to content

Commit ef1a602

Browse files
Merge pull request #6359 from frappe/mergify/bp/master/pr-6358
fix(marketplace): Enhance audit report access control for impersonation (backport #6358)
2 parents 93e9e1e + 8a57463 commit ef1a602

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

press/api/marketplace.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
)
2424
from press.utils import get_app_tag, get_current_team, get_last_doc, is_user_part_of_team, unique
2525
from press.utils.billing import get_frappe_io_connection
26+
from press.utils.user import is_desk_user
2627

2728
if TYPE_CHECKING:
2829
from press.marketplace.doctype.marketplace_app_plan.marketplace_app_plan import MarketplaceAppPlan
@@ -1387,9 +1388,13 @@ def get_app_audit(app: str):
13871388
"""
13881389
current_team = get_current_team()
13891390
app_team = frappe.db.get_value("Marketplace App", app, "team")
1390-
# not permitted to get the audit report if user is not a member of the team of the marketplace app
1391-
if app_team != current_team or not is_user_part_of_team(frappe.session.user, app_team):
1392-
frappe.throw(_("You are not permitted to get the audit report for this app"), frappe.PermissionError)
1391+
# for impersonation, the session user needs to have system user role, in that case we allow seeing other audit reports.
1392+
if not is_desk_user(frappe.session.user): # noqa: SIM102 - nested if makes the logic more readable.
1393+
# not permitted to get the audit report if user is not a member of the team of the marketplace app
1394+
if app_team != current_team or not is_user_part_of_team(frappe.session.user, app_team):
1395+
frappe.throw(
1396+
_("You are not permitted to get the audit report for this app"), frappe.PermissionError
1397+
)
13931398

13941399
# get_all, limit 1, order by creation desc
13951400
audit_name = frappe.get_all(

0 commit comments

Comments
 (0)