Skip to content

Commit

Permalink
fix(perms): ticket: list query conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
ssiyad committed Nov 24, 2023
1 parent 8a56d5c commit 2c4d091
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,3 +693,18 @@ def has_permission(doc, user=None):
or is_agent(user)
or doc.customer in get_customer(user)
)


# Custom perms for list query. Only the `WHERE` part
# https://frappeframework.com/docs/user/en/python-api/hooks#modify-list-query
def permission_query(user):
user = user or frappe.session.user
if is_agent(user):
return
customer = get_customer(user)
res = "`contact`={user} OR `raised_by`={user} OR `owner`={user}".format(

Check warning on line 705 in helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py

View check run for this annotation

Codecov / codecov/patch

helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py#L700-L705

Added lines #L700 - L705 were not covered by tests
user=frappe.db.escape(user)
)
for c in customer:
res += 'OR `customer`="{customer}"'.format(customer=frappe.db.escape(c))
return res

Check warning on line 710 in helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py

View check run for this annotation

Codecov / codecov/patch

helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py#L708-L710

Added lines #L708 - L710 were not covered by tests
4 changes: 4 additions & 0 deletions helpdesk/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@
has_permission = {
"HD Ticket": "helpdesk.helpdesk.doctype.hd_ticket.hd_ticket.has_permission",
}

permission_query_conditions = {
"HD Ticket": "helpdesk.helpdesk.doctype.hd_ticket.hd_ticket.permission_query",
}

0 comments on commit 2c4d091

Please sign in to comment.