PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 2.4.5
Fluent Support – Helpdesk & Customer Support Ticket System v2.4.5
2.4.5 2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 All 69 releases
← All changes | app/Services/MailerInbox/MailBoxService.php +30 -30 1.10.4 → 2.4.5 View file →
@@ -7,8 +7,9 @@
7 7 use FluentSupport\App\Models\MailBox;
8 8 use FluentSupport\App\Models\Meta;
9 9 use FluentSupport\App\Models\Ticket;
10 10 use FluentSupport\App\Services\EmailNotification\Settings;
11 +use FluentSupport\App\Services\Tickets\AgentTicketAccess;
11 12 use FluentSupport\Framework\Support\Arr;
12 13 use Exception;
13 14
14 15 class MailBoxService
@@ -13,9 +14,8 @@
13 14
14 15 class MailBoxService
15 16 {
16 17 /**
17 - * This `getMailBoxes` method is used to get all mailboxes.
18 18 * @return array
19 19 */
20 20 public function getMailBoxes ()
21 21 {
@@ -30,23 +30,23 @@
30 30 ];
31 31 }
32 32
33 33 /**
34 - * This `deleteMailBox` method is used to delete a mailbox.
35 - * @param int $mailBoxId The id of the mailbox to be deleted.
36 - * @param int $fallbackId The id of the fallback mailbox to be used.
34 + * Delete a mailbox and move its tickets (and default flag) to the fallback.
35 + *
36 + * @param int $mailBoxId
37 + * @param int $fallbackId
37 38 * @return array
38 39 */
39 40 public function deleteMailBox($mailBoxId, $fallbackId )
40 41 {
41 42 if ( $mailBoxId == $fallbackId ) {
42 - throw new \Exception('Fallback Box can not be the same as MailBox ID');
43 + throw new \Exception(esc_html__('Fallback Box cannot be the same as MailBox ID', 'fluent-support'));
43 44 }
44 45
45 46 $box = MailBox::findOrFail($mailBoxId);
46 47 $fallbackBox = MailBox::findOrFail($fallbackId);
47 48
48 - // if the mailbox is default, then make the fallback mailbox default
49 49 if($box->is_default == 'yes'){
50 50 $fallbackBox->is_default = 'yes';
51 51 $fallbackBox->save();
52 52 }
@@ -51,9 +51,9 @@
51 51 $fallbackBox->save();
52 52 }
53 53
54 54 /*
55 - * Action before delete a mailbox
55 + * Fires before a mailbox is deleted.
56 56 *
57 57 * @since v1.0.0
58 58 * @param object $box Mailbox
59 59 * @param object $fallbackBox Fallback mailbox
@@ -63,13 +63,13 @@
63 63 $this->deleteAllMailBoxMeta($mailBoxId);
64 64
65 65 MailBox::where('id', $mailBoxId)->delete();
66 66
67 - // let's transfer the tickets now
67 + // Not a move — fluent_support/mailbox_deleted below is the event for this.
68 68 Ticket::syncMailBoxId($mailBoxId, $fallbackId);
69 69
70 70 /*
71 - * Action on mailbox delete
71 + * Fires after a mailbox is deleted.
72 72 *
73 73 * @since v1.0.0
74 74 * @param integer $mailBoxId
75 75 * @param object $fallbackBox Fallback mailbox
@@ -81,9 +81,10 @@
81 81 ];
82 82 }
83 83
84 84 /**
85 - * This `moveTickets` method is used to move tickets from one mailbox to another.
85 + * Move the selected tickets, or all of the mailbox's tickets, to $data['new_box_id'].
86 + *
86 87 * @param array $data
87 88 * @param int $mailBoxId
88 89 * @return array
89 90 */
@@ -94,9 +95,9 @@
94 95 $newBox = MailBox::findOrFail($data['new_box_id']);
95 96 $oldBox = MailBox::findOrFail($mailBoxId);
96 97
97 98 /**
98 - * Action before tickets moved
99 + * Fires before tickets move to another mailbox.
99 100 * @since v1.5.7
100 101 * @param array $data
101 102 * @param object $oldBox Current mailbox
102 103 * @param object $newBox Mailbox where selected tickets will be moved
@@ -108,9 +109,8 @@
108 109 ->update([
109 110 'mailbox_id' => $newBox->id
110 111 ]);
111 112 } else {
112 - // Move all ticket for the MailBox
113 113 Ticket::where('mailbox_id', $mailBoxId)
114 114 ->update([
115 115 'mailbox_id' => $newBox->id
116 116 ]);
@@ -115,9 +115,9 @@
115 115 'mailbox_id' => $newBox->id
116 116 ]);
117 117 }
118 118 /**
119 - * Action after tickets moved
119 + * Fires after tickets move to another mailbox.
120 120 * @since v1.5.7
121 121 * @param array $data
122 122 * @param object $oldBox Mailbox where selected tickets were moved from
123 123 * @param object $newBox Mailbox where selected tickets were moved to
@@ -130,9 +130,8 @@
130 130
131 131 }
132 132
133 133 /**
134 - * This `setAsDefault` method will set a business box as default. Update is_default column to yes for the selected mailbox and no for others.
135 134 * @param int $mailBoxId
136 135 * @return array
137 136 */
138 137 public function setAsDefault ($mailBoxId )
@@ -152,9 +151,8 @@
152 151 ];
153 152 }
154 153
155 154 /**
156 - * This `getEmailSetups` method is used to get the email setups
157 155 * @param int $boxId
158 156 * @return array
159 157 */
160 158 public function getEmailsSetups ( $boxId )
@@ -175,11 +173,11 @@
175 173 ];
176 174 }
177 175
178 176 /**
179 - * This `saveEmailSettings` method is used to save the email settings for the mailbox
180 - * @param object $request
177 + * @param string $emailType
181 178 * @param int $boxId
179 + * @param array $data
182 180 * @return array
183 181 */
184 182 public function saveEmailSettings ($emailType, $boxId, $data )
185 183 {
@@ -196,9 +194,8 @@
196 194 ];
197 195 }
198 196
199 197 /**
200 - * This `getTickets` method is used to get the tickets for the given mailbox
201 198 * @param array $filters
202 199 * @param int $boxId
203 200 * @return array
204 201 */
@@ -204,9 +201,9 @@
204 201 */
205 202 public function getTickets ($filters, $boxId )
206 203 {
207 204 if (!$boxId) {
208 - throw new \Exception('MailBox ID must be provided');
205 + throw new \Exception(esc_html__('MailBox ID must be provided', 'fluent-support'));
209 206 }
210 207
211 208 $ticketsQuery = Ticket::getTicketsQuery();
212 209
@@ -211,17 +208,17 @@
211 208 $ticketsQuery = Ticket::getTicketsQuery();
212 209
213 210 $ticketsQuery->where('mailbox_id', $boxId);
214 211
215 - if ( $filters['customer_id'] ) {
212 + if ( !empty($filters['customer_id']) ) {
216 213 $ticketsQuery->where('customer_id', $filters['customer_id']);
217 214 }
218 215
219 - if ( $filters['product_id'] ) {
216 + if ( !empty($filters['product_id']) ) {
220 217 $ticketsQuery->where('product_id', $filters['product_id']);
221 218 }
222 219
223 - if ( $filters['ticket_title'] ) {
220 + if ( !empty($filters['ticket_title']) ) {
224 221 $ticketsQuery->where('title', 'LIKE', "%". $filters['ticket_title'] ."%");
225 222 }
226 223
227 224 return [
@@ -232,17 +229,23 @@
232 229 private function validateTicketMoving ( $data, $mailBoxId )
233 230 {
234 231
235 232 if ($data['new_box_id'] == $mailBoxId) {
236 - throw new \Exception('New Box can not be the same as MailBox ID');
233 + throw new \Exception(esc_html__('New Box cannot be the same as MailBox ID', 'fluent-support'));
237 234 }
238 235
239 236 if ( $data['move_type'] == 'Custom' && empty($data['ticket_ids']) ) {
240 - throw new \Exception('Invalid request submitted, Select ticket first');
237 + throw new \Exception(esc_html__('Invalid request submitted. Please select a ticket first', 'fluent-support'));
241 238 }
242 239 $ticketIDs = $data['ticket_ids'];
243 240 $newMailBoxId = (int)$data['new_box_id'];
244 241
242 + // Current-user mailbox access is checked by callers that act on behalf
243 + // of the logged-in user (MailBoxController::moveTickets). This service
244 + // is also called by Pro workflows and MCP, which run on behalf of an
245 + // automation/agent-tool call rather than the current browser session,
246 + // and already enforce their own access checks before calling here.
247 +
245 248 foreach ($ticketIDs as $ticketID) {
246 249 $ticket = Ticket::findOrFail($ticketID);
247 250 if (!$ticket->agent_id) {
248 251 continue;
@@ -252,15 +255,12 @@
252 255 if (!$agent) {
253 256 continue;
254 257 }
255 258
256 - $restrictions = $agent->getMeta('agent_restrictions', []);
257 - if (!empty($restrictions['restrictedBusinessBoxes'])) {
258 - $restrictedBoxes = array_map('intval', $restrictions['restrictedBusinessBoxes']);
259 + $restrictedBoxes = (new AgentTicketAccess())->getRestrictedMailboxIds($agent);
259 260
260 - if (in_array($newMailBoxId, $restrictedBoxes)) {
261 - throw new \Exception('Agent is restricted for this mailbox ticket');
262 - }
261 + if (in_array($newMailBoxId, $restrictedBoxes, true)) {
262 + throw new \Exception(esc_html__('Agent is restricted for this mailbox ticket', 'fluent-support'));
263 263 }
264 264 }
265 265 return true;
266 266 }