|
16 | 16 | use PhpList\RestBundle\Common\Validator\RequestValidator; |
17 | 17 | use PhpList\RestBundle\Subscription\Request\SubscribePageRequest; |
18 | 18 | use PhpList\RestBundle\Subscription\Serializer\SubscribePageNormalizer; |
| 19 | +use PhpList\RestBundle\Subscription\Serializer\SubscribePagePublicNormalizer; |
19 | 20 | use Symfony\Bridge\Doctrine\Attribute\MapEntity; |
20 | 21 | use Symfony\Component\HttpFoundation\JsonResponse; |
21 | 22 | use Symfony\Component\HttpFoundation\Request; |
@@ -153,16 +154,58 @@ className: SubscribePage::class, |
153 | 154 | )] |
154 | 155 | public function getPage(Request $request): JsonResponse |
155 | 156 | { |
156 | | - $admin = $this->authentication->authenticateByApiKey($request); |
157 | | - $page = $this->subscribePageManager->findPage(id: (int) $request->get('id')); |
| 157 | + $admin = $this->requireAuthentication($request); |
| 158 | + if (!$admin->getPrivileges()->has(PrivilegeFlag::Subscribers)) { |
| 159 | + throw $this->createAccessDeniedException('You are not allowed to view subscribe pages.'); |
| 160 | + } |
158 | 161 |
|
159 | | - if (!$page || ($page->isActive() === false && $admin === null)) { |
| 162 | + $page = $this->subscribePageManager->findPage(id: (int) $request->get('id')); |
| 163 | + if (!$page) { |
160 | 164 | throw $this->createNotFoundException('Subscribe page not found'); |
161 | 165 | } |
162 | 166 |
|
163 | 167 | return $this->json($this->normalizer->normalize($page), Response::HTTP_OK); |
164 | 168 | } |
165 | 169 |
|
| 170 | + #[Route('/{id}/public', name: 'get_public', requirements: ['id' => '\\d+'], methods: ['GET'])] |
| 171 | + #[OA\Get( |
| 172 | + path: '/api/v2/subscribe-pages/{id}/public', |
| 173 | + description: '🚧 **Status: Beta** – This method is under development. Avoid using in production.', |
| 174 | + summary: 'Get public subscribe page (placeholders replaced with actual values)', |
| 175 | + tags: ['subscriptions'], |
| 176 | + parameters: [ |
| 177 | + new OA\Parameter( |
| 178 | + name: 'id', |
| 179 | + description: 'Subscribe page ID', |
| 180 | + in: 'path', |
| 181 | + required: true, |
| 182 | + schema: new OA\Schema(type: 'integer') |
| 183 | + ) |
| 184 | + ], |
| 185 | + responses: [ |
| 186 | + new OA\Response( |
| 187 | + response: 200, |
| 188 | + description: 'Success', |
| 189 | + content: new OA\JsonContent(ref: '#/components/schemas/SubscribePagePublic'), |
| 190 | + ), |
| 191 | + new OA\Response( |
| 192 | + response: 404, |
| 193 | + description: 'Not Found', |
| 194 | + content: new OA\JsonContent(ref: '#/components/schemas/NotFoundErrorResponse') |
| 195 | + ), |
| 196 | + ] |
| 197 | + )] |
| 198 | + public function getPublicPage(Request $request, SubscribePagePublicNormalizer $normalizer): JsonResponse |
| 199 | + { |
| 200 | + $page = $this->subscribePageManager->findPublicPage(id: (int) $request->get('id')); |
| 201 | + |
| 202 | + if (!$page || $page->isActive() === false) { |
| 203 | + throw $this->createNotFoundException('Subscribe page not found'); |
| 204 | + } |
| 205 | + |
| 206 | + return $this->json($normalizer->normalize($page), Response::HTTP_OK); |
| 207 | + } |
| 208 | + |
166 | 209 | #[Route('', name: 'create', methods: ['POST'])] |
167 | 210 | #[OA\Post( |
168 | 211 | path: '/api/v2/subscribe-pages', |
|
0 commit comments