|
26 | 26 | use Composer\Pcre\Preg; |
27 | 27 | use Graze\DogStatsD\Client as StatsDClient; |
28 | 28 | use Psr\Log\LoggerInterface; |
| 29 | +use Symfony\Bridge\Doctrine\Attribute\MapEntity; |
29 | 30 | use Symfony\Component\HttpFoundation\BinaryFileResponse; |
30 | 31 | use Symfony\Component\HttpFoundation\JsonResponse; |
31 | 32 | use Symfony\Component\HttpFoundation\Request; |
|
34 | 35 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
35 | 36 | use Symfony\Component\Routing\Attribute\Route; |
36 | 37 | use Symfony\Component\Routing\RouterInterface; |
37 | | -use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
38 | 38 | use Symfony\Component\Validator\Validator\ValidatorInterface; |
39 | 39 | use Symfony\Contracts\HttpClient\HttpClientInterface; |
40 | 40 |
|
@@ -184,14 +184,14 @@ public function updatePackageAction(Request $request, string $githubWebhookSecre |
184 | 184 | } |
185 | 185 |
|
186 | 186 | #[Route(path: '/api/packages/{package}', name: 'api_edit_package', requirements: ['package' => '[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?'], defaults: ['_format' => 'json'], methods: ['PUT'])] |
187 | | - public function editPackageAction(Request $request, Package $package, ValidatorInterface $validator, StatsDClient $statsd): JsonResponse |
| 187 | + public function editPackageAction(Request $request, #[MapEntity(mapping: ['package' => 'name'])] Package $package, ValidatorInterface $validator, StatsDClient $statsd): JsonResponse |
188 | 188 | { |
189 | 189 | $user = $this->findUser($request); |
190 | 190 | if (!$user) { |
191 | 191 | return new JsonResponse(['status' => 'error', 'message' => 'Missing or invalid username/apiToken in request'], 406); |
192 | 192 | } |
193 | 193 | if (!$package->getMaintainers()->contains($user)) { |
194 | | - throw new AccessDeniedException(); |
| 194 | + return new JsonResponse(['status' => 'error', 'message' => 'You are not allowed to edit this package'], 403); |
195 | 195 | } |
196 | 196 |
|
197 | 197 | $statsd->increment('edit_package_api'); |
|
0 commit comments