HoshiAI-be/app/Policies/UserTestPolicy.php
2025-11-12 23:04:55 +01:00

72 lines
1.6 KiB
PHP

<?php
namespace App\Policies;
use App\Models\User;
use App\Models\UserTest;
use Illuminate\Auth\Access\Response;
class UserTestPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return true;
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, UserTest $userTest): bool
{
return $user->id == $userTest->user_id || $user->type == 'creator' || $user->type == 'admin';
}
public function canBeEdit(User $user, UserTest $userTest): bool
{
return ($user->id == $userTest->user_id && $userTest->isAvailable()) || $user->type == 'creator' || $user->type == 'admin';
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return $user->type != 'banned';
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, UserTest $userTest): bool
{
return $user->type == 'admin';
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, UserTest $userTest): bool
{
return $user->type == 'admin';
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, UserTest $userTest): bool
{
return false;
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, UserTest $userTest): bool
{
return false;
}
}