From 8b528286f99e64e7a2514b96a36764aa20b43d91 Mon Sep 17 00:00:00 2001 From: John Wesley <47087725+jwr1@users.noreply.github.com> Date: Wed, 14 Aug 2024 14:02:51 -0400 Subject: [PATCH] Revert "Make the API return the server public key and add a dedicated route for it" (#1024) --- config/kbin_routes/notification_api.yaml | 6 --- .../Api/Notification/NotificationPushApi.php | 52 +------------------ src/DTO/ServerPublicKeyDto.php | 13 ----- 3 files changed, 1 insertion(+), 70 deletions(-) delete mode 100644 src/DTO/ServerPublicKeyDto.php diff --git a/config/kbin_routes/notification_api.yaml b/config/kbin_routes/notification_api.yaml index bf1537e4d..f18cadf28 100644 --- a/config/kbin_routes/notification_api.yaml +++ b/config/kbin_routes/notification_api.yaml @@ -47,12 +47,6 @@ api_notification_retrieve: methods: [ GET ] format: json -api_notification_push_get_public_key: - controller: App\Controller\Api\Notification\NotificationPushApi::GetServerPublicPushKey - path: /api/notification/push/publicKey - methods: [ GET ] - format: json - api_notification_push_register: controller: App\Controller\Api\Notification\NotificationPushApi::createSubscription path: /api/notification/push diff --git a/src/Controller/Api/Notification/NotificationPushApi.php b/src/Controller/Api/Notification/NotificationPushApi.php index 46dccb1c8..86a5c8d17 100644 --- a/src/Controller/Api/Notification/NotificationPushApi.php +++ b/src/Controller/Api/Notification/NotificationPushApi.php @@ -6,10 +6,8 @@ use App\Controller\Traits\PrivateContentTrait; use App\DTO\NotificationPushSubscriptionRequestDto; -use App\DTO\ServerPublicKeyDto; use App\Entity\UserPushSubscription; use App\Payloads\PushNotification; -use App\Repository\SiteRepository; use App\Repository\UserPushSubscriptionRepository; use App\Schema\Errors\ForbiddenErrorSchema; use App\Schema\Errors\NotFoundErrorSchema; @@ -31,53 +29,6 @@ class NotificationPushApi extends NotificationBaseApi { use PrivateContentTrait; - #[OA\Response( - response: 200, - description: '', - headers: [ - new OA\Header(header: 'X-RateLimit-Remaining', description: 'Number of requests left until you will be rate limited', schema: new OA\Schema(type: 'integer')), - new OA\Header(header: 'X-RateLimit-Retry-After', description: 'Unix timestamp to retry the request after', schema: new OA\Schema(type: 'integer')), - new OA\Header(header: 'X-RateLimit-Limit', description: 'Number of requests available', schema: new OA\Schema(type: 'integer')), - ], - content: new OA\JsonContent(ref: new Model(type: ServerPublicKeyDto::class)) - )] - #[OA\Response( - response: 401, - description: 'Permission denied due to missing or expired token', - content: new OA\JsonContent(ref: new Model(type: UnauthorizedErrorSchema::class)) - )] - #[OA\Response( - response: 403, - description: 'You are not allowed to get the public push key', - content: new OA\JsonContent(ref: new Model(type: ForbiddenErrorSchema::class)) - )] - #[OA\Response( - response: 429, - description: 'You are being rate limited', - headers: [ - new OA\Header(header: 'X-RateLimit-Remaining', description: 'Number of requests left until you will be rate limited', schema: new OA\Schema(type: 'integer')), - new OA\Header(header: 'X-RateLimit-Retry-After', description: 'Unix timestamp to retry the request after', schema: new OA\Schema(type: 'integer')), - new OA\Header(header: 'X-RateLimit-Limit', description: 'Number of requests available', schema: new OA\Schema(type: 'integer')), - ], - content: new OA\JsonContent(ref: new Model(type: TooManyRequestsErrorSchema::class)) - )] - #[OA\RequestBody(content: new Model(type: NotificationPushSubscriptionRequestDto::class))] - #[OA\Tag(name: 'notification')] - #[Security(name: 'oauth2', scopes: ['user:notification:read'])] - #[IsGranted('ROLE_OAUTH2_USER:NOTIFICATION:READ')] - /** - * Get the public push key of the server. - */ - public function GetServerPublicPushKey( - RateLimiterFactory $apiNotificationLimiter, - SiteRepository $siteRepository, - ): JsonResponse { - $headers = $this->rateLimit($apiNotificationLimiter); - $user = $this->getUserOrThrow(); - - return new JsonResponse(new ServerPublicKeyDto($siteRepository->findAll()[0]->pushPublicKey), headers: $headers); - } - #[OA\Response( response: 200, description: 'Created a new push subscription. If there already is a push subscription for this client it will be overwritten. a test notification will be sent right away', @@ -120,7 +71,6 @@ public function createSubscription( SettingsManager $settingsManager, UserPushSubscriptionManager $pushSubscriptionManager, TranslatorInterface $translator, - SiteRepository $siteRepository, #[MapRequestPayload] NotificationPushSubscriptionRequestDto $payload ): JsonResponse { $headers = $this->rateLimit($apiNotificationLimiter); @@ -145,7 +95,7 @@ public function createSubscription( $testNotification = new PushNotification('', $translator->trans('test_push_message', locale: $pushSubscription->locale)); $pushSubscriptionManager->sendTextToUser($user, $testNotification, specificToken: $apiToken); - return new JsonResponse(new ServerPublicKeyDto($siteRepository->findAll()[0]->pushPublicKey), headers: $headers); + return new JsonResponse(headers: $headers); } catch (\ErrorException $e) { $this->logger->error('There was an exception while deleting a UserPushSubscription: {e} - {m}. {o}', [ 'e' => \get_class($e), diff --git a/src/DTO/ServerPublicKeyDto.php b/src/DTO/ServerPublicKeyDto.php deleted file mode 100644 index 65ac9256b..000000000 --- a/src/DTO/ServerPublicKeyDto.php +++ /dev/null @@ -1,13 +0,0 @@ -