Skip to content

Commit 36c2db5

Browse files
authored
removed "ex_apps_api_scopes" table (#262)
We hold pre-defined API Scopes in memory only. Anyway we currently do not supporting defining API Scopes at runtime and not sure that we will in future, so better to make it simpler and faster for now. --------- Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
1 parent 1917ca8 commit 36c2db5

14 files changed

Lines changed: 77 additions & 309 deletions

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8-
## [2.4.0 - 2024-04-0x]
8+
## [2.4.0 - 2024-04-04]
99

1010
### Added
1111

1212
- API for listening to file system events. #259
1313

14+
### Changed
15+
16+
- Optimizations(1) related to speed up handling the incoming ExApps requests. #262
17+
- `occ app_api:scopes:list` command removed as not needed. #262
18+
1419
### Fixed
1520

1621
- Corrected error handling for `occ` commands: `register` and `update`. #258

appinfo/info.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ to join us in shaping a more versatile, stable, and secure app landscape.
9191
<command>OCA\AppAPI\Command\Daemon\RegisterDaemon</command>
9292
<command>OCA\AppAPI\Command\Daemon\UnregisterDaemon</command>
9393
<command>OCA\AppAPI\Command\Daemon\ListDaemons</command>
94-
<command>OCA\AppAPI\Command\ApiScopes\ListApiScopes</command>
9594
</commands>
9695
<settings>
9796
<admin>OCA\AppAPI\Settings\Admin</admin>

docs/ManagingExternalApplications.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@ System user
116116

117117
System user (``[system user]``) in the list means that this ExApp was setup as a system ExApp.
118118

119-
List ExApp Scopes
120-
-----------------
121-
122-
List accepted scopes (see :ref:`api_scopes`) for ExApp.
123-
124-
Command: ``app_api:app:scopes:list <appid>``
125-
126119
Using the ExApp Management UI
127120
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
128121

docs/tech_details/ApiScopes.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ tailored access to the functionalities they need, enhancing performance and user
4040
As Nextcloud evolves, this list of API groups will continue to grow, offering developers a wide array of tools
4141
to create innovative and efficient applications.
4242

43-
The command to list registered scopes, `occ app_api:scopes:list`, remains an invaluable tool for developers
44-
and administrators, offering a quick and easy way to verify the API scopes available and required by applications within the Nextcloud platform.
45-
4643
The streamlined approach to API scopes not only simplifies the application development process
4744
but also aligns with best practices in software design, emphasizing clarity, security, and efficiency.
4845
This refinement in the handling of API scopes reflects Nextcloud's commitment to providing a robust and developer-friendly platform.

docs/tech_details/Authentication.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,11 @@ After successful authentication AppAPI sets `app_api` session key to ``true``.
8989
$this->session->set('app_api', true);
9090
9191
.. note:: The Nextcloud server verifies this session key and allows **CORS protection** and **Two-Factor authentication** to be bypassed for requests coming from ExApps.
92+
93+
For ``System`` applications additional flag is set:
94+
95+
.. code-block:: php
96+
97+
$this->session->set('app_api_system', true);
98+
99+
.. note:: The Nextcloud Server skips rate limiting for requests coming from ``System`` ExApps.

lib/Command/ApiScopes/ListApiScopes.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

lib/Command/ExApp/Register.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
132132
$appInfo['port'] = $appInfo['port'] ?? $this->exAppService->getExAppFreePort();
133133
$appInfo['secret'] = $appInfo['secret'] ?? $this->random->generate(128);
134134
$appInfo['daemon_config_name'] = $appInfo['daemon_config_name'] ?? $daemonConfigName;
135-
$appInfo['api_scopes'] = array_values($this->exAppApiScopeService->mapScopeNamesToNumbers($appInfo['external-app']['scopes']));
135+
$appInfo['api_scopes'] = array_values($this->exAppApiScopeService->mapScopeGroupsToNumbers($appInfo['external-app']['scopes']));
136136
$exApp = $this->exAppService->registerExApp($appInfo);
137137
if (!$exApp) {
138138
$this->logger->error(sprintf('Error during registering ExApp %s.', $appId));
@@ -142,7 +142,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
142142
return 3;
143143
}
144144
if (count($appInfo['external-app']['scopes']) > 0) {
145-
if (!$this->exAppScopesService->registerExAppScopes($exApp, $this->exAppApiScopeService->mapScopeNamesToNumbers($appInfo['external-app']['scopes']))) {
145+
if (!$this->exAppScopesService->registerExAppScopes($exApp, $this->exAppApiScopeService->mapScopeGroupsToNumbers($appInfo['external-app']['scopes']))) {
146146
$this->logger->error(sprintf('Error while registering API scopes for %s.', $appId));
147147
if ($outputConsole) {
148148
$output->writeln(sprintf('Error while registering API scopes for %s.', $appId));

lib/Command/ExApp/Update.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private function updateExApp(InputInterface $input, OutputInterface $output, str
171171
}
172172
}
173173

174-
$appInfo['api_scopes'] = array_values($this->exAppApiScopeService->mapScopeNamesToNumbers($appInfo['external-app']['scopes']));
174+
$appInfo['api_scopes'] = array_values($this->exAppApiScopeService->mapScopeGroupsToNumbers($appInfo['external-app']['scopes']));
175175
if (!$this->exAppService->updateExAppInfo($exApp, $appInfo)) {
176176
$this->logger->error(sprintf('Failed to update ExApp %s info', $appId));
177177
if ($outputConsole) {
@@ -244,7 +244,7 @@ private function updateExApp(InputInterface $input, OutputInterface $output, str
244244
return $exAppScope->getScopeGroup();
245245
}, $this->exAppScopeService->getExAppScopes($exApp));
246246
// Prepare for prompt of newly requested ExApp scopes
247-
$requiredScopes = $this->compareExAppScopes($currentExAppScopes, $appInfo['external-app']['scopes']);
247+
$requiredScopes = array_values(array_diff($this->exAppApiScopeService->mapScopeGroupsToNumbers($appInfo['external-app']['scopes']), $currentExAppScopes));
248248

249249
$forceScopes = (bool) $input->getOption('force-scopes');
250250
$confirmScopes = $forceScopes;
@@ -269,7 +269,7 @@ private function updateExApp(InputInterface $input, OutputInterface $output, str
269269
}
270270

271271
if (!$this->exAppScopeService->registerExAppScopes(
272-
$exApp, $this->exAppApiScopeService->mapScopeNamesToNumbers($appInfo['external-app']['scopes']))
272+
$exApp, $this->exAppApiScopeService->mapScopeGroupsToNumbers($appInfo['external-app']['scopes']))
273273
) {
274274
$this->logger->error(sprintf('Failed to update ExApp %s scopes.', $appId));
275275
if ($outputConsole) {
@@ -293,15 +293,4 @@ private function updateExApp(InputInterface $input, OutputInterface $output, str
293293
}
294294
return 0;
295295
}
296-
297-
/**
298-
* Compare ExApp scopes and return difference (new requested)
299-
*
300-
* @param array $currentExAppScopes
301-
* @param array $newExAppScopes
302-
* @return array
303-
*/
304-
private function compareExAppScopes(array $currentExAppScopes, array $newExAppScopes): array {
305-
return array_values(array_diff($this->exAppApiScopeService->mapScopeNamesToNumbers($newExAppScopes), $currentExAppScopes));
306-
}
307296
}

lib/Db/ExAppApiScope.php

Lines changed: 0 additions & 65 deletions
This file was deleted.

lib/Db/ExAppApiScopeMapper.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)