Resolve "Donner l'accès aux services Marketing" See merge request ldc-web/projets/qrcollector/qrcollector-back!25
86 lines
2.4 KiB
PHP
86 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Enums\Users\RoleEnum;
|
|
use App\Models\Url;
|
|
use App\Models\User;
|
|
use App\Policies\Rules\UserStaticRules;
|
|
|
|
class UrlPolicy
|
|
{
|
|
/**
|
|
* Determine whether the user can view any models.
|
|
*
|
|
* @param \App\Models\User $authUser
|
|
* @return boolean
|
|
*/
|
|
public function viewAny(User $authUser): bool
|
|
{
|
|
return UserStaticRules::atLeastRole($authUser, RoleEnum::marketing);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can view the model.
|
|
*
|
|
* @param \App\Models\User $authUser
|
|
* @param \App\Models\Url $url
|
|
* @return boolean
|
|
*/
|
|
public function view(User $authUser, Url $url): bool
|
|
{
|
|
return (UserStaticRules::atLeastRole($authUser, RoleEnum::marketing) &&
|
|
\collect($authUser->brands->pluck('id'))->contains($url->brand->id)) ||
|
|
UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can create a new model.
|
|
*
|
|
* @param \App\Models\User $authUser
|
|
* @return boolean
|
|
*/
|
|
public function create(User $authUser): bool
|
|
{
|
|
return UserStaticRules::atLeastRole($authUser, RoleEnum::marketing);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can update the model.
|
|
*
|
|
* @param \App\Models\User $authUser
|
|
* @param \App\Models\Url $url
|
|
* @return boolean
|
|
*/
|
|
public function update(User $authUser, Url $url): bool
|
|
{
|
|
return (UserStaticRules::atLeastRole($authUser, RoleEnum::marketing) &&
|
|
\collect($authUser->brands->pluck('id'))->contains($url->brand->id)) ||
|
|
UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can duplicate the model.
|
|
*
|
|
* @param \App\Models\User $authUser
|
|
* @param \App\Models\Url $url
|
|
* @return boolean
|
|
*/
|
|
public function duplicate(User $authUser, Url $url): bool
|
|
{
|
|
return (UserStaticRules::atLeastRole($authUser, RoleEnum::marketing) &&
|
|
\collect($authUser->brands->pluck('id'))->contains($url->brand->id)) ||
|
|
UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can delete the model.
|
|
*
|
|
* @param \App\Models\User $authUser
|
|
* @return boolean
|
|
*/
|
|
public function delete(User $authUser): bool
|
|
{
|
|
return UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor);
|
|
}
|
|
}
|