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 @@ /> -
+
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() 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 c01797dc3..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 @@ -189,6 +191,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 +341,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 ( @@ -909,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)