| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Http\Policies; |
| 4 |
|
| 5 |
use FluentCart\App\Services\Permission\PermissionManager; |
| 6 |
use FluentCart\Framework\Http\Request\Request; |
| 7 |
|
| 8 |
/** |
| 9 |
* Unlike the other policies here, this one deliberately does not read the |
| 10 |
* route's permission meta. |
| 11 |
* |
| 12 |
* The endpoint it guards serves many unrelated data sets behind one URL — |
| 13 |
* product variations, labels, attributes, tax states — so a single route-level |
| 14 |
* permission would have to be the union of all of them, and would let anyone |
| 15 |
* holding the weakest one read the data behind the strongest. The check that |
| 16 |
* matters is per data key, and only the controller knows which key was asked |
| 17 |
* for. |
| 18 |
* |
| 19 |
* So this is the outer door: it keeps non-admins out entirely, and leaves |
| 20 |
* AdvanceFilterController::resolvePermission() to decide who may read what. |
| 21 |
* |
| 22 |
* @package FluentCart\App\Http\Policies |
| 23 |
* |
| 24 |
* @version 1.0.0 |
| 25 |
*/ |
| 26 |
class AdvanceFilterPolicy extends Policy |
| 27 |
{ |
| 28 |
/** |
| 29 |
* @param Request $request |
| 30 |
* @return bool |
| 31 |
*/ |
| 32 |
public function verifyRequest(Request $request): bool |
| 33 |
{ |
| 34 |
/* |
| 35 |
* getUserPermissions() is empty for anyone without a FluentCart role, |
| 36 |
* which is the distinction wanted here — a logged-in customer must not |
| 37 |
* reach the controller at all. Deliberately not Helper::getCurrentUser(), |
| 38 |
* which resolves for every logged-in WordPress user. |
| 39 |
*/ |
| 40 |
return !empty(PermissionManager::getUserPermissions()); |
| 41 |
} |
| 42 |
} |
| 43 |
|