mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 16:12:09 +00:00
64 lines
1.6 KiB
PHP
64 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Models\Player;
|
|
use App\Models\Room;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class KickRoomPlayerRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
$room = $this->route('room');
|
|
$targetPlayer = $this->route('player');
|
|
|
|
if (
|
|
! $room instanceof Room
|
|
|| ! $targetPlayer instanceof Player
|
|
|| $targetPlayer->room_id !== $room->id
|
|
|| $targetPlayer->is_moderator
|
|
|| ($room->owner_id !== null && $targetPlayer->user_id === $room->owner_id)
|
|
) {
|
|
return false;
|
|
}
|
|
|
|
$user = $this->user();
|
|
|
|
if ($user !== null && $user->id === $room->owner_id) {
|
|
return true;
|
|
}
|
|
|
|
$currentPlayer = $this->currentPlayer($room);
|
|
|
|
return ! $room->isClosed()
|
|
&& $currentPlayer !== null
|
|
&& $currentPlayer->id !== $targetPlayer->id
|
|
&& ($currentPlayer->is_moderator || $room->allow_participants_to_manage_rounds);
|
|
}
|
|
|
|
public function currentPlayer(Room $room): ?Player
|
|
{
|
|
$playerId = $this->session()->get("room_players.{$room->id}");
|
|
|
|
if (! is_numeric($playerId)) {
|
|
return null;
|
|
}
|
|
|
|
return $room->players()->find((int) $playerId);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, array<int, string>>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [];
|
|
}
|
|
}
|