public function editAction(Player $player, Player $me) { if (!$me->canEdit($player)) { throw new ForbiddenException("You are not allowed to edit other players"); } $params = array('me' => $player, 'self' => false); return $this->forward('edit', $params, 'Profile'); }
public function showAction(Server $server, Player $me, Request $request) { if ($server->staleInfo()) { $server->forceUpdate(); } if ($request->get('forced') && $me->canEdit($server)) { $server->forceUpdate(); } return array("server" => $server); }
public function inviteAction(Team $team, Player $player, Player $me) { if (!$me->canEdit($team)) { throw new ForbiddenException("You are not allowed to invite a player to that team!"); } elseif ($team->isMember($player->getId())) { throw new ForbiddenException("The specified player is already a member of that team."); } elseif (Invitation::hasOpenInvitation($player->getId(), $team->getId())) { throw new ForbiddenException("This player has already been invited to join the team."); } return $this->showConfirmationForm(function () use($team, $player, $me) { $invite = Invitation::sendInvite($player->getId(), $me->getId(), $team->getId()); Service::getDispatcher()->dispatch(Events::TEAM_INVITE, new TeamInviteEvent($invite)); return new RedirectResponse($team->getUrl()); }, "Are you sure you want to invite {$player->getEscapedUsername()} to {$team->getEscapedName()}?", "Player {$player->getUsername()} has been invited to {$team->getName()}"); }
public function recalculateAction(Player $me, $match) { $match = Match::get($match); // get a match even if it's deleted if (!$me->canEdit($match)) { throw new ForbiddenException("You are not allowed to edit that match."); } return $this->showConfirmationForm(function () use($match) { $response = new StreamedResponse(); $response->headers->set('Content-Type', 'text/plain'); $response->setCallback(function () use($match) { $this->recalculate($match); }); $response->send(); }, "Do you want to recalculate ELO history for all teams and matches after the specified match?", "ELO history recalculated", "Recalculate ELOs", function () use($match) { if ($match->isDeleted()) { return new RedirectResponse($match->getURL('list')); } return new RedirectResponse($match->getURL('show')); }, "Match/recalculate.html.twig", $noButton = true); }
/** * Find whether a player can edit a model * * @param Player $player The player who wants to delete the model * @param PermissionModel $model The model which will be edited * @return bool */ protected function canEdit($player, $model) { return $player->canEdit($model); }
public function teamLeaveAction(Player $me, Conversation $conversation) { $team = $me->getTeam(); if (!$me->canEdit($team)) { throw new ForbiddenException("You are not allowed to remove your team from this conversation."); } elseif (!$conversation->isMember($team)) { throw new ForbiddenException("That team is not participating in this conversation."); } return $this->showConfirmationForm(function () use($conversation, $team) { $conversation->removeMember($team); $event = new ConversationAbandonEvent($conversation, $team); Service::getDispatcher()->dispatch(Events::CONVERSATION_ABANDON, $event); return new RedirectResponse($conversation->getURL()); }, "Are you sure you want to remove {$team->getEscapedName()} from this conversation?", "Your team is no longer participating in that conversation.", "Remove team"); }
/** * Make sure that a player can edit a team * * Throws an exception if a player is not an admin or the leader of a team * @throws HTTPException * @param Player $player The player to test * @param Team $team The team * @param string $message The error message to show * @return void */ private function assertCanEdit(Player $player, Team $team, $message = "You are not allowed to edit that team") { if (!$player->canEdit($team)) { throw new ForbiddenException($message); } }