PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.4
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.4
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
← All changes | includes/models/class-wpsc-agent.php +56 -9 3.4.6 → 3.5.4 View file →
@@ -65,22 +65,22 @@
65 65 // create ticket event to reset unresolved and workload counts of related agents to the ticket.
66 66 add_action( 'wpsc_create_new_ticket', array( __CLASS__, 'create_new_ticket' ), 500 );
67 67
68 68 // change status event to reset unresolved and workload counts of related agents to the ticket.
69 - add_action( 'wpsc_change_ticket_status', array( __CLASS__, 'change_status' ), 200, 4 );
69 + add_action( 'wpsc_change_ticket_status', array( __CLASS__, 'change_status' ), 500, 4 );
70 70
71 71 // assigned agent event to reset unresolved and workload counts of related agents to the ticket.
72 - add_action( 'wpsc_change_assignee', array( __CLASS__, 'change_assignee' ), 200, 4 );
72 + add_action( 'wpsc_change_assignee', array( __CLASS__, 'change_assignee' ), 500, 4 );
73 73
74 74 // change raised by event to reset unresolved and workload counts of related agents to the ticket.
75 - add_action( 'wpsc_change_raised_by', array( __CLASS__, 'change_raised_by' ), 200, 4 );
75 + add_action( 'wpsc_change_raised_by', array( __CLASS__, 'change_raised_by' ), 500, 4 );
76 76
77 77 // archive/restore/delete ticket event to reset unresolved and workload counts of related agents to the ticket.
78 - add_action( 'wpsc_delete_ticket', array( __CLASS__, 'reset_agent_unresolved_count' ), 200 );
79 - add_action( 'wpsc_ticket_restore', array( __CLASS__, 'reset_agent_unresolved_count' ), 200 );
80 - add_action( 'wpsc_ticket_delete_permanently', array( __CLASS__, 'reset_agent_unresolved_count' ), 200 );
81 - add_action( 'wpsc_ticket_archive', array( __CLASS__, 'reset_agents_unresolved_count' ), 200, 2 );
82 - add_action( 'wpsc_archive_ticket_restore', array( __CLASS__, 'reset_agents_unresolved_count' ), 200, 2 );
78 + add_action( 'wpsc_delete_ticket', array( __CLASS__, 'reset_agent_unresolved_count' ), 500 );
79 + add_action( 'wpsc_ticket_restore', array( __CLASS__, 'reset_agent_unresolved_count' ), 500 );
80 + add_action( 'wpsc_ticket_delete_permanently', array( __CLASS__, 'reset_agent_unresolved_count' ), 500 );
81 + add_action( 'wpsc_ticket_archive', array( __CLASS__, 'reset_agents_unresolved_count' ), 500, 2 );
82 + add_action( 'wpsc_archive_ticket_restore', array( __CLASS__, 'reset_agents_unresolved_count' ), 500, 2 );
83 83
84 84 // agent autocomplete admin access only.
85 85 add_action( 'wp_ajax_wpsc_agent_autocomplete_admin_access', array( __CLASS__, 'agent_autocomplete_admin_access' ) );
86 86
@@ -571,12 +571,21 @@
571 571 * @return array
572 572 */
573 573 public static function agent_autocomplete( $filters ) {
574 574
575 + // Whitelisted map of accepted sort_by values to actual DB columns - only
576 + // the two options offered in the sort-by dropdown are valid here.
577 + $sortable_columns = array(
578 + 'name' => 'name',
579 + 'workload' => 'workload',
580 + );
581 + $orderby = isset( $sortable_columns[ $filters['sort_by'] ] ) ?
582 + $sortable_columns[ $filters['sort_by'] ] : 'name';
583 +
575 584 $args = array(
576 585 'search' => $filters['term'],
577 586 'items_per_page' => 25,
578 - 'orderby' => $filters['sort_by'],
587 + 'orderby' => $orderby,
579 588 'order' => 'ASC',
580 589 'meta_query' => array(
581 590 'relation' => 'AND',
582 591 array(
@@ -1184,8 +1193,46 @@
1184 1193
1185 1194 $sql = $sql . $joins . $where;
1186 1195
1187 1196 return (int) $wpdb->get_var( $sql );
1197 + }
1198 +
1199 + /**
1200 + * Check current user ticket access for capability
1201 + *
1202 + * @param WPSC_Ticket|WPSC_Archive_Ticket $ticket Ticket object.
1203 + * @param string $cap - capability name.
1204 + * @return boolean
1205 + */
1206 + public static function has_ticket_cap( $ticket, $cap ) {
1207 +
1208 + $current_user = WPSC_Current_User::$current_user;
1209 +
1210 + $assigned_agents = array_map(
1211 + fn ( $agent ) => $agent->id,
1212 + $ticket->assigned_agent
1213 + );
1214 +
1215 + $flag = false;
1216 + if (
1217 + (
1218 + ! $ticket->assigned_agent &&
1219 + $current_user->agent->has_cap( $cap . '-unassigned' )
1220 + ) ||
1221 + (
1222 + in_array( $current_user->agent->id, $assigned_agents ) &&
1223 + $current_user->agent->has_cap( $cap . '-assigned-me' )
1224 + ) ||
1225 + (
1226 + $ticket->assigned_agent &&
1227 + ! in_array( $current_user->agent->id, $assigned_agents ) &&
1228 + $current_user->agent->has_cap( $cap . '-assigned-others' )
1229 + )
1230 + ) {
1231 + $flag = true;
1232 + }
1233 +
1234 + return apply_filters( 'wpsc_it_has_ticket_cap', $flag, $ticket, $cap );
1188 1235 }
1189 1236 }
1190 1237 endif;
1191 1238