-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
665 additions
and
7 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
config/validator/Application/SigningAuthority/SaveSigningAuthorityCommand.xml
This file contains 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,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping https://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"> | ||
<class name="App\Application\Organization\SigningAuthority\Command\SaveSigningAuthorityCommand"> | ||
<property name="name"> | ||
<constraint name="NotBlank"/> | ||
<constraint name="Length"> | ||
<option name="max">100</option> | ||
</constraint> | ||
</property> | ||
<property name="placeOfSignature"> | ||
<constraint name="NotBlank"/> | ||
<constraint name="Length"> | ||
<option name="max">100</option> | ||
</constraint> | ||
</property> | ||
<property name="signatoryName"> | ||
<constraint name="NotBlank"/> | ||
<constraint name="Length"> | ||
<option name="max">100</option> | ||
</constraint> | ||
</property> | ||
<property name="address"> | ||
<constraint name="NotBlank"/> | ||
</property> | ||
</class> | ||
</constraint-mapping> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions
27
src/Application/Organization/SigningAuthority/Command/SaveSigningAuthorityCommand.php
This file contains 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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application\Organization\SigningAuthority\Command; | ||
|
||
use App\Application\CommandInterface; | ||
use App\Domain\Organization\SigningAuthority\SigningAuthority; | ||
use App\Domain\User\Organization; | ||
|
||
final class SaveSigningAuthorityCommand implements CommandInterface | ||
{ | ||
public ?string $name = null; | ||
public ?string $address = null; | ||
public ?string $placeOfSignature = null; | ||
public ?string $signatoryName = null; | ||
|
||
public function __construct( | ||
public readonly Organization $organization, | ||
public readonly ?SigningAuthority $signingAuthority = null, | ||
) { | ||
$this->name = $signingAuthority?->getName(); | ||
$this->address = $signingAuthority?->getAddress(); | ||
$this->placeOfSignature = $signingAuthority?->getPlaceOfSignature(); | ||
$this->signatoryName = $signingAuthority?->getSignatoryName(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/Application/Organization/SigningAuthority/Command/SaveSigningAuthorityCommandHandler.php
This file contains 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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application\Organization\SigningAuthority\Command; | ||
|
||
use App\Application\IdFactoryInterface; | ||
use App\Domain\Organization\SigningAuthority\Repository\SigningAuthorityRepositoryInterface; | ||
use App\Domain\Organization\SigningAuthority\SigningAuthority; | ||
|
||
final class SaveSigningAuthorityCommandHandler | ||
{ | ||
public function __construct( | ||
private IdFactoryInterface $idFactory, | ||
private SigningAuthorityRepositoryInterface $signingAuthorityRepository, | ||
) { | ||
} | ||
|
||
public function __invoke(SaveSigningAuthorityCommand $command): SigningAuthority | ||
{ | ||
if ($signingAuthority = $command->signingAuthority) { | ||
$signingAuthority->update( | ||
name: $command->name, | ||
address: $command->address, | ||
placeOfSignature: $command->placeOfSignature, | ||
signatoryName: $command->signatoryName, | ||
); | ||
|
||
return $signingAuthority; | ||
} | ||
|
||
return $this->signingAuthorityRepository->add( | ||
new SigningAuthority( | ||
uuid: $this->idFactory->make(), | ||
name: $command->name, | ||
address: $command->address, | ||
placeOfSignature: $command->placeOfSignature, | ||
signatoryName: $command->signatoryName, | ||
organization: $command->organization, | ||
), | ||
); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...pplication/Organization/SigningAuthority/Query/GetSigningAuthorityByOrganizationQuery.php
This file contains 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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application\Organization\SigningAuthority\Query; | ||
|
||
use App\Application\QueryInterface; | ||
|
||
final class GetSigningAuthorityByOrganizationQuery implements QueryInterface | ||
{ | ||
public function __construct( | ||
public readonly string $organizationUuid, | ||
) { | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ion/Organization/SigningAuthority/Query/GetSigningAuthorityByOrganizationQueryHandler.php
This file contains 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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application\Organization\SigningAuthority\Query; | ||
|
||
use App\Domain\Organization\SigningAuthority\Repository\SigningAuthorityRepositoryInterface; | ||
use App\Domain\Organization\SigningAuthority\SigningAuthority; | ||
|
||
final class GetSigningAuthorityByOrganizationQueryHandler | ||
{ | ||
public function __construct( | ||
private SigningAuthorityRepositoryInterface $signingAuthorityRepository, | ||
) { | ||
} | ||
|
||
public function __invoke(GetSigningAuthorityByOrganizationQuery $query): ?SigningAuthority | ||
{ | ||
return $this->signingAuthorityRepository->findOneByOrganizationUuid($query->organizationUuid); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Domain/Organization/SigningAuthority/Repository/SigningAuthorityRepositoryInterface.php
This file contains 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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Domain\Organization\SigningAuthority\Repository; | ||
|
||
use App\Domain\Organization\SigningAuthority\SigningAuthority; | ||
|
||
interface SigningAuthorityRepositoryInterface | ||
{ | ||
public function findOneByOrganizationUuid(string $organizationUuid): ?SigningAuthority; | ||
|
||
public function add(SigningAuthority $signingAuthority): SigningAuthority; | ||
} |
This file contains 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
78 changes: 78 additions & 0 deletions
78
...ucture/Controller/MyArea/Organization/SigningAuthority/EditSigningAuthorityController.php
This file contains 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,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Infrastructure\Controller\MyArea\Organization\SigningAuthority; | ||
|
||
use App\Application\CommandBusInterface; | ||
use App\Application\Organization\SigningAuthority\Command\SaveSigningAuthorityCommand; | ||
use App\Application\Organization\SigningAuthority\Query\GetSigningAuthorityByOrganizationQuery; | ||
use App\Application\QueryBusInterface; | ||
use App\Infrastructure\Controller\MyArea\Organization\AbstractOrganizationController; | ||
use App\Infrastructure\Form\Organization\SigningAuthorityFormType; | ||
use App\Infrastructure\Security\Voter\OrganizationVoter; | ||
use Symfony\Bundle\SecurityBundle\Security; | ||
use Symfony\Component\Form\FormFactoryInterface; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
use Symfony\Component\Routing\Requirement\Requirement; | ||
use Symfony\Component\Routing\RouterInterface; | ||
|
||
final class EditSigningAuthorityController extends AbstractOrganizationController | ||
{ | ||
public function __construct( | ||
private \Twig\Environment $twig, | ||
private FormFactoryInterface $formFactory, | ||
private RouterInterface $router, | ||
private CommandBusInterface $commandBus, | ||
QueryBusInterface $queryBus, | ||
Security $security, | ||
) { | ||
parent::__construct($queryBus, $security); | ||
} | ||
|
||
#[Route( | ||
'/organizations/{uuid}/signing_authority/edit', | ||
name: 'app_config_signing_authority_edit', | ||
requirements: ['uuid' => Requirement::UUID], | ||
methods: ['GET', 'POST'], | ||
)] | ||
public function __invoke(Request $request, string $uuid): Response | ||
{ | ||
$organization = $this->getOrganization($uuid); | ||
|
||
if (!$this->security->isGranted(OrganizationVoter::EDIT, $organization)) { | ||
throw new AccessDeniedHttpException(); | ||
} | ||
|
||
$signingAuthority = $this->queryBus->handle(new GetSigningAuthorityByOrganizationQuery($uuid)); | ||
$command = new SaveSigningAuthorityCommand($organization, $signingAuthority); | ||
$form = $this->formFactory->create(SigningAuthorityFormType::class, $command); | ||
$form->handleRequest($request); | ||
|
||
if ($form->isSubmitted() && $form->isValid()) { | ||
$this->commandBus->handle($command); | ||
|
||
return new RedirectResponse( | ||
url: $this->router->generate('app_config_signing_authority_edit', ['uuid' => $uuid]), | ||
status: Response::HTTP_SEE_OTHER, | ||
); | ||
} | ||
|
||
return new Response( | ||
content: $this->twig->render( | ||
name: 'my_area/organization/signing_authority/form.html.twig', | ||
context: [ | ||
'organization' => $organization, | ||
'form' => $form->createView(), | ||
], | ||
), | ||
status: ($form->isSubmitted() && !$form->isValid()) | ||
? Response::HTTP_UNPROCESSABLE_ENTITY | ||
: Response::HTTP_OK, | ||
); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/Infrastructure/Form/Organization/SigningAuthorityFormType.php
This file contains 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,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Infrastructure\Form\Organization; | ||
|
||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\SubmitType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextareaType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
final class SigningAuthorityFormType extends AbstractType | ||
{ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder | ||
->add( | ||
'name', | ||
TextType::class, | ||
options: [ | ||
'label' => 'signing_authority.name', | ||
'help' => 'signing_authority.name.help', | ||
], | ||
) | ||
->add( | ||
'address', | ||
TextareaType::class, | ||
options: [ | ||
'label' => 'signing_authority.address', | ||
'help' => 'signing_authority.address.help', | ||
], | ||
) | ||
->add( | ||
'placeOfSignature', | ||
TextType::class, | ||
options: [ | ||
'label' => 'signing_authority.placeOfSignature', | ||
'help' => 'signing_authority.placeOfSignature.help', | ||
], | ||
) | ||
->add( | ||
'signatoryName', | ||
TextType::class, | ||
options: [ | ||
'label' => 'signing_authority.signatoryName', | ||
'help' => 'signing_authority.signatoryName.help', | ||
], | ||
) | ||
->add('save', SubmitType::class, | ||
options: [ | ||
'label' => 'common.save', | ||
'attr' => ['class' => 'fr-btn'], | ||
], | ||
) | ||
; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...structure/Persistence/Doctrine/Repository/SigningAuthority/SigningAuthorityRepository.php
This file contains 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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Infrastructure\Persistence\Doctrine\Repository\SigningAuthority; | ||
|
||
use App\Domain\Organization\SigningAuthority\Repository\SigningAuthorityRepositoryInterface; | ||
use App\Domain\Organization\SigningAuthority\SigningAuthority; | ||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
|
||
final class SigningAuthorityRepository extends ServiceEntityRepository implements SigningAuthorityRepositoryInterface | ||
{ | ||
public function __construct(ManagerRegistry $registry) | ||
{ | ||
parent::__construct($registry, SigningAuthority::class); | ||
} | ||
|
||
public function add(SigningAuthority $signingAuthority): SigningAuthority | ||
{ | ||
$this->getEntityManager()->persist($signingAuthority); | ||
|
||
return $signingAuthority; | ||
} | ||
|
||
public function findOneByOrganizationUuid(string $organizationUuid): ?SigningAuthority | ||
{ | ||
return $this->createQueryBuilder('s') | ||
->where('s.organization = :uuid') | ||
->setParameter('uuid', $organizationUuid) | ||
->setMaxResults(1) | ||
->getQuery() | ||
->getOneOrNullResult() | ||
; | ||
} | ||
} |
This file contains 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
Oops, something went wrong.