Skip to content

Commit

Permalink
fix(ux): ticket: list filters: apply only on agents (#1301)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssiyad authored Jul 11, 2023
1 parent 64c7f26 commit 67dde67
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
6 changes: 4 additions & 2 deletions helpdesk/api/auth.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import frappe

from helpdesk.utils import is_agent as _is_agent


@frappe.whitelist()
def get_user():
user = frappe.get_doc("User", frappe.session.user)

is_agent = bool(frappe.db.exists("HD Agent", frappe.session.user))
is_agent = _is_agent()
is_admin = user.username == "administrator"
has_desk_access = is_agent or is_admin
user_image = user.user_image
Expand All @@ -29,8 +31,8 @@ def get_user():
@frappe.whitelist(allow_guest=True)
def oauth_providers():
from frappe.utils.html_utils import get_icon_html
from frappe.utils.password import get_decrypted_password
from frappe.utils.oauth import get_oauth2_authorize_url, get_oauth_keys
from frappe.utils.password import get_decrypted_password

out = []
providers = frappe.get_all(
Expand Down
16 changes: 15 additions & 1 deletion helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
default_outgoing_email_account,
default_ticket_outgoing_email_account,
)
from helpdesk.utils import capture_event, publish_event
from helpdesk.utils import capture_event, publish_event, is_agent


class HDTicket(Document):
Expand Down Expand Up @@ -55,6 +55,20 @@ def get_list_select(query: Query):

@staticmethod
def get_list_filters(query: Query):
if is_agent():
return HDTicket.get_agent_list_filters(query)

return HDTicket.get_customer_list_filters(query)

@staticmethod
def get_customer_list_filters(query: Query):
QBTicket = frappe.qb.DocType("HD Ticket")
user = frappe.session.user
query = query.where(QBTicket.raised_by == user)
return query

@staticmethod
def get_agent_list_filters(query: Query):
user = frappe.session.user

if HDTicket.can_ignore_restrictions(user):
Expand Down
18 changes: 12 additions & 6 deletions helpdesk/helpdesk/doctype/hd_ticket_type/hd_ticket_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}
],
"links": [],
"modified": "2023-03-26 22:41:29.459274",
"modified": "2023-07-11 13:43:46.419795",
"modified_by": "Administrator",
"module": "Helpdesk",
"name": "HD Ticket Type",
Expand Down Expand Up @@ -71,21 +71,27 @@
"write": 1
},
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Helpdesk Contact",
"share": 1,
"write": 1
"share": 1
},
{
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "All",
"share": 1
}
],
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
}
12 changes: 11 additions & 1 deletion helpdesk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@
from frappe.utils.telemetry import capture as _capture


def is_agent(user: str = frappe.session.user) -> bool:
"""
Check whether `user` is an agent
:param user: User to check against, defaults to current user
:return: Whether `user` is an agent
"""
return bool(frappe.db.exists("HD Agent", user))


def publish_event(event: str, data: dict):
room = get_website_room()
frappe.publish_realtime(event, message=data, room=room, after_commit=True)


def capture_event(event: str):
return _capture(event, "helpdesk")
return _capture(event, "helpdesk")


def extract_mentions(html):
Expand Down

0 comments on commit 67dde67

Please sign in to comment.