42 lines
1.0 KiB
PHP
42 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Enums\RoleEnum;
|
|
use App\Models\User;
|
|
|
|
class UserPolicy
|
|
{
|
|
public function view(User $user, User $showedUser)
|
|
{
|
|
if($user->role == RoleEnum::ADMIN) {
|
|
return true;
|
|
}
|
|
if($user->role == RoleEnum::DISPATCHER) {
|
|
return $user->warehouse_id == $showedUser->warehouse_id;
|
|
}
|
|
|
|
return $user->role == $showedUser->role && $user->warehouse_id == $showedUser->warehouse_id;
|
|
}
|
|
|
|
public function create(User $user)
|
|
{
|
|
return $user->role == RoleEnum::ADMIN;
|
|
}
|
|
|
|
public function update(User $user, User $updatedUser)
|
|
{
|
|
return $user->role == RoleEnum::ADMIN && $user->warehouse_id == $updatedUser->warehouse_id;
|
|
}
|
|
|
|
public function delete(User $user, User $deletedUser)
|
|
{
|
|
return $user->role == RoleEnum::ADMIN && $user->warehouse_id == $deletedUser->warehouse_id;
|
|
}
|
|
|
|
public function viewCar(User $user, User $carUser)
|
|
{
|
|
return $carUser->role == RoleEnum::DRIVER;
|
|
}
|
|
}
|