security->getUser(); if (is_null($userEntity)) { throw new HttpException(Response::HTTP_FORBIDDEN, "Unauthorized."); } $customRole = $this->customRoleRepository->findBy([ 'name' => $leagueId . Role::LEAGUE_PRESIDENT->value, 'userEntity' => $userEntity ]); if (is_null($customRole)) { throw new HttpException(Response::HTTP_FORBIDDEN, "Usuario no tiene permiso para editar la liga."); } } public function teamCaptainRequest(int $leagueId, $teamId): User { $userEntity = $this->security->getUser(); if (!$userEntity instanceof User) { throw new HttpException(Response::HTTP_FORBIDDEN, "Unauthorized"); } $captainCustomRole = $this->customRoleRepository->findBy([ 'name' => $teamId . Role::TEAM_CAPTAIN->value, ]); if (!is_null($captainCustomRole)) { throw new HttpException(Response::HTTP_FORBIDDEN, "Equipo con id: $teamId ya tiene capitan"); } $leagueMemberRole = $this->customRoleRepository->findBy([ 'name' => $leagueId . Role::LEAGUE_MEMBER->value, 'user' => $userEntity ]); if (is_null($leagueMemberRole)) { throw new HttpException(Response::HTTP_FORBIDDEN, "Usuario no es miembro de la liga"); } return $userEntity; } public function isLeaguePresident(int $leagueId, User $leagueAdmin): bool { $adminRoles = $leagueAdmin->getCustomRoles(); if (!$adminRoles->isEmpty()) { foreach ($adminRoles as $adminRoleEntity) { $explodedRole = explode('_', $adminRoleEntity->getName()); if ( strtolower($explodedRole[1]) == 'league' && strtolower($explodedRole[2]) == 'president' && $explodedRole[0] == $leagueId ) { return true; } } } throw new HttpException(Response::HTTP_NOT_FOUND,'Forbidden.'); } }