Skip to content

Commit d5d9b2e

Browse files
committed
Add hydrator role
1 parent e44d50b commit d5d9b2e

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

src/Controller/DefiController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function getTokenList(Request $request): JsonResponse
9090
*/
9191
public function generateTokenSymbol(Request $request): JsonResponse
9292
{
93-
$this->authenticatorService->checkAdminRights($this->getApiToken($request));
93+
$this->authenticatorService->checkHydratorRights($this->getApiToken($request));
9494

9595
return $this->defiService->generateTokenSymbol();
9696
}
@@ -112,7 +112,7 @@ public function generateTokenSymbol(Request $request): JsonResponse
112112
*/
113113
public function generateLpPair(Request $request): JsonResponse
114114
{
115-
$this->authenticatorService->checkAdminRights($this->getApiToken($request));
115+
$this->authenticatorService->checkHydratorRights($this->getApiToken($request));
116116

117117
return $this->defiService->generateLpPairToken();
118118
}

src/Service/AuthenticatorService.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ public function checkAdminRights(?string $apiKey)
3535
}
3636
}
3737

38+
/**
39+
* Check hydrator rights.
40+
*
41+
* @param string|null $apiKey
42+
*/
43+
public function checkHydratorRights(?string $apiKey)
44+
{
45+
if (!empty($apiKey)) {
46+
$application = $this->getApplicationByToken($apiKey);
47+
}
48+
49+
if (empty($apiKey) || !$this->applicationHaveHydratorRights($application)) {
50+
throw new HttpException(Response::HTTP_FORBIDDEN, "Unauthorized");
51+
}
52+
}
53+
3854
/**
3955
* Get application by token.
4056
*
@@ -72,6 +88,18 @@ public function applicationHaveAdminRights(Application $application): bool
7288
return in_array("ROLE_ADMIN", $application->getUser()->getRoles());
7389
}
7490

91+
/**
92+
* Check if Application have hydrator rights.
93+
*
94+
* @param Application $application
95+
*
96+
* @return bool
97+
*/
98+
public function applicationHaveHydratorRights(Application $application): bool
99+
{
100+
return in_array("ROLE_HYDRATOR", $application->getUser()->getRoles());
101+
}
102+
75103
/**
76104
* Check user authentication.
77105
*

src/Service/UserService.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public function userRegistration(Request $request): array
4141
case 'isFreemium':
4242
array_push($roles, "ROLE_FREEMIUM");
4343
break;
44+
case 'isHydrator':
45+
array_push($roles, "ROLE_HYDRATOR");
46+
break;
4447
}
4548

4649
$user = $this->checkUserExistence($request->get('email'));

templates/admin/registerApiUser.html.twig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
Freemium
4242
</label>
4343
</div>
44+
<div class="form-check form-check-inline">
45+
<input class="form-check-input" type="radio" value="isHydrator" name="quotaRole" id="isHydrator">
46+
<label class="form-check-label" for="isHydrator">
47+
Hydrator
48+
</label>
49+
</div>
4450
</div>
4551
<div class="form-group">
4652
<input type="text" class="form-control" id="formGroupUsername" name="username" placeholder="Username" required>

0 commit comments

Comments
 (0)