Skip to content

Commit

Permalink
fix(perms): ticket: list query conditions (#1634)
Browse files Browse the repository at this point in the history
* fix(perms): ticket: list query conditions

* fix: add table name (for joins)

* fix: whitespace
  • Loading branch information
ssiyad committed Nov 24, 2023
1 parent 8a56d5c commit 81b106d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 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,20 @@ 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 = "`tabHD Ticket`.contact={user} OR `tabHD Ticket`.raised_by={user} OR `tabHD Ticket`.owner={user}".format(
user=frappe.db.escape(user)
)
for c in customer:
res += ' OR `tabHD Ticket`.customer="{customer}"'.format(
customer=frappe.db.escape(c)
)
return res
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 81b106d

Please sign in to comment.