Skip to content

Commit

Permalink
Merge pull request #2019 from RitvikSardana/non-portal-ticket-creation
Browse files Browse the repository at this point in the history
feat: settings to allow to create tickets without permission
  • Loading branch information
RitvikSardana authored Oct 22, 2024
2 parents 81adc58 + 08276d3 commit c0d16ad
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 13 deletions.
5 changes: 2 additions & 3 deletions desk/src/pages/TicketCustomer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion desk/src/pages/TicketNew.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/>
</div>
<!-- existing fields -->
<div class="flex flex-col flex-1" :class="subject.length >= 2 && 'gap-5'">
<div class="flex flex-col" :class="subject.length >= 2 && 'gap-5'">
<FormControl
v-model="subject"
type="text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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()
Expand Down
30 changes: 25 additions & 5 deletions helpdesk/helpdesk/doctype/hd_settings/hd_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions helpdesk/helpdesk/doctype/hd_settings/hd_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
31 changes: 30 additions & 1 deletion helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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)

0 comments on commit c0d16ad

Please sign in to comment.