| @@ -11,9 +11,8 @@ | ||
| 11 | 11 | */ |
| 12 | 12 | class CustomerPolicy extends Policy |
| 13 | 13 | { |
| 14 | 14 | /** |
| 15 | - * Check user permission for any method | |
| 16 | 15 | * @param \FluentSupport\Framework\Http\Request\Request $request |
| 17 | 16 | * @return Boolean |
| 18 | 17 | */ |
| 19 | 18 | public function verifyRequest(Request $request) |
| @@ -20,19 +19,13 @@ | ||
| 20 | 19 | { |
| 21 | 20 | return PermissionManager::currentUserCan('fst_sensitive_data'); |
| 22 | 21 | } |
| 23 | 22 | |
| 24 | - /** | |
| 25 | - * Deleting a single customer. | |
| 26 | - */ | |
| 27 | 23 | public function delete(Request $request) |
| 28 | 24 | { |
| 29 | 25 | return $this->guardCustomerDeletion($request); |
| 30 | 26 | } |
| 31 | 27 | |
| 32 | - /** | |
| 33 | - * Deleting multiple customers in one request. | |
| 34 | - */ | |
| 35 | 28 | public function bulkDelete(Request $request) |
| 36 | 29 | { |
| 37 | 30 | return $this->guardCustomerDeletion($request); |
| 38 | 31 | } |
| @@ -41,13 +34,10 @@ | ||
| 41 | 34 | * Deletion cascades into tickets, conversations and attachments. |
| 42 | 35 | */ |
| 43 | 36 | protected function guardCustomerDeletion(Request $request) |
| 44 | 37 | { |
| 45 | - // The router runs EITHER the per-route method OR verifyRequest(), never both | |
| 46 | - // (FoundationTrait.php:120-122), so re-apply the module boundary here. | |
| 47 | - // The exception code is carried through as the HTTP status by | |
| 48 | - // Route::permissionCallback(), which falls back to 403 when the code is 0. | |
| 49 | - // Pass it explicitly so an unauthenticated caller gets the canonical 401. | |
| 38 | + // The router runs either the per-route method or verifyRequest(), not both, | |
| 39 | + // so re-apply the module boundary. The exception code becomes the HTTP status. | |
| 50 | 40 | if (!$this->verifyRequest($request)) { |
| 51 | 41 | throw new \Exception( |
| 52 | 42 | esc_html__('You do not have permission to manage customers.', 'fluent-support'), |
| 53 | 43 | is_user_logged_in() ? 403 : 401 |
| @@ -53,16 +43,13 @@ | ||
| 53 | 43 | is_user_logged_in() ? 403 : 401 |
| 54 | 44 | ); |
| 55 | 45 | } |
| 56 | 46 | |
| 57 | - // By default this also needs manage_options, a capability the plugin cannot mint. | |
| 58 | - // Sites can drop that requirement with the filter below; the boundary above still | |
| 59 | - // applies either way. Throwing gives a specific 403. | |
| 47 | + // manage_options can't be granted by the plugin's own permissions. | |
| 48 | + // Sites can drop this requirement. The boundary above still applies. | |
| 60 | 49 | $requiresAdmin = apply_filters('fluent_support/customer_delete_requires_admin', true); |
| 61 | 50 | |
| 62 | 51 | if ($requiresAdmin && !current_user_can('manage_options')) { |
| 63 | - // Only reachable by a logged-in user who already cleared the module | |
| 64 | - // boundary above, so 403 is always the right status here. | |
| 65 | 52 | throw new \Exception( |
| 66 | 53 | esc_html__('Only administrators can delete customers.', 'fluent-support'), |
| 67 | 54 | 403 |
| 68 | 55 | ); |