From 81b106d1b84848a79f3892736909d601c9dc6ce2 Mon Sep 17 00:00:00 2001 From: Sabu Siyad Date: Fri, 24 Nov 2023 12:12:09 +0530 Subject: [PATCH] fix(perms): ticket: list query conditions (#1634) * fix(perms): ticket: list query conditions * fix: add table name (for joins) * fix: whitespace --- .../helpdesk/doctype/hd_ticket/hd_ticket.py | 17 +++++++++++++++++ helpdesk/hooks.py | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py b/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py index a11128012..076ca7b4d 100644 --- a/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py +++ b/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py @@ -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 diff --git a/helpdesk/hooks.py b/helpdesk/hooks.py index 63d9545a4..7657fef95 100644 --- a/helpdesk/hooks.py +++ b/helpdesk/hooks.py @@ -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", +}