@@ -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
11161111def 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
11601162def 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 :
0 commit comments