| @@ -19,14 +19,11 @@ | ||
| 19 | 19 | return self::$restricted; |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * Assert the current user can read/write $ticket. | |
| 23 | + * Check the current user can access $ticket, including mailbox restrictions. | |
| 24 | + * Returns WP_Error on failure, null on success: | |
| 24 | 25 | * |
| 25 | - * Checks both the canAccessTicket visibility rule and any mailbox | |
| 26 | - * restrictions the agent has been assigned. Returns WP_Error on the first | |
| 27 | - * failure, null on success — so callers do: | |
| 28 | - * | |
| 29 | 26 | * if ($err = TicketAccessGuard::assert($ticket)) { |
| 30 | 27 | * return $err; |
| 31 | 28 | * } |
| 32 | 29 | */ |
| @@ -44,9 +41,9 @@ | ||
| 44 | 41 | return null; |
| 45 | 42 | } |
| 46 | 43 | |
| 47 | 44 | /** |
| 48 | - * Assert the current user can create tickets in / move tickets to $mailboxId. | |
| 45 | + * Check the current user can create or move tickets in $mailboxId. | |
| 49 | 46 | * Returns WP_Error on failure, null on success. |
| 50 | 47 | */ |
| 51 | 48 | public static function assertMailboxWritable($mailboxId) |
| 52 | 49 | { |
| @@ -57,12 +54,15 @@ | ||
| 57 | 54 | return null; |
| 58 | 55 | } |
| 59 | 56 | |
| 60 | 57 | /** |
| 61 | - * Assert that $targetAgent is not restricted from the mailbox of $ticket. | |
| 58 | + * Check $targetAgent isn't restricted from the ticket's mailbox. | |
| 62 | 59 | * Returns WP_Error on failure, null on success. |
| 60 | + * | |
| 61 | + * @param int|null $mailboxId Destination mailbox when the ticket is being | |
| 62 | + * moved; null checks the one it sits in now. | |
| 63 | 63 | */ |
| 64 | - public static function assertAssignableAgent(Ticket $ticket, Agent $targetAgent) | |
| 64 | + public static function assertAssignableAgent(Ticket $ticket, Agent $targetAgent, $mailboxId = null) | |
| 65 | 65 | { |
| 66 | 66 | $meta = $targetAgent->getMeta('agent_restrictions'); |
| 67 | 67 | $agentRestricted = (!empty($meta['businessBoxRestrictions']) && !empty($meta['restrictedBusinessBoxes'])) |
| 68 | 68 | ? $meta['restrictedBusinessBoxes'] |
| @@ -67,9 +67,11 @@ | ||
| 67 | 67 | $agentRestricted = (!empty($meta['businessBoxRestrictions']) && !empty($meta['restrictedBusinessBoxes'])) |
| 68 | 68 | ? $meta['restrictedBusinessBoxes'] |
| 69 | 69 | : []; |
| 70 | 70 | |
| 71 | - if ($agentRestricted && in_array((int) $ticket->mailbox_id, array_map('intval', $agentRestricted), true)) { | |
| 71 | + $checkMailboxId = $mailboxId === null ? (int) $ticket->mailbox_id : (int) $mailboxId; | |
| 72 | + | |
| 73 | + if ($agentRestricted && in_array($checkMailboxId, array_map('intval', $agentRestricted), true)) { | |
| 72 | 74 | return MCPHelper::error('forbidden', __("That agent is restricted from this ticket's mailbox", 'fluent-support')); |
| 73 | 75 | } |
| 74 | 76 | |
| 75 | 77 | return null; |