| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\App\Http\Controllers; |
| 4 |
|
| 5 |
use FluentSupport\App\Modules\PermissionManager; |
| 6 |
use FluentSupport\Framework\Http\Controller as BaseController; |
| 7 |
|
| 8 |
abstract class Controller extends BaseController |
| 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 |
} |
| 43 |
} |
| 44 |
|