From edf0a34e5936df1bf34496e53c55bc5b5744d779 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sun, 6 Jan 2019 20:03:28 +0100 Subject: [PATCH] Implemented draft for CRUD management --- .../Controller/API/APIControllerInterface.php | 19 ------- .../Controller/API/AbstractAPIController.php | 20 +++++--- .../API/CRUDControllerInterface.php | 47 ------------------ .../API/Meta/HeredityApiController.php | 8 ++- .../Controller/API/Meta/LawApiController.php | 4 +- .../API/Meta/MemberApiController.php | 8 ++- .../API/Meta/RightApiController.php | 8 ++- .../API/Source/SourceApiController.php | 49 ++++++++++++------- .../AbstractSecureCRUD.php | 11 +++++ .../Create/AbstractSecureCreator.php | 11 +++++ .../Create/SecureCreatorInterface.php | 19 +++++++ .../Create/SecureSourceCreator.php | 28 +++++++++++ .../Create/SecureSourceCreatorInterface.php | 11 +++++ .../SecureCRUDFactoryService.php | 42 ++++++++++++++++ .../SecureCRUDInterface.php | 12 +++++ .../API/Source/SourceControllerTest.php | 28 +++++++++++ 16 files changed, 232 insertions(+), 93 deletions(-) delete mode 100644 application/symfony/src/Controller/API/APIControllerInterface.php delete mode 100644 application/symfony/src/Controller/API/CRUDControllerInterface.php create mode 100644 application/symfony/src/Domain/SecureCRUDManagement/AbstractSecureCRUD.php create mode 100644 application/symfony/src/Domain/SecureCRUDManagement/Create/AbstractSecureCreator.php create mode 100644 application/symfony/src/Domain/SecureCRUDManagement/Create/SecureCreatorInterface.php create mode 100644 application/symfony/src/Domain/SecureCRUDManagement/Create/SecureSourceCreator.php create mode 100644 application/symfony/src/Domain/SecureCRUDManagement/Create/SecureSourceCreatorInterface.php create mode 100644 application/symfony/src/Domain/SecureCRUDManagement/SecureCRUDFactoryService.php create mode 100644 application/symfony/src/Domain/SecureCRUDManagement/SecureCRUDInterface.php create mode 100644 application/symfony/tests/Unit/Controller/API/Source/SourceControllerTest.php diff --git a/application/symfony/src/Controller/API/APIControllerInterface.php b/application/symfony/src/Controller/API/APIControllerInterface.php deleted file mode 100644 index 134d247..0000000 --- a/application/symfony/src/Controller/API/APIControllerInterface.php +++ /dev/null @@ -1,19 +0,0 @@ -getUser()) { + //throw $this->createAccessDeniedException('The user must be logged in!'); + } + if (Request::METHOD_POST === $request->getMethod()) { $response = new Response(); $response->setContent('Post Request!'); return $response; } - - $response = new Response(); - $response->setContent('GET Request!'); + /** + * @var SecureSourceCreatorInterface + */ + $sourceCreator = $crudFactory->create(); + $response->setContent($sourceCreator->create()->getText()); return $response; - $requestedSource = new PureSource(); - $requestedSource->setSlug(SystemSlugType::IMPRINT); - $requestedRight = new Right(); - $requestedRight->setSource($requestedSource); - $requestedRight->setLayer(LayerType::SOURCE); - $requestedRight->setType(CRUDType::READ); - $sourceResponseManager = new SourceRESTResponseManager($this->getUser(), $entityManager, $requestedRight, $this->getViewHandler()); +// $response = new Response(); +// $response->setContent('GET Request!'); - return $sourceResponseManager->getResponse(); +// return $response; + +// $requestedSource = new PureSource(); +// $requestedSource->setSlug(SystemSlugType::IMPRINT); +// $requestedRight = new Right(); +// $requestedRight->setSource($requestedSource); +// $requestedRight->setLayer(LayerType::SOURCE); +// $requestedRight->setType(CRUDType::READ); +// $sourceResponseManager = new SourceRESTResponseManager($this->getUser(), $entityManager, $requestedRight, $this->getViewHandler()); + +// return $sourceResponseManager->getResponse(); } /** @@ -67,7 +82,7 @@ class SourceApiController extends AbstractAPIController * ) * {@inheritdoc} * - * @see \App\Controller\API\CRUDControllerInterface::update() + * @see \App\Controller\API\AbstractAPIController::update() */ public function update(Request $request, $identifier): Response { @@ -80,7 +95,7 @@ class SourceApiController extends AbstractAPIController * ) * {@inheritdoc} * - * @see \App\Controller\API\APIControllerInterface::list() + * @see \App\Controller\API\AbstractAPIController::list() */ public function list(Request $request): Response { @@ -93,7 +108,7 @@ class SourceApiController extends AbstractAPIController * ) * {@inheritdoc} * - * @see \App\Controller\API\CRUDControllerInterface::delete() + * @see \App\Controller\API\AbstractAPIController::delete() */ public function delete(Request $request, $identifier): Response { diff --git a/application/symfony/src/Domain/SecureCRUDManagement/AbstractSecureCRUD.php b/application/symfony/src/Domain/SecureCRUDManagement/AbstractSecureCRUD.php new file mode 100644 index 0000000..34a7d61 --- /dev/null +++ b/application/symfony/src/Domain/SecureCRUDManagement/AbstractSecureCRUD.php @@ -0,0 +1,11 @@ +setText('Hello World!'); + + return $source; + } +} diff --git a/application/symfony/src/Domain/SecureCRUDManagement/Create/SecureSourceCreatorInterface.php b/application/symfony/src/Domain/SecureCRUDManagement/Create/SecureSourceCreatorInterface.php new file mode 100644 index 0000000..5166ac7 --- /dev/null +++ b/application/symfony/src/Domain/SecureCRUDManagement/Create/SecureSourceCreatorInterface.php @@ -0,0 +1,11 @@ +request = $requestStack->getCurrentRequest(); + $this->security = $security; + } + + /** + * @param RightInterface $requestedRight + */ + public function create(?RightInterface $requestedRight = null) + { + return new SecureSourceCreator($this->request, $this->security); + } +} diff --git a/application/symfony/src/Domain/SecureCRUDManagement/SecureCRUDInterface.php b/application/symfony/src/Domain/SecureCRUDManagement/SecureCRUDInterface.php new file mode 100644 index 0000000..3f143bd --- /dev/null +++ b/application/symfony/src/Domain/SecureCRUDManagement/SecureCRUDInterface.php @@ -0,0 +1,12 @@ + $url, + ]); + $request->setMethod(Request::METHOD_GET); + $response = static::$kernel->handle($request); + $this->assertEquals(200, $response->getStatusCode()); + } +}