feat: api admin user and game policies
This commit is contained in:
@@ -12,9 +12,6 @@ class GamePolicy
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
if ($user->blocked === 1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,12 +20,9 @@ class GamePolicy
|
||||
*/
|
||||
public function view(User $user, Game $game): bool
|
||||
{
|
||||
if ($user->type === "A") {
|
||||
if ($user->type === 'A') {
|
||||
return true;
|
||||
}
|
||||
if ($user->blocked === 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
$game->player1_user_id === $user->id ||
|
||||
@@ -45,7 +39,7 @@ class GamePolicy
|
||||
*/
|
||||
public function create(User $user): bool
|
||||
{
|
||||
if ($user->type === "A" || $user->blocked === 1) {
|
||||
if ($user->type === 'A') {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -54,12 +48,12 @@ class GamePolicy
|
||||
|
||||
public function join(User $user, Game $game): bool
|
||||
{
|
||||
if ($user->type === "A" || $user->blocked === 1) {
|
||||
if ($user->type === 'A') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
$game->status !== "waiting" ||
|
||||
$game->status !== 'waiting' ||
|
||||
$game->player1_user_id === $user->id
|
||||
) {
|
||||
return false;
|
||||
@@ -70,12 +64,12 @@ class GamePolicy
|
||||
|
||||
public function resign(User $user, Game $game): bool
|
||||
{
|
||||
if ($user->type === "A" || $user->blocked === 1) {
|
||||
if ($user->type === 'A') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
$game->status !== "ongoing" ||
|
||||
$game->status !== 'ongoing' ||
|
||||
($game->player1_user_id !== $user->id &&
|
||||
$game->player2_user_id !== $user->id)
|
||||
) {
|
||||
@@ -90,12 +84,12 @@ class GamePolicy
|
||||
*/
|
||||
public function update(User $user, Game $game): bool
|
||||
{
|
||||
if ($user->type === "A" || $user->blocked === 1) {
|
||||
if ($user->type === 'A') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
$game->status !== "ongoing" ||
|
||||
$game->status !== 'ongoing' ||
|
||||
($game->player1_user_id !== $user->id &&
|
||||
$game->player2_user_id !== $user->id)
|
||||
) {
|
||||
@@ -110,7 +104,8 @@ class GamePolicy
|
||||
*/
|
||||
public function delete(User $user, Game $game): bool
|
||||
{
|
||||
return false;
|
||||
// Only admins can delete games
|
||||
return $user->type === 'A';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user