Skip to content

Commit

Permalink
chore: handle if sla does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
ssiyad committed Oct 17, 2023
1 parent 079036f commit 2d07252
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 3 additions & 5 deletions helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,15 +718,13 @@ def set_sla(self):
"""
if sla := get_sla(self):
self.sla = sla.name
self.sla = None

def apply_sla(self):
"""
Apply SLA if set. This won't check whether the SLA exists. Hence, will
fail/error if the SLA is deleted.
Apply SLA if set.
"""
if self.sla:
frappe.get_doc("HD Service Level Agreement", self.sla).apply(self)
if sla := frappe.get_last_doc("HD Service Level Agreement", {"name": self.sla}):
sla.apply(self)

Check warning on line 727 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#L726-L727

Added lines #L726 - L727 were not covered by tests

# `on_communication_update` is a special method exposed from `Communication` doctype.
# It is called when a communication is updated. Beware of changes as this effectively
Expand Down
13 changes: 12 additions & 1 deletion helpdesk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ def check_permissions(doctype, parent):
frappe.throw(f"Insufficient Permission for {doctype}", frappe.PermissionError)


def is_admin(user: str = None) -> bool:

Check warning on line 25 in helpdesk/utils.py

View check run for this annotation

Codecov / codecov/patch

helpdesk/utils.py#L25

Added line #L25 was not covered by tests
"""
Check whether `user` is an admin
:param user: User to check against, defaults to current user
:return: Whether `user` is an admin
"""
user = user or frappe.session.user
return user == "Administrator"

Check warning on line 33 in helpdesk/utils.py

View check run for this annotation

Codecov / codecov/patch

helpdesk/utils.py#L32-L33

Added lines #L32 - L33 were not covered by tests


def is_agent(user: str = None) -> bool:
"""
Check whether `user` is an agent
Expand All @@ -30,7 +41,7 @@ def is_agent(user: str = None) -> bool:
:return: Whether `user` is an agent
"""
user = user or frappe.session.user
return bool(frappe.db.exists("HD Agent", {"name": user}))
return is_admin() or bool(frappe.db.exists("HD Agent", {"name": user}))

Check warning on line 44 in helpdesk/utils.py

View check run for this annotation

Codecov / codecov/patch

helpdesk/utils.py#L44

Added line #L44 was not covered by tests


def publish_event(event: str, data: dict, user: str = None):
Expand Down

0 comments on commit 2d07252

Please sign in to comment.