Skip to content

Commit

Permalink
Multiple ESI Tokens #32
Browse files Browse the repository at this point in the history
- Add eve logins to apps.
  • Loading branch information
tkhamez committed Aug 29, 2021
1 parent 899eaf6 commit 5190aae
Show file tree
Hide file tree
Showing 13 changed files with 455 additions and 134 deletions.
28 changes: 15 additions & 13 deletions backend/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,21 @@
'/api/app/v1/groups-with-fallback' => ['GET', [AppGroupController::class, 'groupsWithFallbackV1']],
'/api/app/v1/group-members/{groupId}' => ['GET', [AppGroupController::class, 'members']],

'/api/user/app/all' => ['GET', [AppController::class, 'all']],
'/api/user/app/create' => ['POST', [AppController::class, 'create']],
'/api/user/app/{id}/show' => ['GET', [AppController::class, 'show']],
'/api/user/app/{id}/rename' => ['PUT', [AppController::class, 'rename']],
'/api/user/app/{id}/delete' => ['DELETE', [AppController::class, 'delete']],
'/api/user/app/{id}/add-group/{gid}' => ['PUT', [AppController::class, 'addGroup']],
'/api/user/app/{id}/remove-group/{gid}' => ['PUT', [AppController::class, 'removeGroup']],
'/api/user/app/{id}/managers' => ['GET', [AppController::class, 'managers']],
'/api/user/app/{id}/add-manager/{pid}' => ['PUT', [AppController::class, 'addManager']],
'/api/user/app/{id}/remove-manager/{pid}' => ['PUT', [AppController::class, 'removeManager']],
'/api/user/app/{id}/add-role/{name}' => ['PUT', [AppController::class, 'addRole']],
'/api/user/app/{id}/remove-role/{name}' => ['PUT', [AppController::class, 'removeRole']],
'/api/user/app/{id}/change-secret' => ['PUT', [AppController::class, 'changeSecret']],
'/api/user/app/all' => ['GET', [AppController::class, 'all']],
'/api/user/app/create' => ['POST', [AppController::class, 'create']],
'/api/user/app/{id}/show' => ['GET', [AppController::class, 'show']],
'/api/user/app/{id}/rename' => ['PUT', [AppController::class, 'rename']],
'/api/user/app/{id}/delete' => ['DELETE', [AppController::class, 'delete']],
'/api/user/app/{id}/add-group/{gid}' => ['PUT', [AppController::class, 'addGroup']],
'/api/user/app/{id}/remove-group/{gid}' => ['PUT', [AppController::class, 'removeGroup']],
'/api/user/app/{id}/managers' => ['GET', [AppController::class, 'managers']],
'/api/user/app/{id}/add-manager/{pid}' => ['PUT', [AppController::class, 'addManager']],
'/api/user/app/{id}/remove-manager/{pid}' => ['PUT', [AppController::class, 'removeManager']],
'/api/user/app/{id}/add-role/{name}' => ['PUT', [AppController::class, 'addRole']],
'/api/user/app/{id}/remove-role/{name}' => ['PUT', [AppController::class, 'removeRole']],
'/api/user/app/{id}/add-eve-login/{eveLoginId}' => ['PUT', [AppController::class, 'addEveLogin']],
'/api/user/app/{id}/remove-eve-login/{eveLoginId}' => ['PUT', [AppController::class, 'removeEveLogin']],
'/api/user/app/{id}/change-secret' => ['PUT', [AppController::class, 'changeSecret']],

'/api/user/alliance/all' => ['GET', [AllianceController::class, 'all']],
'/api/user/alliance/with-groups' => ['GET', [AllianceController::class, 'withGroups']],
Expand Down
117 changes: 117 additions & 0 deletions backend/src/Controller/User/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Neucore\Controller\BaseController;
use Neucore\Entity\App;
use Neucore\Entity\EveLogin;
use Neucore\Entity\Group;
use Neucore\Entity\Player;
use Neucore\Entity\Role;
Expand Down Expand Up @@ -45,6 +46,11 @@ class AppController extends BaseController
*/
private $role;

/**
* @var EveLogin|null
*/
private $eveLogin;

/**
* @var array
*/
Expand Down Expand Up @@ -668,6 +674,106 @@ public function removeRole(string $id, string $name): ResponseInterface
return $this->flushAndReturn(204);
}

/**
* @OA\Put(
* path="/user/app/{id}/add-eve-login/{eveLoginId}",
* operationId="userAppAddEveLogin",
* summary="Add an EVE login to an app.",
* description="Needs role: app-admin",
* tags={"App"},
* security={{"Session"={}, "CSRF"={}}},
* @OA\Parameter(
* name="id",
* in="path",
* required=true,
* description="ID of the app.",
* @OA\Schema(type="integer")
* ),
* @OA\Parameter(
* name="eveLoginId",
* in="path",
* required=true,
* description="ID of the EVE login.",
* @OA\Schema(type="integer")
* ),
* @OA\Response(
* response="204",
* description="EVE login added."
* ),
* @OA\Response(
* response="403",
* description="Not authorized."
* ),
* @OA\Response(
* response="404",
* description="EVE login and/or app not found."
* )
* )
*/
public function addEveLogin(string $id, string $eveLoginId): ResponseInterface
{
if (!$this->findAppAndEveLogin($id, $eveLoginId)) {
return $this->response->withStatus(404);
}

foreach ($this->application->getEveLogins() as $existingEveLogin) {
if ($existingEveLogin->getId() === (int) $eveLoginId) {
return $this->response->withStatus(204);
}
}

$this->application->addEveLogin($this->eveLogin);

return $this->flushAndReturn(204);
}

/**
* @OA\Put(
* path="/user/app/{id}/remove-eve-login/{eveLoginId}",
* operationId="userAppRemoveEveLogin",
* summary="Remove an EVE login from an app.",
* description="Needs role: app-admin",
* tags={"App"},
* security={{"Session"={}, "CSRF"={}}},
* @OA\Parameter(
* name="id",
* in="path",
* required=true,
* description="ID of the app.",
* @OA\Schema(type="integer")
* ),
* @OA\Parameter(
* name="eveLoginId",
* in="path",
* required=true,
* description="ID of the EVE login.",
* @OA\Schema(type="integer")
* ),
* @OA\Response(
* response="204",
* description="EVE login removed."
* ),
* @OA\Response(
* response="403",
* description="Not authorized."
* ),
* @OA\Response(
* response="404",
* description="EVE login and/or app not found."
* )
* )
*/
public function removeEveLogin(string $id, string $eveLoginId): ResponseInterface
{
if (!$this->findAppAndEveLogin($id, $eveLoginId)) {
return $this->response->withStatus(404);
}

$this->application->removeEveLogin($this->eveLogin);

return $this->flushAndReturn(204);
}

/**
* @noinspection PhpUnused
* @OA\Put(
Expand Down Expand Up @@ -763,6 +869,17 @@ private function findAppAndRole(string $id, string $name): bool
return true;
}

private function findAppAndEveLogin(string $id, string $eveLoginId): bool
{
$eveLogin = $this->repositoryFactory->getEveLoginRepository()->find($eveLoginId);
if (!$this->findApp($id) || !$eveLogin) {
return false;
}
$this->eveLogin = $eveLogin;

return true;
}

private function findApp(string $id): bool
{
$applicationEntity = $this->repositoryFactory->getAppRepository()->find((int) $id);
Expand Down
Loading

0 comments on commit 5190aae

Please sign in to comment.