Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
persist-credentials: false
submodules: true
repository: nextcloud/server
ref: ${{ matrix.server-versions }}
ref: feat/noid/app-password-route-gate

- name: Checkout app
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand Down
3 changes: 3 additions & 0 deletions lib/Controller/EndpointController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

namespace OCA\Notifications\Controller;

use NCU\AppFramework\Http\Attribute\TokenScope;
use OCA\Notifications\Exceptions\NotificationNotFoundException;
use OCA\Notifications\Handler;
use OCA\Notifications\Push;
use OCA\Notifications\ResponseDefinitions;
use OCA\Notifications\Service\ClientService;
use OCA\Notifications\TokenScopes;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\ApiRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
Expand All @@ -38,6 +40,7 @@
* @psalm-import-type NotificationsNotification from ResponseDefinitions
* @psalm-import-type NotificationsNotificationAction from ResponseDefinitions
*/
#[TokenScope(scope: TokenScopes::NOTIFICATIONS_READ)]

Check failure on line 43 in lib/Controller/EndpointController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedAttributeClass

lib/Controller/EndpointController.php:43:3: UndefinedAttributeClass: Attribute class NCU\AppFramework\Http\Attribute\TokenScope does not exist (see https://psalm.dev/241)
class EndpointController extends OCSController {
public function __construct(
string $appName,
Expand Down
3 changes: 3 additions & 0 deletions lib/Controller/PushController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

namespace OCA\Notifications\Controller;

use NCU\AppFramework\Http\Attribute\TokenScope;
use OC\Authentication\Token\IProvider;
use OC\Security\IdentityProof\Manager;
use OCA\Notifications\ResponseDefinitions;
use OCA\Notifications\TokenScopes;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\ApiRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
Expand All @@ -32,6 +34,7 @@
* @psalm-import-type NotificationsPushDevice from ResponseDefinitions
*/
#[OpenAPI(scope: 'push')]
#[TokenScope(scope: TokenScopes::NOTIFICATIONS_READ)]

Check failure on line 37 in lib/Controller/PushController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedAttributeClass

lib/Controller/PushController.php:37:3: UndefinedAttributeClass: Attribute class NCU\AppFramework\Http\Attribute\TokenScope does not exist (see https://psalm.dev/241)
class PushController extends OCSController {
public function __construct(
string $appName,
Expand Down
3 changes: 3 additions & 0 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

namespace OCA\Notifications\Controller;

use NCU\AppFramework\Http\Attribute\TokenScope;
use OCA\Notifications\AppInfo\Application;
use OCA\Notifications\Model\Settings;
use OCA\Notifications\Model\SettingsMapper;
use OCA\Notifications\TokenScopes;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\ApiRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
Expand Down Expand Up @@ -48,6 +50,7 @@
#[NoAdminRequired]
#[OpenAPI]
#[ApiRoute(verb: 'POST', url: '/api/{apiVersion}/settings', requirements: ['apiVersion' => '(v2)'])]
#[TokenScope(scope: TokenScopes::NOTIFICATIONS_READ)]

Check failure on line 53 in lib/Controller/SettingsController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedAttributeClass

lib/Controller/SettingsController.php:53:4: UndefinedAttributeClass: Attribute class NCU\AppFramework\Http\Attribute\TokenScope does not exist (see https://psalm.dev/241)
public function personal(int $batchSetting, string $soundNotification, string $soundTalk): DataResponse {
$this->settingsMapper->setBatchSettingForUser($this->settingsMapper->getSettingsByUser($this->userId), $batchSetting);

Expand Down
3 changes: 3 additions & 0 deletions lib/Controller/WebPushController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

namespace OCA\Notifications\Controller;

use NCU\AppFramework\Http\Attribute\TokenScope;
use OC\Authentication\Token\IProvider;
use OC\Security\IdentityProof\Manager;
use OCA\Notifications\TokenScopes;
use OCA\Notifications\WebPush\ActivationSubStatus;
use OCA\Notifications\WebPush\NewSubStatus;
use OCA\Notifications\WebPushClient;
Expand All @@ -35,6 +37,7 @@
use Symfony\Component\Uid\Uuid;

#[OpenAPI(scope: 'webpush')]
#[TokenScope(scope: TokenScopes::NOTIFICATIONS_READ)]

Check failure on line 40 in lib/Controller/WebPushController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedAttributeClass

lib/Controller/WebPushController.php:40:3: UndefinedAttributeClass: Attribute class NCU\AppFramework\Http\Attribute\TokenScope does not exist (see https://psalm.dev/241)
class WebPushController extends OCSController {
public function __construct(
string $appName,
Expand Down
17 changes: 17 additions & 0 deletions lib/TokenScopes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Notifications;

/**
* App password scopes for notifications
*/
class TokenScopes {
public const NOTIFICATIONS_READ = 'notifications:notifications:read';
}
58 changes: 58 additions & 0 deletions tests/Unit/Controller/TokenScopeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Notifications\Tests\Unit\Controller;

use NCU\AppFramework\Http\Attribute\TokenScope;
use OCA\Notifications\Controller\APIController;
use OCA\Notifications\Controller\EndpointController;
use OCA\Notifications\Controller\PushController;
use OCA\Notifications\Controller\SettingsController;
use OCA\Notifications\Controller\WebPushController;
use OCA\Notifications\TokenScopes;
use PHPUnit\Framework\Attributes\DataProvider;
use Test\TestCase;

class TokenScopeTest extends TestCase {
public static function openControllers(): array {
return [
'notifications' => [EndpointController::class],
'push registration' => [PushController::class],
'web push registration' => [WebPushController::class],
];
}

#[DataProvider('openControllers')]
public function testOpenControllers(string $class): void {
$attribute = (new \ReflectionClass($class))->getAttributes(TokenScope::class)[0];
$this->assertSame(TokenScopes::NOTIFICATIONS_READ, $attribute->getArguments()['scope']);
}

public function testPersonalSettingsOnly(): void {
$personal = (new \ReflectionMethod(SettingsController::class, 'personal'))->getAttributes(TokenScope::class)[0];
$this->assertSame(TokenScopes::NOTIFICATIONS_READ, $personal->getArguments()['scope']);
$this->assertSame([], (new \ReflectionMethod(SettingsController::class, 'admin'))->getAttributes(TokenScope::class));
$this->assertSame([], (new \ReflectionClass(SettingsController::class))->getAttributes(TokenScope::class));
}

public static function closedControllers(): array {
return [
'admin' => [APIController::class],
];
}

#[DataProvider('closedControllers')]
public function testClosedControllers(string $class): void {
$class = new \ReflectionClass($class);
$this->assertSame([], $class->getAttributes(TokenScope::class));
foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
$this->assertSame([], $method->getAttributes(TokenScope::class), $method->getName());
}
}
}
Loading