diff --git a/app/Policies/ClaimPolicy.php b/app/Policies/ClaimPolicy.php index 0d4c23a..a6ea601 100644 --- a/app/Policies/ClaimPolicy.php +++ b/app/Policies/ClaimPolicy.php @@ -3,6 +3,7 @@ namespace App\Policies; use App\Enums\Users\RoleEnum; +use App\Models\Claim; use App\Models\User; use Illuminate\Auth\Access\HandlesAuthorization; use App\Policies\Rules\UserStaticRules as USR; @@ -12,16 +13,6 @@ class ClaimPolicy { use HandlesAuthorization; - /** - * View a Claim. - * - * @return boolean - */ - public function view(): bool - { - return USR::everyOne(); - } - /** * View any a Claim. * @@ -35,21 +26,25 @@ class ClaimPolicy /** * Preview a Claim. * + * @param \App\Models\User $authUser + * @param \App\Models\Claim $claim * @return boolean */ - public function preview(): bool + public function preview(User $authUser, Claim $claim): bool { - return USR::everyOne(); + return $this->checkOnlyMinAdminOrInUserBrands($authUser, $claim); } /** * Update a Claim. * + * @param \App\Models\User $authUser + * @param \App\Models\Claim $claim * @return boolean */ - public function update(): bool + public function update(User $authUser, Claim $claim): bool { - return USR::everyOne(); + return $this->checkOnlyMinAdminOrInUserBrands($authUser, $claim); } /** @@ -66,40 +61,65 @@ class ClaimPolicy /** * Determine whether the user can update the associated subject of the model. * + * @param \App\Models\User $authUser + * @param \App\Models\Claim $claim * @return boolean */ - public function updateSubject(): bool + public function updateSubject(User $authUser, Claim $claim): bool { - return USR::everyOne(); + return $this->checkOnlyMinAdminOrInUserBrands($authUser, $claim); } /** * Update a Claim. * + * @param \App\Models\User $authUser + * @param \App\Models\Claim $claim * @return boolean */ - public function updateType(): bool + public function updateType(User $authUser, Claim $claim): bool { - return USR::everyOne(); + return $this->checkOnlyMinAdminOrInUserBrands($authUser, $claim); } /** * Update a Claim. * + * @param \App\Models\User $authUser + * @param \App\Models\Claim $claim * @return boolean */ - public function updateStatus(): bool + public function updateStatus(User $authUser, Claim $claim): bool { - return USR::everyOne(); + return $this->checkOnlyMinAdminOrInUserBrands($authUser, $claim); } /** * Update a Claim. * + * @param \App\Models\User $authUser + * @param \App\Models\Claim $claim * @return boolean */ - public function updateResponseType(): bool + public function updateResponseType(User $authUser, Claim $claim): bool { - return USR::everyOne(); + return $this->checkOnlyMinAdminOrInUserBrands($authUser, $claim); + } + + /** + * Check if the user an access a specific resource. + * + * @param \App\Models\User $authUser + * @param \App\Models\Claim $claim + * @return boolean + */ + private function checkOnlyMinAdminOrInUserBrands(User $authUser, Claim $claim): bool + { + $userBrandModelKeys = $authUser->brands->modelKeys(); + $claimModelKey = $claim->brand->getKey(); + return UserStaticRules::atLeastRole($authUser, RoleEnum::admin) || ( + UserStaticRules::atLeastRole($authUser, RoleEnum::marketing) + && \in_array($claimModelKey, $userBrandModelKeys) + ); } } diff --git a/resources/views/bo/pages/claims/edit.blade.php b/resources/views/bo/pages/claims/edit.blade.php index 926c5c7..1ad0110 100644 --- a/resources/views/bo/pages/claims/edit.blade.php +++ b/resources/views/bo/pages/claims/edit.blade.php @@ -5,90 +5,101 @@ @section('breadcrumb', request()->route()->getName()) @section('content') -
{{ e($claimModel->email) }}
- @if ($claimModel->customer && auth()->user()->can('view', $claimModel->customer)) - - {{ __('Lien vers la fiche client') }} - - - @endif - @if ($claimModel->getFormatedAddress()) -{{ $claimModel->getFormatedAddress() ? e($claimModel->getFormatedAddress()) : null }}
- @endif -Fichier:
- - {{ __('Voir la pièce jointe associée') }} +{{ e($claimModel->email) }}
+ @if ($claimModel->customer && auth()->user()->can('view', $claimModel->customer)) + + {{ __('Lien vers la fiche client') }} + -+ {{ $claimModel->getFormatedAddress() ? e($claimModel->getFormatedAddress()) : null }} +
+ @endif +Fichier:
+ + {{ __('Voir la pièce jointe associée') }} + +