From 9ab1e0c84b68cd9caae2c9df9640ff910b909d76 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 14 Apr 2025 00:21:57 -0600 Subject: [PATCH] Update CustomFilterPolicy --- app/Policies/CustomFilterPolicy.php | 39 ++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/app/Policies/CustomFilterPolicy.php b/app/Policies/CustomFilterPolicy.php index 11699ea95..5c3d9669a 100644 --- a/app/Policies/CustomFilterPolicy.php +++ b/app/Policies/CustomFilterPolicy.php @@ -3,20 +3,57 @@ namespace App\Policies; use App\Models\CustomFilter; -use App\Models\User; +use App\User; class CustomFilterPolicy { + /** + * Determine whether the user can view any models. + */ + public function viewAny(User $user): bool + { + return false; + } + + /** + * Determine whether the user can view the custom filter. + * + * @param \App\User $user + * @param \App\Models\CustomFilter $filter + * @return bool + */ public function view(User $user, CustomFilter $filter) { return $user->profile_id === $filter->profile_id; } + /** + * Determine whether the user can create models. + */ + public function create(User $user): bool + { + return CustomFilter::whereProfileId($user->profile_id)->count() <= 100; + } + + /** + * Determine whether the user can update the custom filter. + * + * @param \App\User $user + * @param \App\Models\CustomFilter $filter + * @return bool + */ public function update(User $user, CustomFilter $filter) { return $user->profile_id === $filter->profile_id; } + /** + * Determine whether the user can delete the custom filter. + * + * @param \App\User $user + * @param \App\Models\CustomFilter $filter + * @return bool + */ public function delete(User $user, CustomFilter $filter) { return $user->profile_id === $filter->profile_id;