Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lazka committed Nov 21, 2023
1 parent f66694e commit 7bd511a
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Dbp\Relay\DispatchBundle\Controller;
namespace Dbp\Relay\DispatchBundle\ApiPlatform;

use Dbp\Relay\DispatchBundle\Authorization\AuthorizationService;
use Dbp\Relay\DispatchBundle\Entity\Request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

declare(strict_types=1);

namespace Dbp\Relay\DispatchBundle\DataPersister;
namespace Dbp\Relay\DispatchBundle\ApiPlatform;

use ApiPlatform\Core\DataPersister\ContextAwareDataPersisterInterface;
use ApiPlatform\Metadata\DeleteOperationInterface;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use Dbp\Relay\CoreBundle\Exception\ApiError;
use Dbp\Relay\DispatchBundle\Authorization\AuthorizationService;
use Dbp\Relay\DispatchBundle\Entity\Request;
use Dbp\Relay\DispatchBundle\Service\DispatchService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

class RequestDataPersister extends AbstractController implements ContextAwareDataPersisterInterface
class RequestProcessor extends AbstractController implements ProcessorInterface
{
/**
* @var DispatchService
Expand All @@ -30,11 +32,6 @@ public function __construct(DispatchService $dispatchService, AuthorizationServi
$this->auth = $auth;
}

public function supports($data, array $context = []): bool
{
return $data instanceof Request;
}

/**
* @param mixed $data
*
Expand Down Expand Up @@ -71,25 +68,22 @@ public function persist($data, array $context = [])
return $request;
}

/**
* @param mixed $data
*
* @return void
*/
public function remove($data, array $context = [])
public function process($data, Operation $operation, array $uriVariables = [], array $context = [])
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$this->auth->checkCanUse();

$request = $data;
assert($request instanceof Request);
if ($operation instanceof DeleteOperationInterface) {
$request = $data;
assert($request instanceof Request);

$this->auth->checkCanWrite($request->getGroupId());
$this->auth->checkCanWrite($request->getGroupId());

if ($request->isSubmitted()) {
throw ApiError::withDetails(Response::HTTP_BAD_REQUEST, 'Submitted requests cannot be modified!', 'dispatch:request-submitted-read-only');
}
if ($request->isSubmitted()) {
throw ApiError::withDetails(Response::HTTP_BAD_REQUEST, 'Submitted requests cannot be modified!', 'dispatch:request-submitted-read-only');
}

$this->dispatchService->removeRequestById($request->getIdentifier());
$this->dispatchService->removeRequestById($request->getIdentifier());
}
}
}
68 changes: 68 additions & 0 deletions src/ApiPlatform/RequestProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare(strict_types=1);

namespace Dbp\Relay\DispatchBundle\ApiPlatform;

use ApiPlatform\Metadata\CollectionOperationInterface;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\Pagination\PartialPaginatorInterface;
use ApiPlatform\State\ProviderInterface;
use Dbp\Relay\CoreBundle\Exception\ApiError;
use Dbp\Relay\CoreBundle\Rest\Query\Pagination\Pagination;
use Dbp\Relay\CoreBundle\Rest\Query\Pagination\WholeResultPaginator;
use Dbp\Relay\DispatchBundle\Authorization\AuthorizationService;
use Dbp\Relay\DispatchBundle\Entity\Request;
use Dbp\Relay\DispatchBundle\Service\DispatchService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

final class RequestProvider extends AbstractController implements ProviderInterface
{
/**
* @var DispatchService
*/
private $dispatchService;
/**
* @var AuthorizationService
*/
private $auth;

public function __construct(DispatchService $dispatchService, AuthorizationService $auth)
{
$this->dispatchService = $dispatchService;
$this->auth = $auth;
}

/**
* @return PartialPaginatorInterface|Request
*/
public function provide(Operation $operation, array $uriVariables = [], array $context = [])
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$this->auth->checkCanUse();

if ($operation instanceof CollectionOperationInterface) {
$filters = $context['filters'] ?? [];

$groupId = $filters['groupId'] ?? null;
if ($groupId === null) {
throw ApiError::withDetails(Response::HTTP_BAD_REQUEST, 'groupId query parameter missing');
}
$this->auth->checkCanReadMetadata($groupId);

return new WholeResultPaginator(
$this->dispatchService->getRequestsForGroupId($groupId),
Pagination::getCurrentPageNumber($filters),
Pagination::getMaxNumItemsPerPage($filters));
} else {
$id = $uriVariables['identifier'];
assert(is_string($id));
$request = $this->dispatchService->getRequestById($id);
$groupId = $request->getGroupId();
$this->auth->checkCanReadMetadata($groupId);

return $request;
}
}
}
59 changes: 0 additions & 59 deletions src/DataProvider/RequestCollectionDataProvider.php

This file was deleted.

47 changes: 0 additions & 47 deletions src/DataProvider/RequestItemDataProvider.php

This file was deleted.

2 changes: 0 additions & 2 deletions src/DependencyInjection/DbpRelayDispatchExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class DbpRelayDispatchExtension extends ConfigurableExtension implements Prepend

public function loadInternal(array $mergedConfig, ContainerBuilder $container)
{
$this->addResourceClassDirectory($container, __DIR__.'/../Entity');

$pathsToHide = [
'/dispatch/pre-addressing-requests/{identifier}',
'/dispatch/pre-addressing-requests',
Expand Down
Loading

0 comments on commit 7bd511a

Please sign in to comment.