Skip to content

Commit

Permalink
Add new reject endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Tamás András Horváth <[email protected]>
  • Loading branch information
icetee committed May 27, 2023
1 parent e43650e commit f40674a
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@
App\Middleware\UserMiddleware::class,
App\Handler\Account\PrintHandler::class
], 'admin.api.account.print');

$app->post('/admin/api/account/reject', [
Jwt\Handler\JwtAuthMiddleware::class,
App\Middleware\UserMiddleware::class,
App\Handler\Account\RejectHandler::class
], 'admin.api.account.reject');
};
2 changes: 2 additions & 0 deletions src/App/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function getDependencies(): array
Handler\Account\SearchHandler::class => Handler\Account\SearchHandlerFactory::class,
Handler\Account\SendHandler::class => Handler\Account\SendHandlerFactory::class,
Handler\Account\PrintHandler::class => Handler\Account\PrintHandlerFactory::class,
Handler\Account\RejectHandler::class => Handler\Account\RejectHandlerFactory::class,
Handler\Setting\GetHandler::class => Handler\Setting\GetHandlerFactory::class,
Service\AccountServiceInterface::class => Service\AccountServiceFactory::class,
Service\AuditLogServiceInterface::class => Service\AuditLogServiceFactory::class,
Expand All @@ -59,6 +60,7 @@ public function getInputFilters(): array
'invokables' => [
InputFilter\AccountSearchFilter::class => InputFilter\AccountSearchFilter::class,
InputFilter\AccountSendFilter::class => InputFilter\AccountSendFilter::class,
InputFilter\AccountRejectFilter::class => InputFilter\AccountRejectFilter::class,
],
];
}
Expand Down
49 changes: 49 additions & 0 deletions src/App/src/Handler/Account/RejectHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace App\Handler\Account;

use App\Service\AccountServiceInterface;
use App\Middleware\UserMiddleware;
use Laminas\Diactoros\Response\JsonResponse;
use Laminas\InputFilter\InputFilterInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

final class RejectHandler implements RequestHandlerInterface
{
public function __construct(
private AccountServiceInterface $accountService,
private InputFilterInterface $accountRejectFilter
) {
$this->accountService = $accountService;
$this->accountRejectFilter = $accountRejectFilter;
}

public function handle(ServerRequestInterface $request): ResponseInterface
{
$user = $request->getAttribute(UserMiddleware::class);

$body = $request->getParsedBody();

$this->accountRejectFilter->setData($body);

if (! $this->accountRejectFilter->isValid()) {
return new JsonResponse([
'errors' => $this->accountRejectFilter->getMessages(),
], 422);
}

$this->accountService->sendRejectNotification(
$user,
$this->accountRejectFilter->getValues()['type'],
$this->accountRejectFilter->getValues()['email'],
);

return new JsonResponse([
'message' => 'Sikeres elutasító e-mail küldés'
]);
}
}
25 changes: 25 additions & 0 deletions src/App/src/Handler/Account/RejectHandlerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace App\Handler\Account;

use App\InputFilter\AccountRejectFilter;
use App\Service\AccountServiceInterface;
use Laminas\InputFilter\InputFilterPluginManager;
use Psr\Container\ContainerInterface;

final class RejectHandlerFactory
{
public function __invoke(ContainerInterface $container): RejectHandler
{
/** @var InputFilterPluginManager $pluginManager */
$pluginManager = $container->get(InputFilterPluginManager::class);
$inputFilter = $pluginManager->get(AccountRejectFilter::class);

return new RejectHandler(
$container->get(AccountServiceInterface::class),
$inputFilter
);
}
}
75 changes: 75 additions & 0 deletions src/App/src/InputFilter/AccountRejectFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

declare(strict_types=1);

namespace App\InputFilter;

use Laminas\Filter;
use Laminas\InputFilter\InputFilter;
use Laminas\Validator;

/** phpcs:disable */
class AccountRejectFilter extends InputFilter
{
public function init()
{
$this->add([
'name' => 'type',
'allow_empty' => false,
'validators' => [
new Validator\NotEmpty([
'messages' => [
Validator\NotEmpty::IS_EMPTY => 'Kötelező a mező kitöltése',
Validator\NotEmpty::INVALID => 'Hibás mező tipus',
],
]),
],
'filters' => [
new Filter\StringTrim(),
new Filter\StripTags(),
new Filter\StringToUpper(),
],
]);

$this->add([
'name' => 'email',
'allow_empty' => false,
'validators' => [
new Validator\NotEmpty([
'messages' => [
Validator\NotEmpty::IS_EMPTY => 'Kötelező a mező kitöltése',
Validator\NotEmpty::INVALID => 'Hibás mező tipus',
],
]),
new Validator\EmailAddress([
'messages' => [
Validator\EmailAddress::INVALID => "Érvénytelen típus megadva. Szöveg adható meg.",
Validator\EmailAddress::INVALID_FORMAT => "A bevitel nem érvényes e-mail cím. Használja az alapformátumot pl. [email protected]",
Validator\EmailAddress::INVALID_HOSTNAME => "'%hostname%' érvénytelen gazdagépnév",
Validator\EmailAddress::INVALID_MX_RECORD => "'%hostname%' úgy tűnik, hogy az e-mail címhez nincs érvényes MX vagy A rekordja",
Validator\EmailAddress::INVALID_SEGMENT => "'%hostname%' is not in a routable network segment. The email address should not be resolved from public network",
Validator\EmailAddress::DOT_ATOM => "'%localPart%' can not be matched against dot-atom format",
Validator\EmailAddress::QUOTED_STRING => "'%localPart%' nem illeszthető idézőjel a szövegbe",
Validator\EmailAddress::INVALID_LOCAL_PART => "'%localPart%' nem érvényes az e-mail cím helyi része",
Validator\EmailAddress::LENGTH_EXCEEDED => "A szöveg meghaladja az engedélyezett hosszúságot",
],
]),
new Validator\StringLength([
'messages' => [
Validator\StringLength::TOO_SHORT => 'Legalább %min% karaktert kell tartalmaznia a mezőnek',
Validator\StringLength::TOO_LONG => 'Kevesebb karaktert kell tartalmaznia a mezőnek mint: %max%',
Validator\StringLength::INVALID => 'Hibás mező tipus. Csak szöveg fogadható el',
],
'min' => 5,
'max' => 255,
]),
],
'filters' => [
new Filter\StringTrim(),
new Filter\StripTags(),
new Filter\StringToLower(),
],
]);
}
}
/** phpcs:enable */
23 changes: 23 additions & 0 deletions src/App/src/Service/AccountService.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ public function sendAccount(UserInterface $user, string $id, string $email): voi
}
}

public function sendRejectNotification(UserInterface $user, string $type, string $email): void
{
$notification = new SimpleNotification("0", $email);

$this->sendRejectEmail($user, $notification, $type);
}

public function printAccount(UserInterface $user, string $id): ?Dompdf
{
$account = $this->accountRepository->find($id);
Expand Down Expand Up @@ -134,4 +141,20 @@ private function printAuthCodeEmail(

return $dompdf;
}

private function sendRejectEmail(
UserInterface $user,
NotificationInterface $notification,
string $type
): void {
$tplData = [
'infoMunicipality' => $this->config['app']['municipality'],
'infoEmail' => $this->config['app']['email'],
'appURL' => $this->config['app']['url'],
];

$this->mailService->send('reject-type-' . $type, $tplData, $notification);

$this->auditService->log($user, 'reject-email', null, $type);
}
}
6 changes: 6 additions & 0 deletions src/App/src/Service/AccountServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ public function printAccount(
UserInterface $user,
string $id
): ?Dompdf;

public function sendRejectNotification(
UserInterface $user,
string $type,
string $email
): void;
}

0 comments on commit f40674a

Please sign in to comment.