| @@ -1,10 +1,43 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace FluentSupport\App\Http\Controllers; |
| 4 | 4 | |
| 5 | +use FluentSupport\App\Modules\PermissionManager; | |
| 5 | 6 | use FluentSupport\Framework\Http\Controller as BaseController; |
| 6 | 7 | |
| 7 | 8 | abstract class Controller extends BaseController |
| 8 | 9 | { |
| 9 | - // | |
| 10 | + /** | |
| 11 | + * Ensure the current agent has at least one ticket management permission. | |
| 12 | + * Draft-only agents (fst_draft_reply only) cannot perform mutating actions. | |
| 13 | + * | |
| 14 | + * @throws \Exception | |
| 15 | + */ | |
| 16 | + protected function ensureCanManageTickets() | |
| 17 | + { | |
| 18 | + if (PermissionManager::canManageTickets()) { | |
| 19 | + return; | |
| 20 | + } | |
| 21 | + | |
| 22 | + throw new \Exception( | |
| 23 | + esc_html__('You do not have permission to perform this action.', 'fluent-support') | |
| 24 | + ); | |
| 25 | + } | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * Ensure the current agent can access the given ticket based on visibility level. | |
| 29 | + * | |
| 30 | + * @param object $ticket | |
| 31 | + * @throws \Exception | |
| 32 | + */ | |
| 33 | + protected function ensureCanAccessTicket($ticket) | |
| 34 | + { | |
| 35 | + if (PermissionManager::canAccessTicket($ticket)) { | |
| 36 | + return; | |
| 37 | + } | |
| 38 | + | |
| 39 | + throw new \Exception( | |
| 40 | + esc_html__('Sorry, You do not have permission to this ticket', 'fluent-support') | |
| 41 | + ); | |
| 42 | + } | |
| 10 | 43 | } |