Files
scrum-poker-internal/app/Http/Requests/KickRoomPlayerRequest.php
T

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->activePlayers()->find((int) $playerId);
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, array<int, string>>
*/
public function rules(): array
{
return [];
}
}