| @@ -14,9 +14,8 @@ | ||
| 14 | 14 | |
| 15 | 15 | class MailBoxService |
| 16 | 16 | { |
| 17 | 17 | /** |
| 18 | - * This `getMailBoxes` method is used to get all mailboxes. | |
| 19 | 18 | * @return array |
| 20 | 19 | */ |
| 21 | 20 | public function getMailBoxes () |
| 22 | 21 | { |
| @@ -31,11 +30,12 @@ | ||
| 31 | 30 | ]; |
| 32 | 31 | } |
| 33 | 32 | |
| 34 | 33 | /** |
| 35 | - * This `deleteMailBox` method is used to delete a mailbox. | |
| 36 | - * @param int $mailBoxId The id of the mailbox to be deleted. | |
| 37 | - * @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 | |
| 38 | 38 | * @return array |
| 39 | 39 | */ |
| 40 | 40 | public function deleteMailBox($mailBoxId, $fallbackId ) |
| 41 | 41 | { |
| @@ -45,9 +45,8 @@ | ||
| 45 | 45 | |
| 46 | 46 | $box = MailBox::findOrFail($mailBoxId); |
| 47 | 47 | $fallbackBox = MailBox::findOrFail($fallbackId); |
| 48 | 48 | |
| 49 | - // if the mailbox is default, then make the fallback mailbox default | |
| 50 | 49 | if($box->is_default == 'yes'){ |
| 51 | 50 | $fallbackBox->is_default = 'yes'; |
| 52 | 51 | $fallbackBox->save(); |
| 53 | 52 | } |
| @@ -52,9 +51,9 @@ | ||
| 52 | 51 | $fallbackBox->save(); |
| 53 | 52 | } |
| 54 | 53 | |
| 55 | 54 | /* |
| 56 | - * Action before delete a mailbox | |
| 55 | + * Fires before a mailbox is deleted. | |
| 57 | 56 | * |
| 58 | 57 | * @since v1.0.0 |
| 59 | 58 | * @param object $box Mailbox |
| 60 | 59 | * @param object $fallbackBox Fallback mailbox |
| @@ -64,13 +63,13 @@ | ||
| 64 | 63 | $this->deleteAllMailBoxMeta($mailBoxId); |
| 65 | 64 | |
| 66 | 65 | MailBox::where('id', $mailBoxId)->delete(); |
| 67 | 66 | |
| 68 | - // let's transfer the tickets now | |
| 67 | + // Not a move — fluent_support/mailbox_deleted below is the event for this. | |
| 69 | 68 | Ticket::syncMailBoxId($mailBoxId, $fallbackId); |
| 70 | 69 | |
| 71 | 70 | /* |
| 72 | - * Action on mailbox delete | |
| 71 | + * Fires after a mailbox is deleted. | |
| 73 | 72 | * |
| 74 | 73 | * @since v1.0.0 |
| 75 | 74 | * @param integer $mailBoxId |
| 76 | 75 | * @param object $fallbackBox Fallback mailbox |
| @@ -82,9 +81,10 @@ | ||
| 82 | 81 | ]; |
| 83 | 82 | } |
| 84 | 83 | |
| 85 | 84 | /** |
| 86 | - * 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 | + * | |
| 87 | 87 | * @param array $data |
| 88 | 88 | * @param int $mailBoxId |
| 89 | 89 | * @return array |
| 90 | 90 | */ |
| @@ -95,9 +95,9 @@ | ||
| 95 | 95 | $newBox = MailBox::findOrFail($data['new_box_id']); |
| 96 | 96 | $oldBox = MailBox::findOrFail($mailBoxId); |
| 97 | 97 | |
| 98 | 98 | /** |
| 99 | - * Action before tickets moved | |
| 99 | + * Fires before tickets move to another mailbox. | |
| 100 | 100 | * @since v1.5.7 |
| 101 | 101 | * @param array $data |
| 102 | 102 | * @param object $oldBox Current mailbox |
| 103 | 103 | * @param object $newBox Mailbox where selected tickets will be moved |
| @@ -109,9 +109,8 @@ | ||
| 109 | 109 | ->update([ |
| 110 | 110 | 'mailbox_id' => $newBox->id |
| 111 | 111 | ]); |
| 112 | 112 | } else { |
| 113 | - // Move all ticket for the MailBox | |
| 114 | 113 | Ticket::where('mailbox_id', $mailBoxId) |
| 115 | 114 | ->update([ |
| 116 | 115 | 'mailbox_id' => $newBox->id |
| 117 | 116 | ]); |
| @@ -116,9 +115,9 @@ | ||
| 116 | 115 | 'mailbox_id' => $newBox->id |
| 117 | 116 | ]); |
| 118 | 117 | } |
| 119 | 118 | /** |
| 120 | - * Action after tickets moved | |
| 119 | + * Fires after tickets move to another mailbox. | |
| 121 | 120 | * @since v1.5.7 |
| 122 | 121 | * @param array $data |
| 123 | 122 | * @param object $oldBox Mailbox where selected tickets were moved from |
| 124 | 123 | * @param object $newBox Mailbox where selected tickets were moved to |
| @@ -131,9 +130,8 @@ | ||
| 131 | 130 | |
| 132 | 131 | } |
| 133 | 132 | |
| 134 | 133 | /** |
| 135 | - * This `setAsDefault` method will set a business box as default. Update is_default column to yes for the selected mailbox and no for others. | |
| 136 | 134 | * @param int $mailBoxId |
| 137 | 135 | * @return array |
| 138 | 136 | */ |
| 139 | 137 | public function setAsDefault ($mailBoxId ) |
| @@ -153,9 +151,8 @@ | ||
| 153 | 151 | ]; |
| 154 | 152 | } |
| 155 | 153 | |
| 156 | 154 | /** |
| 157 | - * This `getEmailSetups` method is used to get the email setups | |
| 158 | 155 | * @param int $boxId |
| 159 | 156 | * @return array |
| 160 | 157 | */ |
| 161 | 158 | public function getEmailsSetups ( $boxId ) |
| @@ -176,11 +173,11 @@ | ||
| 176 | 173 | ]; |
| 177 | 174 | } |
| 178 | 175 | |
| 179 | 176 | /** |
| 180 | - * This `saveEmailSettings` method is used to save the email settings for the mailbox | |
| 181 | - * @param object $request | |
| 177 | + * @param string $emailType | |
| 182 | 178 | * @param int $boxId |
| 179 | + * @param array $data | |
| 183 | 180 | * @return array |
| 184 | 181 | */ |
| 185 | 182 | public function saveEmailSettings ($emailType, $boxId, $data ) |
| 186 | 183 | { |
| @@ -197,9 +194,8 @@ | ||
| 197 | 194 | ]; |
| 198 | 195 | } |
| 199 | 196 | |
| 200 | 197 | /** |
| 201 | - * This `getTickets` method is used to get the tickets for the given mailbox | |
| 202 | 198 | * @param array $filters |
| 203 | 199 | * @param int $boxId |
| 204 | 200 | * @return array |
| 205 | 201 | */ |
| @@ -212,17 +208,17 @@ | ||
| 212 | 208 | $ticketsQuery = Ticket::getTicketsQuery(); |
| 213 | 209 | |
| 214 | 210 | $ticketsQuery->where('mailbox_id', $boxId); |
| 215 | 211 | |
| 216 | - if ( $filters['customer_id'] ) { | |
| 212 | + if ( !empty($filters['customer_id']) ) { | |
| 217 | 213 | $ticketsQuery->where('customer_id', $filters['customer_id']); |
| 218 | 214 | } |
| 219 | 215 | |
| 220 | - if ( $filters['product_id'] ) { | |
| 216 | + if ( !empty($filters['product_id']) ) { | |
| 221 | 217 | $ticketsQuery->where('product_id', $filters['product_id']); |
| 222 | 218 | } |
| 223 | 219 | |
| 224 | - if ( $filters['ticket_title'] ) { | |
| 220 | + if ( !empty($filters['ticket_title']) ) { | |
| 225 | 221 | $ticketsQuery->where('title', 'LIKE', "%". $filters['ticket_title'] ."%"); |
| 226 | 222 | } |
| 227 | 223 | |
| 228 | 224 | return [ |
| @@ -241,8 +237,14 @@ | ||
| 241 | 237 | throw new \Exception(esc_html__('Invalid request submitted. Please select a ticket first', 'fluent-support')); |
| 242 | 238 | } |
| 243 | 239 | $ticketIDs = $data['ticket_ids']; |
| 244 | 240 | $newMailBoxId = (int)$data['new_box_id']; |
| 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. | |
| 245 | 247 | |
| 246 | 248 | foreach ($ticketIDs as $ticketID) { |
| 247 | 249 | $ticket = Ticket::findOrFail($ticketID); |
| 248 | 250 | if (!$ticket->agent_id) { |