From 2622cfbd1ef043214acc67be1473f8e08013364d Mon Sep 17 00:00:00 2001 From: RitvikSardana Date: Mon, 21 Oct 2024 13:31:03 +0530 Subject: [PATCH 01/14] fix: create comm when ticket is created from outside customer portal --- helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py b/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py index c01797dc3..a58e39c10 100644 --- a/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py +++ b/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py @@ -189,6 +189,9 @@ def after_insert(self): log_ticket_activity(self.name, "created this ticket") capture_event("ticket_created") publish_event("helpdesk:new-ticket", {"name": self.name}) + # create communication if we are not hitting the new ticket creation API + if not self.via_customer_portal: + self.create_communication_via_contact(self.description) def on_update(self): # flake8: noqa @@ -336,6 +339,10 @@ def remove_assignment_if_not_in_team(self): Removes the assignment if the agent is not in the team. Should be called inside on_update """ + if self.is_new(): + return + if not self.agent_group or not self._assign: + return if self.has_value_changed("agent_group") and self.status == "Open": current_assigned_agent_doc = self.get_assigned_agent() if ( From 6ee223a918b77053c7fe675a09271805ed24af9d Mon Sep 17 00:00:00 2001 From: RitvikSardana Date: Mon, 21 Oct 2024 13:31:21 +0530 Subject: [PATCH 02/14] fix(styles): ticket creation --- desk/src/pages/TicketCustomer.vue | 5 ++--- desk/src/pages/TicketNew.vue | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/desk/src/pages/TicketCustomer.vue b/desk/src/pages/TicketCustomer.vue index fb4e7aca7..35d14f305 100644 --- a/desk/src/pages/TicketCustomer.vue +++ b/desk/src/pages/TicketCustomer.vue @@ -164,10 +164,9 @@ const showResolveButton = computed(() => ["Open", "Replied"].includes(ticket.data.status) ); -const showEditor = computed(() => - ["Open", "Replied", "Resolved"].includes(ticket.data.status) -); +const showEditor = computed(() => ticket.data.status !== "Closed"); +// this handles whether the ticket was raised and then was closed without any reply from the agent. const showFeedback = computed(() => { return ticket.data?.communications?.some((c) => { if (c.sender !== ticket.data.raised_by) { diff --git a/desk/src/pages/TicketNew.vue b/desk/src/pages/TicketNew.vue index 8f2c4a650..41c463be5 100644 --- a/desk/src/pages/TicketNew.vue +++ b/desk/src/pages/TicketNew.vue @@ -27,7 +27,7 @@ /> -
+
Date: Mon, 21 Oct 2024 15:41:29 +0530 Subject: [PATCH 03/14] fix(query): show customer data altogether --- helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py b/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py index a58e39c10..2715a9ffc 100644 --- a/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py +++ b/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py @@ -916,7 +916,7 @@ def permission_query(user): user=frappe.db.escape(user) ) for c in customer: - res += ' OR `tabHD Ticket`.customer="{customer}"'.format( + res += ' OR `tabHD Ticket`.customer={customer}'.format( customer=frappe.db.escape(c) ) return res From 9e338fe2aac1b5cb71251b06eac7326e54b6c364 Mon Sep 17 00:00:00 2001 From: RitvikSardana Date: Tue, 22 Oct 2024 00:40:44 +0530 Subject: [PATCH 04/14] fix: no permission should be needed for setting up SLA --- helpdesk/helpdesk/doctype/hd_service_level_agreement/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/helpdesk/helpdesk/doctype/hd_service_level_agreement/utils.py b/helpdesk/helpdesk/doctype/hd_service_level_agreement/utils.py index e67558e80..06cbf09e9 100644 --- a/helpdesk/helpdesk/doctype/hd_service_level_agreement/utils.py +++ b/helpdesk/helpdesk/doctype/hd_service_level_agreement/utils.py @@ -16,7 +16,6 @@ def get_sla(ticket: Document) -> Document: :param doc: Ticket to use :return: Applicable SLA """ - check_permissions(DOCTYPE, None) QBSla = frappe.qb.DocType(DOCTYPE) QBPriority = frappe.qb.DocType("HD Service Level Priority") now = now_datetime() From c80c33717b6f46c01ac50e98913f848b9d22e97d Mon Sep 17 00:00:00 2001 From: RitvikSardana Date: Tue, 22 Oct 2024 02:30:26 +0530 Subject: [PATCH 05/14] fix: add setting to allow anyone to create tickets --- .../doctype/hd_settings/hd_settings.json | 30 +++++++++++++++---- .../doctype/hd_settings/hd_settings.py | 14 +++++++++ .../helpdesk/doctype/hd_ticket/hd_ticket.json | 2 +- .../helpdesk/doctype/hd_ticket/hd_ticket.py | 24 ++++++++++++++- 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/helpdesk/helpdesk/doctype/hd_settings/hd_settings.json b/helpdesk/helpdesk/doctype/hd_settings/hd_settings.json index 23bf05e0e..a01dbb9c4 100644 --- a/helpdesk/helpdesk/doctype/hd_settings/hd_settings.json +++ b/helpdesk/helpdesk/doctype/hd_settings/hd_settings.json @@ -12,10 +12,6 @@ "priority_section", "default_priority", "column_break_nvbf", - "ticket_type_section", - "default_ticket_type", - "is_ticket_type_mandatory", - "column_break_zxek", "agent_groups_section", "restrict_tickets_by_agent_group", "do_not_restrict_tickets_without_an_agent_group", @@ -25,6 +21,13 @@ "knowledge_base_section", "suggest_articles_in_new_ticket_page", "prefer_knowledge_base", + "ticket_tab", + "ticket_type_section", + "default_ticket_type", + "is_ticket_type_mandatory", + "column_break_zxek", + "ticket_restrictions_section", + "allow_anyone_to_create_tickets", "workflow_tab", "skip_email_workflow", "instantly_send_email", @@ -274,11 +277,28 @@ "fieldname": "headings_weight", "fieldtype": "Int", "label": "Headings Weight" + }, + { + "fieldname": "ticket_tab", + "fieldtype": "Tab Break", + "label": "Ticket" + }, + { + "fieldname": "ticket_restrictions_section", + "fieldtype": "Section Break", + "label": "Ticket Restrictions" + }, + { + "default": "0", + "description": "If enabled, anyone will be able to create tickets (without any permission). \nUseful in cases where you wants users to create tickets via webforms or some external APIs without authentication.", + "fieldname": "allow_anyone_to_create_tickets", + "fieldtype": "Check", + "label": "Allow anyone to create tickets" } ], "issingle": 1, "links": [], - "modified": "2024-09-18 00:47:04.055942", + "modified": "2024-10-22 02:14:33.360809", "modified_by": "Administrator", "module": "Helpdesk", "name": "HD Settings", diff --git a/helpdesk/helpdesk/doctype/hd_settings/hd_settings.py b/helpdesk/helpdesk/doctype/hd_settings/hd_settings.py index eda948b81..144bb6eb2 100644 --- a/helpdesk/helpdesk/doctype/hd_settings/hd_settings.py +++ b/helpdesk/helpdesk/doctype/hd_settings/hd_settings.py @@ -9,6 +9,11 @@ from frappe.model.naming import append_number_if_name_exists from frappe.realtime import get_website_room +from helpdesk.helpdesk.doctype.hd_ticket.hd_ticket import ( + remove_guest_ticket_creation_permission, + set_guest_ticket_creation_permission, +) + class HDSettings(Document): def get_base_support_rotation(self): @@ -49,12 +54,21 @@ def create_base_support_rotation(self): return + def before_save(self): + self.update_ticket_permissions() + def on_update(self): event = "helpdesk:settings-updated" room = get_website_room() frappe.publish_realtime(event, room=room, after_commit=True) + def update_ticket_permissions(self): + if self.allow_anyone_to_create_tickets: + set_guest_ticket_creation_permission() + if not self.allow_anyone_to_create_tickets: + remove_guest_ticket_creation_permission() + @property def hd_search(self): from helpdesk.api.article import search diff --git a/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.json b/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.json index 204c7b794..3fa5e101c 100644 --- a/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.json +++ b/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.json @@ -410,7 +410,7 @@ "icon": "fa fa-issue", "idx": 61, "links": [], - "modified": "2023-11-23 13:44:59.105648", + "modified": "2024-10-22 01:28:37.126589", "modified_by": "Administrator", "module": "Helpdesk", "name": "HD Ticket", diff --git a/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py b/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py index 2715a9ffc..c915cc34f 100644 --- a/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py +++ b/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py @@ -5,10 +5,12 @@ import frappe from frappe import _ +from frappe.core.page.permission_manager.permission_manager import remove from frappe.desk.form.assign_to import add as assign from frappe.desk.form.assign_to import clear as clear_all_assignments from frappe.desk.form.assign_to import get as get_assignees from frappe.model.document import Document +from frappe.permissions import add_permission, update_permission_property from frappe.query_builder import Order from pypika.functions import Count from pypika.queries import Query @@ -916,7 +918,27 @@ def permission_query(user): user=frappe.db.escape(user) ) for c in customer: - res += ' OR `tabHD Ticket`.customer={customer}'.format( + res += " OR `tabHD Ticket`.customer={customer}".format( customer=frappe.db.escape(c) ) return res + + +def set_guest_ticket_creation_permission(): + doctype = "HD Ticket" + add_permission(doctype, "Guest", 0) + + role = "Guest" + permlevel = 0 + ptype = ["read", "write", "create", "if_owner"] + + for p in ptype: + # update permissions + update_permission_property(doctype, role, permlevel, p, 1) + + +def remove_guest_ticket_creation_permission(): + doctype = "HD Ticket" + role = "Guest" + permlevel = 0 + remove(doctype, role, permlevel, 1) From 08276d3319988f5e8b347eaf86f6ce3da588de28 Mon Sep 17 00:00:00 2001 From: RitvikSardana Date: Tue, 22 Oct 2024 12:59:35 +0530 Subject: [PATCH 06/14] fix: pre commit file --- helpdesk/helpdesk/doctype/hd_service_level_agreement/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpdesk/helpdesk/doctype/hd_service_level_agreement/utils.py b/helpdesk/helpdesk/doctype/hd_service_level_agreement/utils.py index 06cbf09e9..7eaf9c314 100644 --- a/helpdesk/helpdesk/doctype/hd_service_level_agreement/utils.py +++ b/helpdesk/helpdesk/doctype/hd_service_level_agreement/utils.py @@ -4,7 +4,7 @@ from frappe.utils import now_datetime from pypika import Criterion -from helpdesk.utils import check_permissions, get_context +from helpdesk.utils import get_context DOCTYPE = "HD Service Level Agreement" From f8512cb4a0b2f0ce0de91397ec3e4a3811acf400 Mon Sep 17 00:00:00 2001 From: RitvikSardana Date: Thu, 24 Oct 2024 14:17:40 +0530 Subject: [PATCH 07/14] fix: custom fields in filters in customer portal --- helpdesk/api/doc.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/helpdesk/api/doc.py b/helpdesk/api/doc.py index 9369dd91c..06007ee28 100644 --- a/helpdesk/api/doc.py +++ b/helpdesk/api/doc.py @@ -68,23 +68,28 @@ def get_filterable_fields(doctype: str, show_customer_portal_fields=False): ) # for customer portal show only fields present in customer_portal_fields - if show_customer_portal_fields: from_doc_fields = from_doc_fields.where( QBDocField.fieldname.isin(customer_portal_fields) ) - from_custom_fields = from_custom_fields.where( - QBCustomField.fieldname.isin(visible_custom_fields) - ) + if len(visible_custom_fields) > 0: + from_custom_fields = from_custom_fields.where( + QBCustomField.fieldname.isin(visible_custom_fields) + ) + from_custom_fields = from_custom_fields.run(as_dict=True) + else: + from_custom_fields = [] - from_doc_fields = from_doc_fields.run(as_dict=True) - from_custom_fields = from_custom_fields.run(as_dict=True) + if not show_customer_portal_fields: + from_custom_fields = from_custom_fields.run(as_dict=True) + from_doc_fields = from_doc_fields.run(as_dict=True) # from hd ticket template get children with fieldname and hidden_from_customer res = [] res.extend(from_doc_fields) # TODO: Ritvik => till a better way we have for custom fields, just show custom fields + res.extend(from_custom_fields) if not show_customer_portal_fields: res.append( From 097bdf62ce93f27a1615808bf6e8eec0669653f0 Mon Sep 17 00:00:00 2001 From: RitvikSardana Date: Thu, 24 Oct 2024 14:35:27 +0530 Subject: [PATCH 08/14] fix(styles): article page --- desk/src/pages/KnowledgeBaseArticle.vue | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/desk/src/pages/KnowledgeBaseArticle.vue b/desk/src/pages/KnowledgeBaseArticle.vue index 6581796d7..1af81d31b 100644 --- a/desk/src/pages/KnowledgeBaseArticle.vue +++ b/desk/src/pages/KnowledgeBaseArticle.vue @@ -1,10 +1,10 @@