Repository navigation
Dev #173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TatevikGr
wants to merge
11
commits into
main
Choose a base branch
from
dev
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Dev #173
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
98bee7d
dev-dev
tatevikg1 0818714
feat: link track controller and tests
tatevikg1 fb0b5f2
feat: add CampaignMessageDataController and request handling for camp…
tatevikg1 35f6bc5
feat: enhance link tracking with error handling and response updates
tatevikg1 df43ce5
chore: update to php8.2
tatevikg1 c28a247
feat: implement access control for campaign and subscriber list views
tatevikg1 0a1dc08
feat: add AdminNotificationController for fetching admin notifications
tatevikg1 06fa108
feat: remove 500 error response for link tracking in LinkTrackController
tatevikg1 f1f366a
feat: add AdminNotificationNormalizer
tatevikg1 ec9ad48
feat: update error handling in LinkTrackController to return 500 resp…
tatevikg1 57180bb
feat: implement access control for associating messages with subscrib…
tatevikg1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PhpList\RestBundle\Identity\Controller; | ||
|
|
||
| use OpenApi\Attributes as OA; | ||
| use PhpList\Core\Domain\Identity\Model\Dto\AdminNotification; | ||
| use PhpList\Core\Domain\Identity\Service\Authentication; | ||
| use PhpList\Core\Domain\Identity\Service\Notification\AdminNotificationCollector; | ||
| use PhpList\RestBundle\Common\Controller\BaseController; | ||
| use PhpList\RestBundle\Common\Validator\RequestValidator; | ||
| use PhpList\RestBundle\Identity\Serializer\AdminNotificationNormalizer; | ||
| use Symfony\Component\HttpFoundation\JsonResponse; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
| use Symfony\Component\Routing\Attribute\Route; | ||
|
|
||
| /** | ||
| * Returns the in-app notifications to administrators after login. | ||
| */ | ||
| #[Route('/notifications', name: 'admin_notification_')] | ||
| class AdminNotificationController extends BaseController | ||
| { | ||
| public function __construct( | ||
| Authentication $authentication, | ||
| RequestValidator $validator, | ||
| private readonly AdminNotificationCollector $collector, | ||
| private readonly AdminNotificationNormalizer $normalizer, | ||
| ) { | ||
| parent::__construct($authentication, $validator); | ||
| } | ||
|
|
||
| #[Route('', name: 'list', methods: ['GET'])] | ||
| #[OA\Get( | ||
| path: '/api/v2/notifications', | ||
| description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' . | ||
| 'Returns the in-app notifications for the authenticated administrator.', | ||
| summary: 'Gets admin notifications.', | ||
| tags: ['notifications'], | ||
| parameters: [ | ||
| new OA\Parameter( | ||
| name: 'php-auth-pw', | ||
| description: 'Session key obtained from login', | ||
| in: 'header', | ||
| required: true, | ||
| schema: new OA\Schema(type: 'string') | ||
| ), | ||
| ], | ||
| responses: [ | ||
| new OA\Response( | ||
| response: 200, | ||
| description: 'Success', | ||
| content: new OA\JsonContent( | ||
| properties: [ | ||
| new OA\Property( | ||
| property: 'items', | ||
| type: 'array', | ||
| items: new OA\Items(ref: '#/components/schemas/AdminNotification') | ||
| ), | ||
| ], | ||
| type: 'object' | ||
| ) | ||
| ), | ||
| new OA\Response( | ||
| response: 403, | ||
| description: 'Failure', | ||
| content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse') | ||
| ), | ||
| ] | ||
| )] | ||
| public function list(Request $request): JsonResponse | ||
| { | ||
| $administrator = $this->requireAuthentication($request); | ||
|
|
||
| $items = array_map( | ||
| fn (AdminNotification $notification): array => $this->normalizer->normalize($notification), | ||
| $this->collector->collect($administrator) | ||
| ); | ||
|
|
||
| return $this->json(['items' => $items], Response::HTTP_OK); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PhpList\RestBundle\Identity\Serializer; | ||
|
|
||
| use InvalidArgumentException; | ||
| use OpenApi\Attributes as OA; | ||
| use PhpList\Core\Domain\Identity\Model\Dto\AdminNotification; | ||
| use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
|
||
| #[OA\Schema( | ||
| schema: 'AdminNotification', | ||
| properties: [ | ||
| new OA\Property(property: 'code', type: 'string', example: 'campaigns_in_queue'), | ||
| new OA\Property(property: 'level', type: 'string', enum: ['info', 'warning', 'error']), | ||
| new OA\Property(property: 'message', type: 'string'), | ||
| new OA\Property(property: 'context', type: 'object'), | ||
| ], | ||
| type: 'object' | ||
| )] | ||
| class AdminNotificationNormalizer implements NormalizerInterface | ||
| { | ||
| /** | ||
| * @SuppressWarnings("PHPMD.UnusedFormalParameter") | ||
| * @throws InvalidArgumentException | ||
| */ | ||
| public function normalize($object, string $format = null, array $context = []): array | ||
| { | ||
| if (!$object instanceof AdminNotification) { | ||
| throw new InvalidArgumentException('Expected an AdminNotification object.'); | ||
| } | ||
|
|
||
| return [ | ||
| 'code' => $object->code, | ||
| 'level' => $object->level, | ||
| 'message' => $object->message, | ||
| // an object, so that an empty context is encoded as {} and not [] | ||
| 'context' => (object) $object->context, | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * @SuppressWarnings("PHPMD.UnusedFormalParameter") | ||
| */ | ||
| public function supportsNormalization($data, string $format = null): bool | ||
| { | ||
| return $data instanceof AdminNotification; | ||
| } | ||
|
|
||
| /** | ||
| * @SuppressWarnings("PHPMD.UnusedFormalParameter") | ||
| */ | ||
| public function getSupportedTypes(?string $format): array | ||
| { | ||
| return [ | ||
| AdminNotification::class => true, | ||
| ]; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
src/Messaging/Controller/CampaignMessageDataController.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PhpList\RestBundle\Messaging\Controller; | ||
|
|
||
| use Doctrine\ORM\EntityManagerInterface; | ||
| use OpenApi\Attributes as OA; | ||
| use PhpList\Core\Domain\Identity\Service\Authentication; | ||
| use PhpList\Core\Domain\Identity\Service\PermissionChecker; | ||
| use PhpList\Core\Domain\Messaging\Model\Message; | ||
| use PhpList\Core\Domain\Messaging\Service\Manager\MessageDataManager; | ||
| use PhpList\Core\Domain\Messaging\Service\MessageDataLoader; | ||
| use PhpList\RestBundle\Common\Controller\BaseController; | ||
| use PhpList\RestBundle\Common\Validator\RequestValidator; | ||
| use PhpList\RestBundle\Messaging\Dto\CampaignMessageData; | ||
| use PhpList\RestBundle\Messaging\Request\UpdateMessageDataRequest; | ||
| use PhpList\RestBundle\Messaging\Serializer\MessageDataNormalizer; | ||
| use Symfony\Bridge\Doctrine\Attribute\MapEntity; | ||
| use Symfony\Component\HttpFoundation\JsonResponse; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
| use Symfony\Component\Routing\Attribute\Route; | ||
|
|
||
| /** | ||
| * This controller provides REST API to set the campaign settings that are kept in the message data. | ||
| */ | ||
| #[Route('/campaigns', name: 'campaign_message_data_')] | ||
| class CampaignMessageDataController extends BaseController | ||
| { | ||
| public function __construct( | ||
| Authentication $authentication, | ||
| RequestValidator $validator, | ||
| private readonly MessageDataManager $messageDataManager, | ||
| private readonly MessageDataLoader $messageDataLoader, | ||
| private readonly PermissionChecker $permissionChecker, | ||
| private readonly EntityManagerInterface $entityManager, | ||
| private readonly MessageDataNormalizer $messageDataNormalizer, | ||
| ) { | ||
| parent::__construct($authentication, $validator); | ||
| } | ||
|
|
||
| #[Route( | ||
| '/{messageId}/message-data', | ||
| name: 'update', | ||
| requirements: ['messageId' => '\d+'], | ||
| methods: ['PATCH'] | ||
| )] | ||
| #[OA\Patch( | ||
| path: '/api/v2/campaigns/{messageId}/message-data', | ||
| description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' . | ||
| 'Sets campaign settings that are not part of the campaign itself: analytics tracking, notification ' . | ||
| 'addresses and excluded lists. Only the fields that are sent are changed.', | ||
| summary: 'Set campaign message data.', | ||
| requestBody: new OA\RequestBody( | ||
| description: 'The settings to change.', | ||
| required: true, | ||
| content: new OA\JsonContent(ref: '#/components/schemas/UpdateMessageDataRequest') | ||
| ), | ||
| tags: ['campaigns'], | ||
| parameters: [ | ||
| new OA\Parameter( | ||
| name: 'php-auth-pw', | ||
| description: 'Session key obtained from login', | ||
| in: 'header', | ||
| required: true, | ||
| schema: new OA\Schema(type: 'string') | ||
| ), | ||
| new OA\Parameter( | ||
| name: 'messageId', | ||
| description: 'message ID', | ||
| in: 'path', | ||
| required: true, | ||
| schema: new OA\Schema(type: 'string') | ||
| ) | ||
| ], | ||
| responses: [ | ||
| new OA\Response( | ||
| response: 200, | ||
| description: 'Success, returns all the settings of the campaign', | ||
| content: new OA\JsonContent(ref: '#/components/schemas/MessageData') | ||
| ), | ||
| new OA\Response( | ||
| response: 401, | ||
| description: 'Not authenticated', | ||
| content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse') | ||
| ), | ||
| new OA\Response( | ||
| response: 403, | ||
| description: 'Failure', | ||
| content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse') | ||
| ), | ||
| new OA\Response( | ||
| response: 404, | ||
| description: 'Failure', | ||
| content: new OA\JsonContent(ref: '#/components/schemas/NotFoundErrorResponse') | ||
| ), | ||
| new OA\Response( | ||
| response: 422, | ||
| description: 'Failure', | ||
| content: new OA\JsonContent(ref: '#/components/schemas/ValidationErrorResponse') | ||
| ), | ||
| ] | ||
| )] | ||
| public function updateMessageData( | ||
| Request $request, | ||
| #[MapEntity(mapping: ['messageId' => 'id'])] ?Message $message = null, | ||
| ): JsonResponse { | ||
| $authUser = $this->requireAuthentication($request); | ||
| if ($message === null) { | ||
| throw $this->createNotFoundException('Campaign not found.'); | ||
| } | ||
|
|
||
| if (!$this->permissionChecker->canEdit($authUser, $message)) { | ||
| throw $this->createAccessDeniedException('You are not allowed to update campaigns.'); | ||
| } | ||
|
|
||
| /** @var UpdateMessageDataRequest $messageDataRequest */ | ||
| $messageDataRequest = $this->validator->validate($request, UpdateMessageDataRequest::class); | ||
|
|
||
| $this->messageDataManager->storeMessageData($message, $messageDataRequest->getDto()); | ||
| $this->entityManager->flush(); | ||
|
|
||
| $messageData = new CampaignMessageData(($this->messageDataLoader)($message)); | ||
|
|
||
| return $this->json($this->messageDataNormalizer->normalize($messageData), Response::HTTP_OK); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PhpList\RestBundle\Messaging\Dto; | ||
|
|
||
| /** | ||
| * The message data of a campaign, as loaded by core's MessageDataLoader. | ||
| */ | ||
| class CampaignMessageData | ||
| { | ||
| /** @param array<string, mixed> $values */ | ||
| public function __construct(public readonly array $values) | ||
| { | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.