| @@ -8,15 +8,14 @@ | ||
| 8 | 8 | |
| 9 | 9 | class AgentPolicy extends Policy |
| 10 | 10 | { |
| 11 | 11 | /** |
| 12 | - * Check user permission for any method | |
| 13 | 12 | * @param \FluentSupport\Framework\Http\Request\Request $request |
| 14 | 13 | * @return Boolean |
| 15 | 14 | */ |
| 16 | 15 | public function verifyRequest(Request $request) |
| 17 | 16 | { |
| 18 | - // Read access (index) and avatar routes keep the existing boundary. | |
| 17 | + // Only reached by routes without their own method here (index, avatar). | |
| 19 | 18 | return PermissionManager::currentUserCan('fst_sensitive_data'); |
| 20 | 19 | } |
| 21 | 20 | |
| 22 | 21 | public function addAgent(Request $request) |
| @@ -34,13 +33,11 @@ | ||
| 34 | 33 | return $this->guardManageOptions(); |
| 35 | 34 | } |
| 36 | 35 | |
| 37 | 36 | /** |
| 38 | - * Agent records carry the plugin's permission set, so mutating them is a | |
| 39 | - * privilege-granting operation. Gate on a WordPress capability the plugin's | |
| 40 | - * own permission system cannot mint (FS-SEC-003). Throwing (not returning | |
| 41 | - * false) surfaces a specific 403 message instead of WordPress core's | |
| 42 | - * generic "Sorry, you are not allowed to do that." | |
| 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. | |
| 43 | 40 | * |
| 44 | 41 | * @return Boolean |
| 45 | 42 | * @throws \Exception |
| 46 | 43 | */ |
| @@ -49,9 +46,17 @@ | ||
| 49 | 46 | if (current_user_can('manage_options')) { |
| 50 | 47 | return true; |
| 51 | 48 | } |
| 52 | 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 | + | |
| 53 | 57 | throw new \Exception( |
| 54 | - esc_html__('Only administrators can add, edit, or delete support staff.', 'fluent-support') | |
| 58 | + esc_html__('Only administrators can add, edit, or delete support staff.', 'fluent-support'), | |
| 59 | + 403 | |
| 55 | 60 | ); |
| 56 | 61 | } |
| 57 | 62 | } |