Skip to content

Commit 543bf92

Browse files
Merge pull request #2707 from frappe/mergify/bp/main-hotfix/pr-2706
fix(perm): agent should see the assigned tickets (backport #2706)
2 parents e72c64b + 3d5f93d commit 543bf92

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

desk/src/components/AssignmentModal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ import { useConfigStore } from "@/stores/config";
8686
import { useUserStore } from "@/stores/user";
8787
import { call, createResource } from "frappe-ui";
8888
import { useOnboarding } from "frappe-ui/frappe";
89-
import { computed, onMounted, ref, watch } from "vue";
89+
import { computed, onMounted, ref } from "vue";
9090
9191
const props = defineProps({
9292
doctype: {

desk/src/components/ticket-agent/AssignToBody.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ const removeValue = (value) => {
115115
};
116116
117117
const addValue = (value) => {
118+
if (!value) return;
119+
118120
if (value === getUser("").name) {
119121
assignToMe.value = true;
120122
}

desk/src/components/ticket-agent/TicketDetailsTab.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function handleFieldUpdate(
167167
value: FieldValue,
168168
isCoreFieldUpdated = false
169169
) {
170-
if (ticket.value.doc[fieldname] === value) return;
170+
if (ticket.value.doc[fieldname] == value) return;
171171
if (isCoreFieldUpdated) {
172172
const label = getField(fieldname)?.label || fieldname;
173173
notifyTicketUpdate(label, value as string);

helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ def _get_rendered_template(
110110
)
111111

112112
def handle_email_feedback(self):
113-
114113
if (
115114
self.is_new()
116115
or self.via_customer_portal
@@ -196,7 +195,6 @@ def on_update(self):
196195
self.get_doc_before_save()
197196
and self.get_doc_before_save().status_category != "Open"
198197
):
199-
200198
agents = self.get_assigned_agents()
201199
if agents:
202200
for agent in agents:
@@ -436,7 +434,6 @@ def get_assigned_agent(self):
436434
if hasattr(self, "_assign") and self._assign:
437435
assignees = json.loads(self._assign)
438436
if len(assignees) > 0:
439-
440437
# TODO: temporary fix, remove this when only agents can be assigned to ticket
441438
exists = frappe.db.exists("HD Agent", assignees[0])
442439
if exists:
@@ -661,7 +658,6 @@ def reply_via_agent(
661658
def create_communication_via_contact(
662659
self, message, attachments=[], new_ticket=False
663660
):
664-
665661
if not new_ticket and frappe.db.get_single_value(
666662
"HD Settings", "enable_reply_email_to_agent"
667663
):
@@ -758,7 +754,6 @@ def send_reply_email_to_agent(self):
758754
frappe.throw(_(e))
759755

760756
def send_acknowledgement_email(self):
761-
762757
acknowledgement_email_content = frappe.db.get_single_value(
763758
"HD Settings", "acknowledgement_email_content"
764759
)
@@ -1114,7 +1109,6 @@ def filter_standard_fields(fields):
11141109
# permission checks which is not possible with standard permission system. This function
11151110
# is being called from hooks. `doc` is the ticket to check against
11161111
def has_permission(doc, user=None):
1117-
11181112
if not user:
11191113
user = frappe.session.user
11201114

@@ -1141,6 +1135,14 @@ def has_permission(doc, user=None):
11411135
if show_tickets_without_team and not doc.get("agent_group"):
11421136
return True
11431137

1138+
if doc.get("_assign", None):
1139+
try:
1140+
assignees = json.loads(doc._assign)
1141+
if user in assignees:
1142+
return True
1143+
except:
1144+
return False
1145+
11441146
teams = get_agents_team()
11451147
if any([team.get("ignore_restrictions") for team in teams]):
11461148
return True
@@ -1158,7 +1160,6 @@ def has_permission(doc, user=None):
11581160
# Custom perms for list query. Only the `WHERE` part
11591161
# https://frappeframework.com/docs/user/en/python-api/hooks#modify-list-query
11601162
def permission_query(user):
1161-
11621163
if not user:
11631164
user = frappe.session.user
11641165
if is_admin(user):
@@ -1207,6 +1208,12 @@ def permission_query(user):
12071208
query += " OR (`tabHD Ticket`.agent_group is null)"
12081209
return query
12091210

1211+
query += (
1212+
" OR (JSON_SEARCH(`tabHD Ticket`._assign, 'all', {user}) IS NOT NULL)".format(
1213+
user=frappe.db.escape(user)
1214+
)
1215+
)
1216+
12101217
team_names = [t.get("team_name") for t in teams]
12111218

12121219
if not team_names:

helpdesk/search_sqlite.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,10 @@ def prepare_document(self, doc):
8484
document["reference_ticket"] = int(doc.reference_ticket)
8585

8686
if doc.doctype == "Communication":
87-
# For communications, ensure reference fields are set
87+
# For communications, ensure reference fields are set for ticket doctype
8888
document["reference_doctype"] = doc.reference_doctype
8989
if doc.reference_doctype == "HD Ticket":
9090
document["reference_ticket"] = int(doc.reference_name)
91-
else:
92-
document["reference_ticket"] = doc.reference_name
9391

9492
if doc.doctype == "HD Ticket":
9593
document["reference_ticket"] = int(doc.name)

0 commit comments

Comments
 (0)