diff --git a/app/Policies/AccountPolicy.php b/app/Policies/AccountPolicy.php index 5c409f0d..46fad420 100644 --- a/app/Policies/AccountPolicy.php +++ b/app/Policies/AccountPolicy.php @@ -4,16 +4,11 @@ namespace App\Policies; use App\Models\Account; use App\Models\User; +use App\Policies\Concerns\HandlesUserOwnership; class AccountPolicy { - /** - * Determine whether the user can view any models. - */ - public function viewAny(User $user): bool - { - return false; - } + use HandlesUserOwnership; /** * Determine whether the user can view the model. @@ -22,44 +17,4 @@ class AccountPolicy { return $user->id === $account->user_id; } - - /** - * Determine whether the user can create models. - */ - public function create(User $user): bool - { - return false; - } - - /** - * Determine whether the user can update the model. - */ - public function update(User $user, Account $account): bool - { - return $user->id === $account->user_id; - } - - /** - * Determine whether the user can delete the model. - */ - public function delete(User $user, Account $account): bool - { - return $user->id === $account->user_id; - } - - /** - * Determine whether the user can restore the model. - */ - public function restore(User $user, Account $account): bool - { - return false; - } - - /** - * Determine whether the user can permanently delete the model. - */ - public function forceDelete(User $user, Account $account): bool - { - return false; - } } diff --git a/app/Policies/AutomationRulePolicy.php b/app/Policies/AutomationRulePolicy.php index 8b31a29a..320bb02d 100644 --- a/app/Policies/AutomationRulePolicy.php +++ b/app/Policies/AutomationRulePolicy.php @@ -2,64 +2,9 @@ namespace App\Policies; -use App\Models\AutomationRule; -use App\Models\User; +use App\Policies\Concerns\HandlesUserOwnership; class AutomationRulePolicy { - /** - * Determine whether the user can view any models. - */ - public function viewAny(User $user): bool - { - return false; - } - - /** - * Determine whether the user can view the model. - */ - public function view(User $user, AutomationRule $automationRule): bool - { - return false; - } - - /** - * Determine whether the user can create models. - */ - public function create(User $user): bool - { - return false; - } - - /** - * Determine whether the user can update the model. - */ - public function update(User $user, AutomationRule $automationRule): bool - { - return $user->id === $automationRule->user_id; - } - - /** - * Determine whether the user can delete the model. - */ - public function delete(User $user, AutomationRule $automationRule): bool - { - return $user->id === $automationRule->user_id; - } - - /** - * Determine whether the user can restore the model. - */ - public function restore(User $user, AutomationRule $automationRule): bool - { - return false; - } - - /** - * Determine whether the user can permanently delete the model. - */ - public function forceDelete(User $user, AutomationRule $automationRule): bool - { - return false; - } + use HandlesUserOwnership; } diff --git a/app/Policies/CategoryPolicy.php b/app/Policies/CategoryPolicy.php index 04769915..d3648cdc 100644 --- a/app/Policies/CategoryPolicy.php +++ b/app/Policies/CategoryPolicy.php @@ -2,64 +2,9 @@ namespace App\Policies; -use App\Models\Category; -use App\Models\User; +use App\Policies\Concerns\HandlesUserOwnership; class CategoryPolicy { - /** - * Determine whether the user can view any models. - */ - public function viewAny(User $user): bool - { - return false; - } - - /** - * Determine whether the user can view the model. - */ - public function view(User $user, Category $category): bool - { - return false; - } - - /** - * Determine whether the user can create models. - */ - public function create(User $user): bool - { - return false; - } - - /** - * Determine whether the user can update the model. - */ - public function update(User $user, Category $category): bool - { - return $user->id === $category->user_id; - } - - /** - * Determine whether the user can delete the model. - */ - public function delete(User $user, Category $category): bool - { - return $user->id === $category->user_id; - } - - /** - * Determine whether the user can restore the model. - */ - public function restore(User $user, Category $category): bool - { - return false; - } - - /** - * Determine whether the user can permanently delete the model. - */ - public function forceDelete(User $user, Category $category): bool - { - return false; - } + use HandlesUserOwnership; } diff --git a/app/Policies/Concerns/HandlesUserOwnership.php b/app/Policies/Concerns/HandlesUserOwnership.php new file mode 100644 index 00000000..3a4b2a8e --- /dev/null +++ b/app/Policies/Concerns/HandlesUserOwnership.php @@ -0,0 +1,65 @@ +id === $model->getAttribute('user_id'); + } + + /** + * Determine whether the user can delete the model. + */ + public function delete(User $user, Model $model): bool + { + return $user->id === $model->getAttribute('user_id'); + } + + /** + * Determine whether the user can restore the model. + */ + public function restore(User $user, Model $model): bool + { + return false; + } + + /** + * Determine whether the user can permanently delete the model. + */ + public function forceDelete(User $user, Model $model): bool + { + return false; + } +} diff --git a/app/Policies/LabelPolicy.php b/app/Policies/LabelPolicy.php index 98403610..e5b1bc45 100644 --- a/app/Policies/LabelPolicy.php +++ b/app/Policies/LabelPolicy.php @@ -2,64 +2,9 @@ namespace App\Policies; -use App\Models\Label; -use App\Models\User; +use App\Policies\Concerns\HandlesUserOwnership; class LabelPolicy { - /** - * Determine whether the user can view any models. - */ - public function viewAny(User $user): bool - { - return false; - } - - /** - * Determine whether the user can view the model. - */ - public function view(User $user, Label $label): bool - { - return false; - } - - /** - * Determine whether the user can create models. - */ - public function create(User $user): bool - { - return false; - } - - /** - * Determine whether the user can update the model. - */ - public function update(User $user, Label $label): bool - { - return $user->id === $label->user_id; - } - - /** - * Determine whether the user can delete the model. - */ - public function delete(User $user, Label $label): bool - { - return $user->id === $label->user_id; - } - - /** - * Determine whether the user can restore the model. - */ - public function restore(User $user, Label $label): bool - { - return false; - } - - /** - * Determine whether the user can permanently delete the model. - */ - public function forceDelete(User $user, Label $label): bool - { - return false; - } + use HandlesUserOwnership; } diff --git a/app/Policies/TransactionPolicy.php b/app/Policies/TransactionPolicy.php index d766b970..972a1bc8 100644 --- a/app/Policies/TransactionPolicy.php +++ b/app/Policies/TransactionPolicy.php @@ -2,43 +2,9 @@ namespace App\Policies; -use App\Models\Transaction; -use App\Models\User; +use App\Policies\Concerns\HandlesUserOwnership; class TransactionPolicy { - public function viewAny(User $user): bool - { - return false; - } - - public function view(User $user, Transaction $transaction): bool - { - return false; - } - - public function create(User $user): bool - { - return false; - } - - public function update(User $user, Transaction $transaction): bool - { - return $user->id === $transaction->user_id; - } - - public function delete(User $user, Transaction $transaction): bool - { - return $user->id === $transaction->user_id; - } - - public function restore(User $user, Transaction $transaction): bool - { - return false; - } - - public function forceDelete(User $user, Transaction $transaction): bool - { - return false; - } + use HandlesUserOwnership; }