Skip to content

Commit

Permalink
Merge pull request #21 from nextcloud/fix/non-root-nc-path
Browse files Browse the repository at this point in the history
  • Loading branch information
provokateurin authored Mar 12, 2024
2 parents 0e5932b + 41a4ed2 commit 9aadb38
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ composer:

.PHONY: npm
npm:
npm ci
npm run build

.PHONY: clean
Expand Down
39 changes: 26 additions & 13 deletions lib/Service/AppsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
use OC;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\IURLGenerator;

class AppsService {

public function __construct(private IAppManager $appManager) {
public function __construct(
private IAppManager $appManager,
private IURLGenerator $url,
) {
}

/**
Expand Down Expand Up @@ -45,7 +49,7 @@ public function findSupported(): array {
private function getSpecPath(string $app): ?string {
$scopeSuffix = '';
if ($app === 'core') {
$baseDir = OC::$SERVERROOT . DIRECTORY_SEPARATOR . "core";
$baseDir = OC::$SERVERROOT . DIRECTORY_SEPARATOR . 'core';
} else {
try {
if (str_contains($app, '-')) {
Expand All @@ -65,25 +69,34 @@ public function getSpec(string $app): string {
$data = json_decode(file_get_contents($this->getSpecPath($app)), true);

// Only give basic authentication as an option
$data["components"]["securitySchemes"] = [
"basic_auth" => [
"type" => "http",
"scheme" => "basic",
$data['components']['securitySchemes'] = [
'basic_auth' => [
'type' => 'http',
'scheme' => 'basic',
],
];
$data["security"] = [
$data['security'] = [
[
"basic_auth" => [],
'basic_auth' => [],
],
];
// Delete individual security requirements
foreach (array_keys($data["paths"]) as $path) {
foreach (array_keys($data["paths"][$path]) as $method) {
if (!in_array($method, ["delete", "get", "post", "put", "patch", "options"])) {
foreach (array_keys($data['paths']) as $path) {
foreach (array_keys($data['paths'][$path]) as $method) {
if (!in_array($method, ['delete', 'get', 'post', 'put', 'patch', 'options'])) {
continue;
}
$operation = &$data["paths"][$path][$method];
unset($operation["security"]);
$operation = &$data['paths'][$path][$method];
unset($operation['security']);
}
}
// fix paths when NC is accessed at a sub path
$webRoot = $this->url->getWebroot();
if ($webRoot !== '' && $webRoot !== '/') {
foreach (array_keys($data['paths']) as $path) {
$prefixedPath = $webRoot . $path;
$data['paths'][$prefixedPath] = $data['paths'][$path];
unset($data['paths'][$path]);
}
}

Expand Down

0 comments on commit 9aadb38

Please sign in to comment.