-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathMagazineReportsRejectApi.php
More file actions
101 lines (93 loc) · 4.02 KB
/
MagazineReportsRejectApi.php
File metadata and controls
101 lines (93 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
declare(strict_types=1);
namespace App\Controller\Api\Magazine\Moderate;
use App\Controller\Api\Magazine\MagazineBaseApi;
use App\Controller\Traits\PrivateContentTrait;
use App\DTO\ReportResponseDto;
use App\Entity\Magazine;
use App\Entity\Report;
use App\Service\ReportManager;
use Nelmio\ApiDocBundle\Attribute\Model;
use Nelmio\ApiDocBundle\Attribute\Security;
use OpenApi\Attributes as OA;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\RateLimiter\RateLimiterFactoryInterface;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class MagazineReportsRejectApi extends MagazineBaseApi
{
use PrivateContentTrait;
#[OA\Response(
response: 200,
description: 'Reject a report',
content: new Model(type: ReportResponseDto::class),
headers: [
new OA\Header(header: 'X-RateLimit-Remaining', schema: new OA\Schema(type: 'integer'), description: 'Number of requests left until you will be rate limited'),
new OA\Header(header: 'X-RateLimit-Retry-After', schema: new OA\Schema(type: 'integer'), description: 'Unix timestamp to retry the request after'),
new OA\Header(header: 'X-RateLimit-Limit', schema: new OA\Schema(type: 'integer'), description: 'Number of requests available'),
]
)]
#[OA\Response(
response: 401,
description: 'Permission denied due to missing or expired token',
content: new OA\JsonContent(ref: new Model(type: \App\Schema\Errors\UnauthorizedErrorSchema::class))
)]
#[OA\Response(
response: 403,
description: 'You are not allowed to accept this report',
content: new OA\JsonContent(ref: new Model(type: \App\Schema\Errors\ForbiddenErrorSchema::class))
)]
#[OA\Response(
response: 404,
description: 'Report not found',
content: new OA\JsonContent(ref: new Model(type: \App\Schema\Errors\NotFoundErrorSchema::class))
)]
#[OA\Response(
response: 429,
description: 'You are being rate limited',
content: new OA\JsonContent(ref: new Model(type: \App\Schema\Errors\TooManyRequestsErrorSchema::class)),
headers: [
new OA\Header(header: 'X-RateLimit-Remaining', schema: new OA\Schema(type: 'integer'), description: 'Number of requests left until you will be rate limited'),
new OA\Header(header: 'X-RateLimit-Retry-After', schema: new OA\Schema(type: 'integer'), description: 'Unix timestamp to retry the request after'),
new OA\Header(header: 'X-RateLimit-Limit', schema: new OA\Schema(type: 'integer'), description: 'Number of requests available'),
]
)]
#[OA\Parameter(
name: 'magazine_id',
in: 'path',
description: 'The magazine the report is in',
schema: new OA\Schema(type: 'integer'),
)]
#[OA\Parameter(
name: 'report_id',
in: 'path',
description: 'The report to reject',
schema: new OA\Schema(type: 'integer'),
)]
#[OA\Tag(name: 'moderation/magazine')]
#[Security(name: 'oauth2', scopes: ['moderate:magazine:reports:action'])]
#[IsGranted('ROLE_OAUTH2_MODERATE:MAGAZINE:REPORTS:ACTION')]
#[IsGranted('moderate', subject: 'magazine')]
/**
* Rejecting a report will preserve the reported item.
*/
public function __invoke(
#[MapEntity(id: 'magazine_id')]
Magazine $magazine,
#[MapEntity(id: 'report_id')]
Report $report,
ReportManager $manager,
RateLimiterFactoryInterface $apiModerateLimiter,
): JsonResponse {
$headers = $this->rateLimit($apiModerateLimiter);
if ($magazine->getId() !== $report->magazine?->getId()) {
throw new NotFoundHttpException('Report not found in magazine');
}
$manager->reject($report, $this->getUserOrThrow());
return new JsonResponse(
$this->serializeReport($report),
headers: $headers
);
}
}