Skip to content

Commit

Permalink
WIP: minor corrections
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
  • Loading branch information
andrey18106 committed Jul 26, 2024
1 parent 713a1c3 commit 70bc3f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions lib/Controller/ExAppProxyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ private function buildMultipartFormData(array $bodyParams, array $files): array
return $multipart;
}

private function passesExAppProxyRoutesChecks(ExApp $exApp, string $other): bool {
private function passesExAppProxyRoutesChecks(ExApp $exApp, string $exAppRoute): bool {
foreach ($exApp->getRoutes() as $route) {
$matchesUrlPattern = preg_match('/' . $route['url'] . '/i', $other) === 1;
$matchesUrlPattern = preg_match('/' . $route['url'] . '/i', $exAppRoute) === 1;
$matchesVerb = str_contains(strtolower($route['verb']), strtolower($this->request->getMethod()));
if ($matchesUrlPattern && $matchesVerb) {
return $this->passesExAppProxyRouteAccessLevelCheck($route['access_level']);
Expand All @@ -236,17 +236,19 @@ private function passesExAppProxyRoutesChecks(ExApp $exApp, string $other): bool

private function passesExAppProxyRouteAccessLevelCheck(int $accessLevel): bool {
return match ($accessLevel) {
ExAppRouteAccessLevel::ADMIN->value => $this->userId !== null && $this->groupManager->isAdmin($this->userId),
ExAppRouteAccessLevel::USER->value => $this->userId !== null,
ExAppRouteAccessLevel::PUBLIC->value => true,
ExAppRouteAccessLevel::USER->value => $this->userId !== null,
ExAppRouteAccessLevel::ADMIN->value => $this->userId !== null && $this->groupManager->isAdmin($this->userId),
default => false,
};
}

private function buildHeadersWithExclude(ExApp $exApp, string $exAppRoute, array $headers): array {
$headersToExclude = [];
foreach ($exApp->getRoutes() as $route) {
if (preg_match($route['url'], $exAppRoute) === 1) {
$matchesUrlPattern = preg_match('/' . $route['url'] . '/i', $exAppRoute) === 1;
$matchesVerb = str_contains(strtolower($route['verb']), strtolower($this->request->getMethod()));
if ($matchesUrlPattern && $matchesVerb) {
$headersToExclude = json_decode($route['headers_to_exclude'], true);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Db/ExApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function jsonSerialize(): array {
}

enum ExAppRouteAccessLevel: int {
case USER = 0;
case ADMIN = 1;
case PUBLIC = 2;
case PUBLIC = 0;
case USER = 1;
case ADMIN = 2;
}

0 comments on commit 70bc3f3

Please sign in to comment.