Skip to content

Commit

Permalink
Merge pull request #137 from nextcloud/feat/scopes/ex-app
Browse files Browse the repository at this point in the history
  • Loading branch information
provokateurin authored Jul 2, 2024
2 parents 5f5f339 + 48cb793 commit 8247301
Show file tree
Hide file tree
Showing 7 changed files with 635 additions and 3 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"phpstan/phpdoc-parser": "^1.28"
},
"require-dev": {
"nextcloud/coding-standard": "^1.2"
"nextcloud/coding-standard": "^1.2",
"nextcloud/ocp": "dev-master"
},
"scripts": {
"lint": "find . -name \\*.php -not -path './tests/*' -not -path './vendor/*' -not -path './build/*' -print0 | xargs -0 -n1 php -l && php -l generate-spec && php -l merge-specs",
Expand Down
252 changes: 250 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions generate-spec
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ foreach ($parsedRoutes as $key => $value) {
$isDeprecated = Helpers::classMethodHasAnnotationOrAttribute($methodFunction, "deprecated");
$isIgnored = Helpers::classMethodHasAnnotationOrAttribute($methodFunction, "IgnoreOpenAPI");
$isPasswordConfirmation = Helpers::classMethodHasAnnotationOrAttribute($methodFunction, "PasswordConfirmationRequired");
$isExApp = Helpers::classMethodHasAnnotationOrAttribute($methodFunction, "ExAppRequired");
$scopes = Helpers::getOpenAPIAttributeScopes($classMethod, $routeName);

if ($isIgnored) {
Expand All @@ -469,6 +470,8 @@ foreach ($parsedRoutes as $key => $value) {
if (empty($scopes)) {
if (!empty($controllerScopes)) {
$scopes = $controllerScopes;
} elseif ($isExApp) {
$scopes = ['ex_app'];
} elseif ($isAdmin) {
$scopes = ['administration'];
} else {
Expand Down
3 changes: 3 additions & 0 deletions tests/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
['name' => 'AdminSettings#movedToSettingsTag', 'url' => '/api/{apiVersion}/moved-with-tag', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'AdminSettings#movedToSettingsTagUnnamed', 'url' => '/api/{apiVersion}/moved-with-unnamed-tag', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],

['name' => 'ExAppSettings#exAppScopeAttribute', 'url' => '/api/{apiVersion}/ex-app-attribute', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'ExAppSettings#exAppScopeOverride', 'url' => '/api/{apiVersion}/ex-app-override', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],

['name' => 'Federation#federationByController', 'url' => '/api/{apiVersion}/controller-scope', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Federation#movedToDefaultScope', 'url' => '/api/{apiVersion}/default-scope', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],

Expand Down
39 changes: 39 additions & 0 deletions tests/lib/Controller/ExAppSettingsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace OCA\Notifications\Controller;

use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\ExAppRequired;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;

class ExAppSettingsController extends OCSController {
/**
* Route is in ex_app scope because of the attribute
*
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: Personal settings updated
*/
#[ExAppRequired]
public function exAppScopeAttribute(): DataResponse {
return new DataResponse();
}

/**
* Route is in ex_app scope because of the override
*
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: Personal settings updated
*/
#[NoAdminRequired]
#[OpenAPI(OpenAPI::SCOPE_EX_APP)]
public function exAppScopeOverride(): DataResponse {
return new DataResponse();
}
}
Loading

0 comments on commit 8247301

Please sign in to comment.