Skip to content
Open

Dev #159

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,26 @@
"role": "Maintainer"
}
],
"repositories": [
{
"type": "vcs",
"url": "https://github.com/TatevikGr/rss-bundle.git"
}
],
"support": {
"issues": "https://github.com/phpList/rest-api/issues",
"forum": "https://discuss.phplist.org/",
"source": "https://github.com/phpList/rest-api"
},
"require": {
"php": "^8.1",
"phplist/core": "dev-main",
"phplist/core": "dev-dev",
"friendsofsymfony/rest-bundle": "*",
"symfony/test-pack": "^1.0",
"symfony/process": "^6.4",
"zircote/swagger-php": "^4.11",
"ext-dom": "*"
"ext-dom": "*",
"tatevikgr/rss-feed": "dev-main as 0.1.0"
},
"require-dev": {
"phpunit/phpunit": "^10.0",
Expand Down Expand Up @@ -123,5 +130,10 @@
}
}
}
},
"config": {
"allow-plugins": {
"php-http/discovery": true
}
}
}
10 changes: 7 additions & 3 deletions config/services/managers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ services:
autowire: true
autoconfigure: true

PhpList\Core\Domain\Messaging\Service\MessageManager:
PhpList\Core\Domain\Messaging\Service\Manager\MessageManager:
autowire: true
autoconfigure: true

PhpList\Core\Domain\Messaging\Service\TemplateManager:
PhpList\Core\Domain\Messaging\Service\Manager\TemplateManager:
autowire: true
autoconfigure: true

PhpList\Core\Domain\Messaging\Service\TemplateImageManager:
PhpList\Core\Domain\Messaging\Service\Manager\TemplateImageManager:
autowire: true
autoconfigure: true

PhpList\Core\Domain\Messaging\Service\Manager\BounceRegexManager:
autowire: true
autoconfigure: true

Expand Down
12 changes: 12 additions & 0 deletions config/services/normalizers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,15 @@ services:
PhpList\RestBundle\Statistics\Serializer\TopLocalPartsNormalizer:
tags: [ 'serializer.normalizer' ]
autowire: true

PhpList\RestBundle\Subscription\Serializer\UserBlacklistNormalizer:
tags: [ 'serializer.normalizer' ]
autowire: true

PhpList\RestBundle\Subscription\Serializer\SubscribePageNormalizer:
tags: [ 'serializer.normalizer' ]
autowire: true

PhpList\RestBundle\Messaging\Serializer\BounceRegexNormalizer:
tags: [ 'serializer.normalizer' ]
autowire: true
7 changes: 6 additions & 1 deletion src/Identity/Controller/AdminAttributeValueController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PhpList\RestBundle\Identity\Controller;

use Doctrine\ORM\EntityManagerInterface;
use OpenApi\Attributes as OA;
use PhpList\Core\Domain\Identity\Model\Filter\AdminAttributeValueFilter;
use PhpList\Core\Domain\Identity\Model\Administrator;
Expand All @@ -27,18 +28,21 @@ class AdminAttributeValueController extends BaseController
private AdminAttributeManager $attributeManager;
private AdminAttributeValueNormalizer $normalizer;
private PaginatedDataProvider $paginatedDataProvider;
private EntityManagerInterface $entityManager;

public function __construct(
Authentication $authentication,
RequestValidator $validator,
AdminAttributeManager $attributeManager,
AdminAttributeValueNormalizer $normalizer,
PaginatedDataProvider $paginatedDataProvider
PaginatedDataProvider $paginatedDataProvider,
EntityManagerInterface $entityManager,
) {
parent::__construct($authentication, $validator);
$this->attributeManager = $attributeManager;
$this->normalizer = $normalizer;
$this->paginatedDataProvider = $paginatedDataProvider;
$this->entityManager = $entityManager;
}

#[Route(
Expand Down Expand Up @@ -122,6 +126,7 @@ public function createOrUpdate(
definition: $definition,
value: $request->toArray()['value'] ?? null
);
$this->entityManager->flush();
$json = $this->normalizer->normalize($attributeDefinition, 'json');

return $this->json($json, Response::HTTP_CREATED);
Expand Down
246 changes: 246 additions & 0 deletions src/Messaging/Controller/BounceRegexController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
<?php

declare(strict_types=1);

namespace PhpList\RestBundle\Messaging\Controller;

use OpenApi\Attributes as OA;
use PhpList\Core\Domain\Messaging\Service\Manager\BounceRegexManager;
use PhpList\Core\Security\Authentication;
use PhpList\RestBundle\Common\Controller\BaseController;
use PhpList\RestBundle\Common\Validator\RequestValidator;
use PhpList\RestBundle\Messaging\Request\CreateBounceRegexRequest;
use PhpList\RestBundle\Messaging\Serializer\BounceRegexNormalizer;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

/**
* Manage bounce regular expressions.
*/
#[Route('/bounces/regex', name: 'bounce_regex_')]
class BounceRegexController extends BaseController
{
public function __construct(
Authentication $authentication,
RequestValidator $validator,
private readonly BounceRegexManager $manager,
private readonly BounceRegexNormalizer $normalizer,
) {
parent::__construct($authentication, $validator);
}

#[Route('', name: 'get_list', methods: ['GET'])]
#[OA\Get(
path: '/api/v2/bounces/regex',
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
'Returns a JSON list of all bounce regex rules.',
summary: 'Gets a list of all bounce regex rules.',
tags: ['bounces'],
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(
type: 'array',
items: new OA\Items(ref: '#/components/schemas/BounceRegex')
)
),
new OA\Response(
response: 403,
description: 'Failure',
content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse')
)
]
)]
public function list(Request $request): JsonResponse
{
$this->requireAuthentication($request);
$items = $this->manager->getAll();
$normalized = array_map(fn($bounceRegex) => $this->normalizer->normalize($bounceRegex), $items);

return $this->json($normalized, Response::HTTP_OK);
}

#[Route('/{regexHash}', name: 'get_one', methods: ['GET'])]
#[OA\Get(
path: '/api/v2/bounces/regex/{regexHash}',
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
'Returns a bounce regex by its hash.',
summary: 'Get a bounce regex by its hash',
tags: ['bounces'],
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: 'regexHash',
description: 'Regex hash',
in: 'path',
required: true,
schema: new OA\Schema(type: 'string')
),
],
responses: [
new OA\Response(
response: 200,
description: 'Success',
content: new OA\JsonContent(ref: '#/components/schemas/BounceRegex')
),
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')
)
]
)]
public function getOne(Request $request, string $regexHash): JsonResponse
{
$this->requireAuthentication($request);
$entity = $this->manager->getByHash($regexHash);
if (!$entity) {
throw $this->createNotFoundException('Bounce regex not found.');
}

return $this->json($this->normalizer->normalize($entity), Response::HTTP_OK);
}

#[Route('', name: 'create_or_update', methods: ['POST'])]
#[OA\Post(
path: '/api/v2/bounces/regex',
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
'Creates a new bounce regex or updates an existing one (matched by regex hash).',
summary: 'Create or update a bounce regex',
requestBody: new OA\RequestBody(
description: 'Create or update a bounce regex rule.',
required: true,
content: new OA\JsonContent(
required: ['regex'],
properties: [
new OA\Property(property: 'regex', type: 'string', example: '/mailbox is full/i'),
new OA\Property(property: 'action', type: 'string', example: 'delete', nullable: true),
new OA\Property(property: 'list_order', type: 'integer', example: 0, nullable: true),
new OA\Property(property: 'admin', type: 'integer', example: 1, nullable: true),
new OA\Property(property: 'comment', type: 'string', example: 'Auto-generated', nullable: true),
new OA\Property(property: 'status', type: 'string', example: 'active', nullable: true),
],
type: 'object'
)
),
tags: ['bounces'],
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: 201,
description: 'Success',
content: new OA\JsonContent(ref: '#/components/schemas/BounceRegex')
),
new OA\Response(
response: 403,
description: 'Failure',
content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse')
),
new OA\Response(
response: 422,
description: 'Failure',
content: new OA\JsonContent(ref: '#/components/schemas/ValidationErrorResponse')
),
]
)]
public function createOrUpdate(Request $request): JsonResponse
{
$this->requireAuthentication($request);
/** @var CreateBounceRegexRequest $dto */
$dto = $this->validator->validate($request, CreateBounceRegexRequest::class);

$entity = $this->manager->createOrUpdateFromPattern(
regex: $dto->regex,
action: $dto->action,
listOrder: $dto->listOrder,
adminId: $dto->admin,
comment: $dto->comment,
status: $dto->status
);

return $this->json($this->normalizer->normalize($entity), Response::HTTP_CREATED);
}

#[Route('/{regexHash}', name: 'delete', methods: ['DELETE'])]
#[OA\Delete(
path: '/api/v2/bounces/regex/{regexHash}',
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
'Delete a bounce regex by its hash.',
summary: 'Delete a bounce regex by its hash',
tags: ['bounces'],
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: 'regexHash',
description: 'Regex hash',
in: 'path',
required: true,
schema: new OA\Schema(type: 'string')
),
],
responses: [
new OA\Response(
response: Response::HTTP_NO_CONTENT,
description: 'Success'
),
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')
)
]
)]
public function delete(Request $request, string $regexHash): JsonResponse
{
$this->requireAuthentication($request);
$entity = $this->manager->getByHash($regexHash);
if (!$entity) {
throw $this->createNotFoundException('Bounce regex not found.');
}
$this->manager->delete($entity);

return $this->json(null, Response::HTTP_NO_CONTENT);
}
}
2 changes: 1 addition & 1 deletion src/Messaging/Controller/CampaignController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use OpenApi\Attributes as OA;
use PhpList\Core\Domain\Messaging\Model\Message;
use PhpList\Core\Domain\Messaging\Service\CampaignProcessor;
use PhpList\Core\Domain\Messaging\Service\Processor\CampaignProcessor;
use PhpList\Core\Security\Authentication;
use PhpList\RestBundle\Common\Controller\BaseController;
use PhpList\RestBundle\Common\Validator\RequestValidator;
Expand Down
2 changes: 1 addition & 1 deletion src/Messaging/Controller/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use OpenApi\Attributes as OA;
use PhpList\Core\Domain\Messaging\Model\Template;
use PhpList\Core\Domain\Messaging\Service\TemplateManager;
use PhpList\Core\Domain\Messaging\Service\Manager\TemplateManager;
use PhpList\Core\Security\Authentication;
use PhpList\RestBundle\Common\Controller\BaseController;
use PhpList\RestBundle\Common\Service\Provider\PaginatedDataProvider;
Expand Down
Loading
Loading