-
Notifications
You must be signed in to change notification settings - Fork 14
Add forward email endpoint #164
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,19 @@ | ||
| services: | ||
| PhpList\RestBundle\Subscription\Service\SubscriberService: | ||
| PhpList\RestBundle\Subscription\Service\SubscriberHistoryService: | ||
| autowire: true | ||
| autoconfigure: true | ||
|
|
||
| PhpList\RestBundle\Subscription\Service\SubscriberHistoryService: | ||
| PhpList\Core\Domain\Messaging\Service\ForwardingGuard: | ||
| autowire: true | ||
| autoconfigure: true | ||
| public: false | ||
|
|
||
| PhpList\Core\Domain\Messaging\Service\ForwardDeliveryService: | ||
| autowire: true | ||
| autoconfigure: true | ||
| public: false | ||
|
|
||
| PhpList\Core\Domain\Messaging\Service\ForwardContentService: | ||
| autowire: true | ||
| autoconfigure: true | ||
| public: false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PhpList\RestBundle\Messaging\Controller; | ||
|
|
||
| use Doctrine\ORM\EntityManagerInterface; | ||
| use OpenApi\Attributes as OA; | ||
| use PhpList\Core\Domain\Messaging\Model\Dto\MessageForwardDto; | ||
| use PhpList\Core\Domain\Messaging\Model\Message; | ||
| use PhpList\Core\Domain\Messaging\Service\MessageForwardService; | ||
| use PhpList\Core\Security\Authentication; | ||
| use PhpList\RestBundle\Common\Controller\BaseController; | ||
| use PhpList\RestBundle\Common\Validator\RequestValidator; | ||
| use PhpList\RestBundle\Messaging\Request\ForwardMessageRequest; | ||
| use PhpList\RestBundle\Messaging\Serializer\ForwardingResultNormalizer; | ||
| 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 for email forwarding | ||
| * | ||
| * @author Tatevik Grigoryan <tatevik@phplist.com> | ||
| */ | ||
| #[Route('/email-forward', name: 'email_forward_')] | ||
| class EmailForwardController extends BaseController | ||
| { | ||
| public function __construct( | ||
| Authentication $authentication, | ||
| RequestValidator $validator, | ||
| private readonly EntityManagerInterface $entityManager, | ||
| private readonly MessageForwardService $messageForwardService, | ||
| private readonly ForwardingResultNormalizer $forwardingResultNormalizer, | ||
| ) { | ||
| parent::__construct($authentication, $validator); | ||
| } | ||
|
|
||
| #[Route('/{messageId}', name: 'forward', requirements: ['messageId' => '\\d+'], methods: ['POST'])] | ||
| #[OA\Post( | ||
| path: '/api/v2/campaigns/{messageId}/forward', | ||
| description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' . | ||
| 'Queues forwarding of a campaign/message to provided recipient emails.', | ||
| summary: 'Forward a message to recipients.', | ||
| requestBody: new OA\RequestBody( | ||
| description: 'Forwarding payload', | ||
| required: true, | ||
| content: new OA\JsonContent(ref: '#/components/schemas/ForwardMessageRequest') | ||
| ), | ||
| 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: 202, | ||
| description: 'Accepted', | ||
| content: new OA\JsonContent(ref: '#/components/schemas/ForwardResult') | ||
| ), | ||
| 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 forwardMessage( | ||
| Request $request, | ||
| #[MapEntity(mapping: ['messageId' => 'id'])] ?Message $message = null | ||
| ): JsonResponse { | ||
| if ($message === null) { | ||
| throw $this->createNotFoundException('Campaign not found.'); | ||
| } | ||
|
|
||
| /** @var ForwardMessageRequest $forwardRequest */ | ||
| $forwardRequest = $this->validator->validate($request, ForwardMessageRequest::class); | ||
|
|
||
| $result = $this->messageForwardService->forward( | ||
| messageForwardDto: new MessageForwardDto( | ||
| emails: $forwardRequest->recipients, | ||
| uid: $forwardRequest->uid, | ||
| fromName: $forwardRequest->fromName, | ||
| fromEmail: $forwardRequest->fromEmail, | ||
| note: $forwardRequest->note, | ||
| ), | ||
| campaign: $message, | ||
| ); | ||
|
|
||
| $this->entityManager->flush(); | ||
|
|
||
| return $this->json( | ||
| $this->forwardingResultNormalizer->normalize($result), | ||
| Response::HTTP_ACCEPTED | ||
|
Comment on lines
+70
to
+118
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's see the full controller file context
cat -n src/Messaging/Controller/EmailForwardController.php | head -130Repository: phpList/rest-api Length of output: 5504 🏁 Script executed: # Find the ForwardingResultNormalizer file
find . -name "*ForwardingResultNormalizer*" -type fRepository: phpList/rest-api Length of output: 117 🏁 Script executed: # Search for schema definitions or OpenAPI schemas related to ForwardResult
find . -name "*.php" -type f | head -50 | xargs grep -l "ForwardResult\|ForwardingResult" 2>/dev/null | head -20Repository: phpList/rest-api Length of output: 113 🏁 Script executed: cat -n src/Messaging/Serializer/ForwardingResultNormalizer.phpRepository: phpList/rest-api Length of output: 2993 🏁 Script executed: # Search for OpenAPI schema definitions (might be in attributes or configuration)
find . -type f -name "*.php" | xargs grep -l "#/components/schemas/ForwardResult" 2>/dev/nullRepository: phpList/rest-api Length of output: 113 🏁 Script executed: # Look for schema attribute definitions or any other ForwardResult/ForwardingResult references
rg "ForwardResult|ForwardingResult" --type php -C 3Repository: phpList/rest-api Length of output: 6174 🏁 Script executed: cat -n src/Messaging/Serializer/ForwardResultNormalizer.phpRepository: phpList/rest-api Length of output: 2500 Resolve the schema naming collision: ForwardingResultNormalizer should define 'ForwardingResult', not 'ForwardResult'. Both Rename the schema in Fix- new OA\Response(
- response: 202,
- description: 'Accepted',
- content: new OA\JsonContent(ref: '#/components/schemas/ForwardResult')
- ),
+ new OA\Response(
+ response: 202,
+ description: 'Accepted',
+ content: new OA\JsonContent(ref: '#/components/schemas/ForwardingResult')
+ ),🤖 Prompt for AI Agents |
||
| ); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.