Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ottaviano committed Jan 31, 2025
1 parent 96fb6d8 commit eb3b29c
Show file tree
Hide file tree
Showing 34 changed files with 130 additions and 78 deletions.
4 changes: 2 additions & 2 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ services:
tags: [{ name: 'serializer.normalizer', priority: 1 }]

App\Normalizer\ConstraintViolationListNormalizer:
decorates: 'serializer.normalizer.constraint_violation_list'
tags: [{ name: 'serializer.normalizer', priority: -1024 }]
decorates: 'api_platform.problem.normalizer.validation_exception'
tags: [{ name: 'serializer.normalizer', priority: -800 }]
arguments:
- '@serializer.name_converter.metadata_aware'

Expand Down
1 change: 0 additions & 1 deletion src/Adhesion/Request/MembershipRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class MembershipRequest implements DonationRequestInterface
#[Assert\NotBlank]
public ?string $nationality = null;

#[Assert\Type('bool')]
public ?bool $exclusiveMembership = null;

#[Assert\AtLeastOneOf([
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Filter/AbstractScopeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function setSecurity(Security $security): void

protected function getAllowedOperationNames(string $resourceClass): array
{
return ['{uuid}_get', '{uuid}.{_format}_get', '_get_collection'];
return ['{uuid}_get', '{uuid}{._format}_get', '_get_collection'];
}

private function isValidOperation(?Operation $operation): bool
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Filter/ScopeVisibilityFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ protected function getAllowedOperationNames(string $resourceClass): array
return ['_api_/v3/jecoute/news/{uuid}_get', '_api_/v3/jecoute/news_get_collection'];
}

return ['{uuid}_get', '{uuid}.{_format}_get', '_get_collection'];
return ['{uuid}_get', '{uuid}{._format}_get', '_get_collection'];
}
}
36 changes: 36 additions & 0 deletions src/Api/IriConverterDecorator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Api;

use ApiPlatform\Metadata\IriConverterInterface;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\Metadata\UrlGeneratorInterface;
use App\Entity\Event\BaseEventCategory;
use Ramsey\Uuid\Uuid;

class IriConverterDecorator implements IriConverterInterface
{
public function __construct(private readonly IriConverterInterface $decorated)
{
}

public function getResourceFromIri(string $iri, array $context = [], ?Operation $operation = null): object
{
if (Uuid::isValid($iri)) {
$iri = $this->decorated->getIriFromResource(resource: $context['resource_class'], context: ['uri_variables' => ['uuid' => $iri]]);
} elseif (is_a($context['resource_class'], BaseEventCategory::class, true)) {
$iri = $this->decorated->getIriFromResource(resource: $context['resource_class'], context: ['uri_variables' => ['slug' => $iri]]);
}

return $this->decorated->getResourceFromIri($iri, $context, $operation);
}

public function getIriFromResource(
object|string $resource,
int $referenceType = UrlGeneratorInterface::ABS_PATH,
?Operation $operation = null,
array $context = [],
): ?string {
return $this->decorated->getIriFromResource($resource, $referenceType, $operation, $context);
}
}
2 changes: 1 addition & 1 deletion src/Api/Listener/AdherentListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function onPostWrite(ViewEvent $viewEvent): void

if (
!\in_array($request->getMethod(), [Request::METHOD_POST, Request::METHOD_PUT])
|| '_api_/adherents/{uuid}/elect_put' !== $request->attributes->get('_api_operation_name')
|| '_api_/v3/adherents/{uuid}/elect_put' !== $request->attributes->get('_api_operation_name')
) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Listener/PostEventInscriptionEditListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function onEventInscriptionChange(RequestEvent $requestEvent): void
{
$request = $requestEvent->getRequest();

if ('_api_/event_inscriptions/{uuid}.{_format}_put' !== $request->attributes->get('_api_operation_name')) {
if ('_api_/event_inscriptions/{uuid}{._format}_put' !== $request->attributes->get('_api_operation_name')) {
return;
}

Expand Down
6 changes: 1 addition & 5 deletions src/Controller/Api/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Controller\Api;

use ApiPlatform\Problem\Serializer\ConstraintViolationListNormalizer;
use App\AdherentProfile\Password;
use App\Entity\Adherent;
use App\Entity\AdherentResetPasswordToken;
Expand Down Expand Up @@ -86,10 +85,7 @@ public function createPassword(
$errors = $validator->validate($password);

if (0 !== $errors->count()) {
return JsonResponse::fromJsonString(
$serializer->serialize($errors, ConstraintViolationListNormalizer::FORMAT),
Response::HTTP_BAD_REQUEST
);
return $this->json($errors, Response::HTTP_BAD_REQUEST);
}

try {
Expand Down
7 changes: 4 additions & 3 deletions src/Entity/Action/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,17 @@
uriTemplate: '/v3/actions/{uuid}',
security: "object.getAuthor() == user or user.hasDelegatedFromUser(object.getAuthor(), 'actions')"
),
new Put(
new HttpOperation(
method: 'PUT',
uriTemplate: '/v3/actions/{uuid}/cancel',
defaults: ['_api_receive' => false],
deserialize: false,
requirements: ['uuid' => '%pattern_uuid%'],
controller: CancelActionController::class
),
new HttpOperation(
method: 'POST|DELETE',
uriTemplate: '/v3/actions/{uuid}/register',
defaults: ['_api_receive' => false],
deserialize: false,
requirements: ['uuid' => '%pattern_uuid%'],
controller: RegisterController::class
),
Expand Down
21 changes: 13 additions & 8 deletions src/Entity/AdherentMessage/AbstractAdherentMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\HttpOperation;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\AdherentMessage\AdherentMessageDataObject;
Expand Down Expand Up @@ -64,27 +65,31 @@
normalizationContext: ['groups' => ['message_read']],
security: "is_granted('REQUEST_SCOPE_GRANTED', 'messages') and (object.getAuthor() == user or user.hasDelegatedFromUser(object.getAuthor(), 'messages'))"
),
new Post(
new HttpOperation(
method: 'POST',
uriTemplate: '/v3/adherent_messages/{uuid}/send',
defaults: ['_api_receive' => false],
deserialize: false,
requirements: ['uuid' => '%pattern_uuid%'],
controller: SendAdherentMessageController::class
),
new Post(
new HttpOperation(
method: 'POST',
uriTemplate: '/v3/adherent_messages/{uuid}/send-test',
defaults: ['_api_receive' => false],
deserialize: false,
requirements: ['uuid' => '%pattern_uuid%'],
controller: SendTestAdherentMessageController::class
),
new Put(
new HttpOperation(
method: 'PUT',
uriTemplate: '/v3/adherent_messages/{uuid}/filter',
defaults: ['_api_receive' => false],
deserialize: false,
requirements: ['uuid' => '%pattern_uuid%'],
controller: UpdateAdherentMessageFilterController::class
),
new Post(
new HttpOperation(
method: 'POST',
uriTemplate: '/v3/adherent_messages/{uuid}/duplicate',
defaults: ['_api_receive' => false],
deserialize: false,
requirements: ['uuid' => '%pattern_uuid%'],
controller: DuplicateMessageController::class
),
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/ElectedRepresentative/ElectedRepresentative.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class ElectedRepresentative implements EntityAdherentBlameableInterface, EntityA
*/
#[Groups(['elected_representative_write', 'elected_representative_read'])]
#[ORM\Column(type: 'boolean', options: ['default' => false])]
private $hasFollowedTraining = false;
public bool $hasFollowedTraining = false;

/**
* Mailchimp unsubscribed date
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/ElectedRepresentative/Mandate.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Mandate
*/
#[Groups(['elected_mandate_write', 'elected_mandate_read', 'elected_representative_read'])]
#[ORM\Column(type: 'boolean', options: ['default' => false])]
private $isElected;
public $isElected;

/**
* @var Zone|null
Expand Down
18 changes: 10 additions & 8 deletions src/Entity/Event/BaseEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,17 @@
new HttpOperation(
method: 'POST|DELETE',
uriTemplate: '/v3/events/{uuid}/subscribe',
defaults: ['_api_receive' => false],
requirements: ['uuid' => '%pattern_uuid%'],
controller: SubscribeAsAdherentController::class,
security: 'is_granted(\'ROLE_USER\')'
security: 'is_granted(\'ROLE_USER\')',
deserialize: false
),
new Post(
new HttpOperation(
method: 'POST',
uriTemplate: '/events/{uuid}/subscribe',
defaults: ['_api_receive' => false],
requirements: ['uuid' => '%pattern_uuid%'],
controller: SubscribeAsAnonymousController::class
controller: SubscribeAsAnonymousController::class,
deserialize: false
),
new HttpOperation(
method: 'POST|DELETE',
Expand All @@ -117,11 +118,12 @@
security: "is_granted('REQUEST_SCOPE_GRANTED', 'events') and is_granted('CAN_MANAGE_EVENT', request.attributes.get('data'))",
deserialize: false
),
new Put(
new HttpOperation(
method: 'PUT',
uriTemplate: '/v3/events/{uuid}/cancel',
defaults: ['_api_receive' => false],
requirements: ['uuid' => '%pattern_uuid%'],
controller: CancelEventController::class
controller: CancelEventController::class,
deserialize: false
),
new GetCollection(
uriTemplate: '/v3/events',
Expand Down
6 changes: 4 additions & 2 deletions src/Entity/Jecoute/JemarcheDataSurvey.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\HttpOperation;
use ApiPlatform\Metadata\Post;
use App\Controller\Api\Jecoute\JemarcheDataSurveyKpiController;
use App\Controller\Api\Jecoute\JemarcheDataSurveyReplyController;
Expand All @@ -22,9 +23,10 @@

#[ApiResource(
operations: [
new Post(
new HttpOperation(
method: 'POST',
uriTemplate: '/v3/jemarche_data_surveys/{uuid}/reply',
defaults: ['_api_receive' => false],
deserialize: false,
requirements: ['uuid' => '%pattern_uuid%'],
controller: JemarcheDataSurveyReplyController::class,
normalizationContext: ['groups' => ['data_survey_read']],
Expand Down
1 change: 0 additions & 1 deletion src/Entity/Jecoute/Region.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ class Region
/**
* @var bool
*/
#[Assert\Type('bool')]
#[ORM\Column(type: 'boolean', options: ['default' => true])]
private $enabled;

Expand Down
10 changes: 5 additions & 5 deletions src/Entity/Jecoute/Riposte.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\HttpOperation;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Controller\Api\Jecoute\IncrementRiposteStatsCounterController;
Expand Down Expand Up @@ -39,12 +40,13 @@
uriTemplate: '/v3/ripostes/{uuid}',
requirements: ['uuid' => '%pattern_uuid%']
),
new Put(
new HttpOperation(
method: 'PUT',
uriTemplate: '/v3/ripostes/{uuid}/action/{action}',
defaults: ['_api_receive' => false],
requirements: ['uuid' => '%pattern_uuid%'],
controller: IncrementRiposteStatsCounterController::class,
security: "is_granted('REQUEST_SCOPE_GRANTED', 'ripostes') or (is_granted('ROLE_USER') and is_granted('ROLE_OAUTH_SCOPE_JEMARCHE_APP'))"
security: "is_granted('REQUEST_SCOPE_GRANTED', 'ripostes') or (is_granted('ROLE_USER') and is_granted('ROLE_OAUTH_SCOPE_JEMARCHE_APP'))",
deserialize: false,
),
new GetCollection(
uriTemplate: '/v3/ripostes',
Expand Down Expand Up @@ -103,15 +105,13 @@ class Riposte implements AuthorInterface, IndexableEntityInterface
/**
* @var bool
*/
#[Assert\Type('bool')]
#[Groups(['riposte_list_read', 'riposte_read', 'riposte_write'])]
#[ORM\Column(type: 'boolean', options: ['default' => true])]
private $withNotification;

/**
* @var bool
*/
#[Assert\Type('bool')]
#[Groups(['riposte_list_read', 'riposte_read', 'riposte_write'])]
#[ORM\Column(type: 'boolean', options: ['default' => true])]
private $enabled;
Expand Down
7 changes: 4 additions & 3 deletions src/Entity/MyTeam/MyTeam.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\HttpOperation;
use App\Api\Filter\MyTeamScopeFilter;
use App\Controller\Api\MyTeam\InitializeMyTeamController;
use App\Entity\Adherent;
Expand All @@ -26,9 +26,10 @@
uriTemplate: '/v3/my_teams',
normalizationContext: ['groups' => ['my_team_read_list']]
),
new Post(
new HttpOperation(
method: 'POST',
uriTemplate: '/v3/my_teams',
defaults: ['_api_receive' => false],
deserialize: false,
controller: InitializeMyTeamController::class
),
],
Expand Down
1 change: 0 additions & 1 deletion src/Entity/Pap/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
),
new Get(
uriTemplate: '/v3/pap_campaigns/{uuid}/questioners',
defaults: ['_api_receive' => false],
requirements: ['uuid' => '%pattern_uuid%'],
controller: GetPapCampaignQuestionersStatsController::class,
security: "is_granted('REQUEST_SCOPE_GRANTED', ['pap_v2', 'pap'])"
Expand Down
6 changes: 4 additions & 2 deletions src/Entity/Pap/CampaignHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\HttpOperation;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Api\Filter\AdherentIdentityFilter;
Expand Down Expand Up @@ -42,9 +43,10 @@
requirements: ['uuid' => '%pattern_uuid%'],
security: 'is_granted(\'ROLE_OAUTH_SCOPE_JEMARCHE_APP\') and object.getQuestioner() == user'
),
new Post(
new HttpOperation(
method: 'POST',
uriTemplate: '/v3/pap_campaign_histories/{uuid}/reply',
defaults: ['_api_receive' => false],
deserialize: false,
requirements: ['uuid' => '%pattern_uuid%'],
controller: CampaignHistoryReplyController::class,
normalizationContext: ['groups' => ['data_survey_read']]
Expand Down
1 change: 0 additions & 1 deletion src/Entity/Phoning/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
),
new Get(
uriTemplate: '/v3/phoning_campaigns/{uuid}/callers',
defaults: ['_api_receive' => false],
requirements: ['uuid' => '%pattern_uuid%'],
controller: GetPhoningCampaignCallersStatsController::class,
security: "is_granted('REQUEST_SCOPE_GRANTED', 'phoning_campaign')"
Expand Down
7 changes: 4 additions & 3 deletions src/Entity/Phoning/CampaignHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\HttpOperation;
use ApiPlatform\Metadata\Put;
use App\Api\Filter\AdherentIdentityFilter;
use App\Controller\Api\Phoning\CampaignHistoryReplyController;
Expand Down Expand Up @@ -37,9 +37,10 @@
requirements: ['uuid' => '%pattern_uuid%'],
security: 'is_granted(\'IS_CAMPAIGN_HISTORY_CALLER\', object)'
),
new Post(
new HttpOperation(
method: 'POST',
uriTemplate: '/v3/phoning_campaign_histories/{uuid}/reply',
defaults: ['_api_receive' => false],
deserialize: false,
requirements: ['uuid' => '%pattern_uuid%'],
controller: CampaignHistoryReplyController::class,
normalizationContext: ['groups' => ['data_survey_read']]
Expand Down
Loading

0 comments on commit eb3b29c

Please sign in to comment.