Skip to content

Commit

Permalink
Merge pull request #1798 from nextcloud/techdebt/noid/try-route-attri…
Browse files Browse the repository at this point in the history
…bute

feat(push): Try the new Route attribute
  • Loading branch information
nickvergessen authored Mar 12, 2024
2 parents 65ccc26 + 94cf797 commit 1681746
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 214 deletions.
2 changes: 0 additions & 2 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
['name' => 'Endpoint#confirmIdsForUser', 'url' => '/api/{apiVersion}/notifications/exists', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v1|v2)']],
['name' => 'Endpoint#deleteNotification', 'url' => '/api/{apiVersion}/notifications/{id}', 'verb' => 'DELETE', 'requirements' => ['apiVersion' => '(v1|v2)', 'id' => '\d+']],
['name' => 'Endpoint#deleteAllNotifications', 'url' => '/api/{apiVersion}/notifications', 'verb' => 'DELETE', 'requirements' => ['apiVersion' => '(v1|v2)']],
['name' => 'Push#registerDevice', 'url' => '/api/{apiVersion}/push', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Push#removeDevice', 'url' => '/api/{apiVersion}/push', 'verb' => 'DELETE', 'requirements' => ['apiVersion' => '(v2)']],

['name' => 'API#generateNotification', 'url' => '/api/{apiVersion}/admin_notifications/{userId}', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v1|v2)']],

Expand Down
10 changes: 6 additions & 4 deletions lib/Controller/PushController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
use OC\Security\IdentityProof\Manager;
use OCA\Notifications\ResponseDefinitions;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\ApiRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
Expand Down Expand Up @@ -79,8 +81,6 @@ public function __construct(string $appName,
}

/**
* @NoAdminRequired
*
* Register device for push notifications
*
* @param string $pushTokenHash Hash of the push token
Expand All @@ -93,6 +93,8 @@ public function __construct(string $appName,
* 400: Registering device is not possible
* 401: Missing permissions to register device
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'POST', url: '/api/{apiVersion}/push', requirements: ['apiVersion' => '(v2)'])]
public function registerDevice(string $pushTokenHash, string $devicePublicKey, string $proxyServer): DataResponse {
$user = $this->userSession->getUser();
if (!$user instanceof IUser) {
Expand Down Expand Up @@ -163,8 +165,6 @@ public function registerDevice(string $pushTokenHash, string $devicePublicKey, s
}

/**
* @NoAdminRequired
*
* Remove a device from push notifications
*
* @return DataResponse<Http::STATUS_OK|Http::STATUS_ACCEPTED|Http::STATUS_UNAUTHORIZED, array<empty>, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{message: string}, array{}>
Expand All @@ -174,6 +174,8 @@ public function registerDevice(string $pushTokenHash, string $devicePublicKey, s
* 400: Removing device is not possible
* 401: Missing permissions to remove device
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'DELETE', url: '/api/{apiVersion}/push', requirements: ['apiVersion' => '(v2)'])]
public function removeDevice(): DataResponse {
$user = $this->userSession->getUser();
if (!$user instanceof IUser) {
Expand Down
Loading

0 comments on commit 1681746

Please sign in to comment.