diff --git a/.github/workflows/tests-special.yml b/.github/workflows/tests-special.yml index 51584697..109bdd75 100644 --- a/.github/workflows/tests-special.yml +++ b/.github/workflows/tests-special.yml @@ -117,7 +117,7 @@ jobs: sleep 5s php occ app_ecosystem_v2:daemon:register manual_install "Manual Install" manual-install 0 0 0 php occ app_ecosystem_v2:app:register nc_py_api manual_install --json-info \ - "{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"port\":$APP_PORT,\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33]},\"protocol\":\"http\",\"system_app\":1}" \ + "{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"port\":$APP_PORT,\"scopes\":{\"required\":[\"SYSTEM\", \"FILES\", \"FILES_SHARING\"],\"optional\":[\"USER_INFO\", \"USER_STATUS\", \"NOTIFICATIONS\", \"WEATHER_STATUS\", \"TALK\"]},\"protocol\":\"http\",\"system_app\":1}" \ -e --force-scopes kill -15 $(cat /tmp/_install.pid) timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 265e908d..d3b4aba4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -130,7 +130,7 @@ jobs: sleep 5s php occ app_ecosystem_v2:daemon:register manual_install "Manual Install" manual-install 0 0 0 php occ app_ecosystem_v2:app:register nc_py_api manual_install --json-info \ - "{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"port\":$APP_PORT,\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33]},\"protocol\":\"http\",\"system_app\":1}" \ + "{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"port\":$APP_PORT,\"scopes\":{\"required\":[\"SYSTEM\", \"FILES\", \"FILES_SHARING\"],\"optional\":[\"USER_INFO\", \"USER_STATUS\", \"NOTIFICATIONS\", \"WEATHER_STATUS\", \"TALK\"]},\"protocol\":\"http\",\"system_app\":1}" \ -e --force-scopes kill -15 $(cat /tmp/_install.pid) timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null diff --git a/docs/tech_details/ApiScopes.rst b/docs/tech_details/ApiScopes.rst index d7764109..e02a4f97 100644 --- a/docs/tech_details/ApiScopes.rst +++ b/docs/tech_details/ApiScopes.rst @@ -25,8 +25,9 @@ The following API groups are currently supported: * ``31`` USER_STATUS * ``32`` NOTIFICATIONS * ``33`` WEATHER_STATUS +* ``50`` TALK -These groups are identified numerically, as opposed to using names. As time progresses, +These groups are identified using names. As time progresses, the list will steadily expand, comprehensively encompassing all potential APIs provided by Nextcloud. There is a CLI command to list registered scopes: ``occ app_ecosystem_v2:scopes:list``. diff --git a/lib/Command/ExApp/Register.php b/lib/Command/ExApp/Register.php index 77c61a13..cd6f3a31 100644 --- a/lib/Command/ExApp/Register.php +++ b/lib/Command/ExApp/Register.php @@ -148,16 +148,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int // Prompt to approve required ExApp scopes if (count($requestedExAppScopeGroups['required']) > 0) { - $output->writeln(sprintf('ExApp %s requested required scopes: %s', $appId, implode(', ', - $this->exAppApiScopeService->mapScopeGroupsToNames($requestedExAppScopeGroups['required'])))); + $output->writeln(sprintf('ExApp %s requested required scopes: %s', $appId, implode(', ', $requestedExAppScopeGroups['required']))); $question = new ConfirmationQuestion('Do you want to approve it? [y/N] ', false); $confirmRequiredScopes = $helper->ask($input, $output, $question); + } else { + $confirmRequiredScopes = true; } // Prompt to approve optional ExApp scopes if ($confirmRequiredScopes && count($requestedExAppScopeGroups['optional']) > 0) { - $output->writeln(sprintf('ExApp %s requested optional scopes: %s', $appId, implode(', ', - $this->exAppApiScopeService->mapScopeGroupsToNames($requestedExAppScopeGroups['optional'])))); + $output->writeln(sprintf('ExApp %s requested optional scopes: %s', $appId, implode(', ', $requestedExAppScopeGroups['optional']))); $question = new ConfirmationQuestion('Do you want to approve it? [y/N] ', false); $confirmOptionalScopes = $helper->ask($input, $output, $question); } @@ -199,7 +199,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int private function registerExAppScopes($output, ExApp $exApp, array $requestedExAppScopeGroups, string $scopeType): void { $registeredScopeGroups = []; - foreach ($requestedExAppScopeGroups as $scopeGroup) { + foreach ($this->exAppApiScopeService->mapScopeNamesToNumbers($requestedExAppScopeGroups) as $scopeGroup) { if ($this->exAppScopesService->setExAppScopeGroup($exApp, $scopeGroup)) { $registeredScopeGroups[] = $scopeGroup; } else { diff --git a/lib/Command/ExApp/Update.php b/lib/Command/ExApp/Update.php index 8fc267eb..21c499d1 100644 --- a/lib/Command/ExApp/Update.php +++ b/lib/Command/ExApp/Update.php @@ -196,6 +196,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->exAppApiScopeService->mapScopeGroupsToNames($requiredScopes)))); $question = new ConfirmationQuestion('Do you want to approve it? [y/N] ', false); $confirmRequiredScopes = $helper->ask($input, $output, $question); + } else { + $confirmRequiredScopes = true; } if ($confirmRequiredScopes && count($optionalScopes) > 0) { @@ -216,7 +218,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $newExAppScopes['optional'] = []; } - $newExAppScopes = array_merge($newExAppScopes['required'], $newExAppScopes['optional']); + $newExAppScopes = array_merge( + $this->exAppApiScopeService->mapScopeNamesToNumbers($newExAppScopes['required']), + $this->exAppApiScopeService->mapScopeNamesToNumbers($newExAppScopes['optional']) + ); if (!$this->exAppScopeService->updateExAppScopes($exApp, $newExAppScopes)) { $output->writeln(sprintf('Failed to update ExApp %s scopes', $appId)); return 1; @@ -244,6 +249,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int * @return array */ private function compareExAppScopes(array $currentExAppScopes, array $newExAppScopes, string $type): array { - return array_values(array_diff($newExAppScopes[$type], $currentExAppScopes)); + return array_values(array_diff($this->exAppApiScopeService->mapScopeNamesToNumbers($newExAppScopes[$type]), $currentExAppScopes)); } } diff --git a/lib/Service/AppEcosystemV2Service.php b/lib/Service/AppEcosystemV2Service.php index 183fee15..2921c211 100644 --- a/lib/Service/AppEcosystemV2Service.php +++ b/lib/Service/AppEcosystemV2Service.php @@ -348,10 +348,10 @@ public function getExAppRequestedScopes(ExApp $exApp, ?\SimpleXMLElement $infoXm if ($scopes !== false) { $scopes = (array) $scopes[0]; $required = array_map(function (string $scopeGroup) { - return intval($scopeGroup); + return $scopeGroup; }, (array) $scopes['required']->value); $optional = array_map(function (string $scopeGroup) { - return intval($scopeGroup); + return $scopeGroup; }, (array) $scopes['optional']->value); return [ 'required' => array_values($required), diff --git a/lib/Service/ExAppApiScopeService.php b/lib/Service/ExAppApiScopeService.php index 5138240b..f8f0147c 100644 --- a/lib/Service/ExAppApiScopeService.php +++ b/lib/Service/ExAppApiScopeService.php @@ -88,8 +88,8 @@ public function registerInitScopes(): bool { ['api_route' => '/cloud/capabilities', 'scope_group' => 1, 'name' => 'BASIC'], ['api_route' => '/cloud/apps', 'scope_group' => 2, 'name' => 'SYSTEM'], ['api_route' => '/apps/provisioning_api/api/', 'scope_group' => 2, 'name' => 'SYSTEM'], - ['api_route' => '/dav/', 'scope_group' => 10, 'name' => 'DAV'], - ['api_route' => '/apps/files/ajax/', 'scope_group' => 10, 'name' => 'DAV'], + ['api_route' => '/dav/', 'scope_group' => 10, 'name' => 'FILES'], + ['api_route' => '/apps/files/ajax/', 'scope_group' => 10, 'name' => 'FILES'], ['api_route' => '/apps/files_sharing/api/', 'scope_group' => 11, 'name' => 'FILES_SHARING'], ['api_route' => '/cloud/users', 'scope_group' => 30, 'name' => 'USER_INFO'], ['api_route' => '/cloud/groups', 'scope_group' => 30, 'name' => 'USER_INFO'], @@ -159,4 +159,13 @@ public function mapScopeGroupsToNames(array $scopeGroups): array { return $apiScope->getName(); }, $apiScopes)); } + + public function mapScopeNamesToNumbers(array $scopeNames): array { + $apiScopes = array_values(array_filter($this->getExAppApiScopes(), function (ExAppApiScope $apiScope) use ($scopeNames) { + return in_array($apiScope->getName(), $scopeNames); + })); + return array_unique(array_map(function (ExAppApiScope $apiScope) { + return $apiScope->getScopeGroup(); + }, $apiScopes)); + } }