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
fluent-support / app / Http / Policies / AgentPolicy.php

AgentPolicy.php in Fluent Support – Helpdesk & Customer Support Ticket System 2.4.5, at app/Http/Policies/AgentPolicy.php

63 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\App\Http\Policies;
4
5 use FluentSupport\App\Modules\PermissionManager;
6 use FluentSupport\Framework\Http\Request\Request;
7 use FluentSupport\Framework\Foundation\Policy;
8
9 class AgentPolicy extends Policy
10 {
11 /**
12 * @param \FluentSupport\Framework\Http\Request\Request $request
13 * @return Boolean
14 */
15 public function verifyRequest(Request $request)
16 {
17 // Only reached by routes without their own method here (index, avatar).
18 return PermissionManager::currentUserCan('fst_sensitive_data');
19 }
20
21 public function addAgent(Request $request)
22 {
23 return $this->guardManageOptions();
24 }
25
26 public function updateAgent(Request $request)
27 {
28 return $this->guardManageOptions();
29 }
30
31 public function deleteAgent(Request $request)
32 {
33 return $this->guardManageOptions();
34 }
35
36 /**
37 * Agent records carry plugin permissions, so editing them grants privileges.
38 * Gate on manage_options, which the plugin's own permission system can't grant.
39 * Throwing gives a specific message, and the code becomes the HTTP status.
40 *
41 * @return Boolean
42 * @throws \Exception
43 */
44 protected function guardManageOptions()
45 {
46 if (current_user_can('manage_options')) {
47 return true;
48 }
49
50 if (!is_user_logged_in()) {
51 throw new \Exception(
52 esc_html__('You must be logged in to perform this action.', 'fluent-support'),
53 401
54 );
55 }
56
57 throw new \Exception(
58 esc_html__('Only administrators can add, edit, or delete support staff.', 'fluent-support'),
59 403
60 );
61 }
62 }
63