Skip to content

Commit

Permalink
Revert "Make the API return the server public key and add a dedicated…
Browse files Browse the repository at this point in the history
… route for it" (#1024)
  • Loading branch information
jwr1 authored Aug 14, 2024
1 parent e4f1139 commit 8b52828
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 70 deletions.
6 changes: 0 additions & 6 deletions config/kbin_routes/notification_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 1 addition & 51 deletions src/Controller/Api/Notification/NotificationPushApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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',
Expand Down Expand Up @@ -120,7 +71,6 @@ public function createSubscription(
SettingsManager $settingsManager,
UserPushSubscriptionManager $pushSubscriptionManager,
TranslatorInterface $translator,
SiteRepository $siteRepository,
#[MapRequestPayload] NotificationPushSubscriptionRequestDto $payload
): JsonResponse {
$headers = $this->rateLimit($apiNotificationLimiter);
Expand All @@ -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),
Expand Down
13 changes: 0 additions & 13 deletions src/DTO/ServerPublicKeyDto.php

This file was deleted.

0 comments on commit 8b52828

Please sign in to comment.