Skip to content

Commit

Permalink
fix(api): get_list: restrict to Helpdesk doctypes
Browse files Browse the repository at this point in the history
  • Loading branch information
ssiyad committed Sep 28, 2023
1 parent 6fcb57b commit 28e1389
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions helpdesk/extends/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import math

import frappe
from frappe import _
from frappe.model.base_document import get_controller
from frappe.query_builder.functions import Count
from frappe.utils import get_user_info_for_avatar
from frappe.utils.caching import redis_cache

from helpdesk.utils import check_permissions

Expand All @@ -26,6 +28,7 @@ def get_list(
parent=None,
debug=False,
):
check_allowed(doctype)
check_permissions(doctype, parent)

query = frappe.qb.get_query(
Expand Down Expand Up @@ -61,6 +64,7 @@ def get_list_meta(
parent=None,
debug=False,
):
check_allowed(doctype)
check_permissions(doctype, parent)

query = frappe.qb.get_query(
Expand Down Expand Up @@ -160,3 +164,16 @@ def transform_assign(r):
continue
row["assignee"] = get_user_info_for_avatar(j.pop())
return r


@redis_cache()
def check_allowed(doctype: str):
"""
Allow only `Helpdesk` doctypes. This is to prevent users from accessing
other doctypes.
:param doctype: Doctype name
"""
if not frappe.get_meta(doctype).module == "Helpdesk":
text = _("You are not allowed to access {0}").format(doctype)
frappe.throw(text, frappe.PermissionError)

0 comments on commit 28e1389

Please sign in to comment.