Skip to content

Commit

Permalink
Merge pull request #1417 from ssiyad/fix/api/handle_list_error_oob
Browse files Browse the repository at this point in the history
fix(api): ticket: handle out of bounds (not found)
  • Loading branch information
ssiyad authored Aug 1, 2023
2 parents da6ef2e + 1e08aaa commit f45b76e
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions helpdesk/helpdesk/doctype/hd_ticket/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from frappe.utils.caching import redis_cache
from pypika import Criterion, Order

from helpdesk.utils import get_customer, is_agent
from helpdesk.utils import get_customer, is_agent, check_permissions


@frappe.whitelist()
def get_one(name):
check_permissions("HD Ticket", None)
QBActivity = frappe.qb.DocType("HD Ticket Activity")
QBComment = frappe.qb.DocType("HD Ticket Comment")
QBCommunication = frappe.qb.DocType("Communication")
Expand Down Expand Up @@ -38,15 +39,16 @@ def get_one(name):
QBTicket.template,
)
.where(QBTicket.name == name)
.limit(1)
)

if not _is_agent:
query = query.where(get_customer_criteria())

try:
ticket = query.run(as_dict=True)[0]
except Exception:
ticket = query.run(as_dict=True)
if not len(ticket):
frappe.throw(_("Ticket not found"), frappe.DoesNotExistError)
ticket = ticket.pop()

contact = (
frappe.qb.from_(QBContact)
Expand Down Expand Up @@ -117,7 +119,12 @@ def get_one(name):
)
custom_fields = (
frappe.qb.from_(QBCustomField)
.select(QBCustomField.fieldname, QBCustomField.label, QBCustomField.value, QBCustomField.route)
.select(
QBCustomField.fieldname,
QBCustomField.label,
QBCustomField.value,
QBCustomField.route,
)
.where(QBCustomField.parent == name)
.where(QBCustomField.parentfield == "custom_fields")
.where(QBCustomField.parenttype == "HD Ticket")
Expand Down Expand Up @@ -160,11 +167,12 @@ def get_attachments(doctype, name):
.run(as_dict=True)
)


@frappe.whitelist()
def update_custom_field(ticket_name, fieldname, value):
frappe.db.set_value(
"HD Ticket Custom Field",
{ "parent": ticket_name, "fieldname": fieldname },
{"parent": ticket_name, "fieldname": fieldname},
"value",
value
)
value,
)

0 comments on commit f45b76e

Please sign in to comment.