2024-01-10 14:49:46 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Policies;
|
|
|
|
|
|
|
|
|
|
use App\Enums\Users\RoleEnum;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Policies\Rules\UserStaticRules;
|
2026-09-28 10:56:08 +02:00
|
|
|
use Illuminate\Contracts\Foundation\Application;
|
2024-09-03 09:50:15 +02:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2024-01-10 14:49:46 +01:00
|
|
|
|
|
|
|
|
class UserPolicy
|
|
|
|
|
{
|
2026-09-28 10:56:08 +02:00
|
|
|
public function __construct(
|
|
|
|
|
private Application $application
|
|
|
|
|
) {}
|
|
|
|
|
|
2024-01-10 14:49:46 +01:00
|
|
|
/**
|
|
|
|
|
* Determine whether the user can view any models.
|
|
|
|
|
*/
|
2024-09-03 09:50:15 +02:00
|
|
|
public function viewAny(Model $authModel): bool
|
2024-01-10 14:49:46 +01:00
|
|
|
{
|
2024-12-03 16:52:10 +01:00
|
|
|
return UserStaticRules::atLeastRole($authModel, RoleEnum::conceptor);
|
2024-01-10 14:49:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine whether the user can view the model.
|
|
|
|
|
*/
|
2024-09-06 14:50:39 +02:00
|
|
|
public function view(Model $authModel, User $user): bool
|
2024-01-10 14:49:46 +01:00
|
|
|
{
|
2026-09-25 16:25:31 +02:00
|
|
|
return $authModel->getRouteKey() === $user->getRouteKey() || UserStaticRules::atLeastRole($authModel, RoleEnum::conceptor);
|
2024-01-10 14:49:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine whether the user can create models.
|
|
|
|
|
*/
|
2024-09-06 14:50:39 +02:00
|
|
|
public function create(Model $authModel): bool
|
2024-01-10 14:49:46 +01:00
|
|
|
{
|
2024-12-03 16:52:10 +01:00
|
|
|
return UserStaticRules::atLeastRole($authModel, RoleEnum::conceptor);
|
2024-01-10 14:49:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine whether the user can update the model.
|
|
|
|
|
*/
|
2024-09-06 14:50:39 +02:00
|
|
|
public function update(Model $authModel, User $user): bool
|
2024-01-10 14:49:46 +01:00
|
|
|
{
|
2026-09-25 16:25:31 +02:00
|
|
|
return $authModel->getRouteKey() === $user->getRouteKey() || UserStaticRules::atLeastRole($authModel, RoleEnum::conceptor);
|
2024-01-10 14:49:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine whether the user can delete the model.
|
|
|
|
|
*/
|
2024-09-06 14:50:39 +02:00
|
|
|
public function delete(Model $authModel, User $user): bool
|
2024-01-10 14:49:46 +01:00
|
|
|
{
|
2026-09-25 16:25:31 +02:00
|
|
|
return $authModel->getRouteKey() !== $user->getRouteKey() && UserStaticRules::atLeastRole($authModel, RoleEnum::conceptor);
|
2024-01-10 14:49:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine whether the user can duplicate the model.
|
|
|
|
|
*/
|
2024-09-06 14:50:39 +02:00
|
|
|
public function duplicate(Model $authModel, User $user): bool
|
2024-01-10 14:49:46 +01:00
|
|
|
{
|
2026-09-28 10:56:08 +02:00
|
|
|
return $authModel->getRouteKey() !== $user->getRouteKey() && UserStaticRules::atLeastRole($authModel, RoleEnum::conceptor);
|
2024-01-10 14:49:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine whether the user can publish/unpublish the model.
|
|
|
|
|
*/
|
2024-09-06 14:50:39 +02:00
|
|
|
public function changePublished(Model $authModel, User $user): bool
|
2024-01-10 14:49:46 +01:00
|
|
|
{
|
2026-09-28 10:56:08 +02:00
|
|
|
return $authModel->getRouteKey() !== $user->getRouteKey() && UserStaticRules::atLeastRole($authModel, RoleEnum::conceptor);
|
2024-01-10 14:49:46 +01:00
|
|
|
}
|
2026-09-23 09:42:01 +02:00
|
|
|
|
|
|
|
|
public function testMails(User $user): bool
|
|
|
|
|
{
|
2026-09-28 10:56:08 +02:00
|
|
|
return !$this->application->environment('production') && $user->role->value <= RoleEnum::admin->value;
|
2026-09-23 09:42:01 +02:00
|
|
|
}
|
2024-01-10 14:49:46 +01:00
|
|
|
}
|