From 1056fcb75e82e04d3cd5abd19483a0aba015be36 Mon Sep 17 00:00:00 2001 From: RahatHameed Date: Thu, 15 Aug 2024 12:00:54 +0200 Subject: [PATCH] OXDEV-8489 Added module status check to block activation - Added logic to check if a module is in the blocklist before activation. - Throws ModuleActivationBlockedException if the module is blocked. - Mentioned this change in readme and chanelog files. --- CHANGELOG.md | 4 +-- README.md | 4 +-- .../ModuleActivationBlockedException.php | 22 +++++++++++++ .../Service/ModuleActivationService.php | 5 +++ .../Service/ModuleActivationsServiceTest.php | 33 +++++++++++++++---- 5 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 src/Module/Exception/ModuleActivationBlockedException.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 36ce835..7b4e628 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Theme list and filtering option on basis of theme name and status - Module list and filtering option on basis of module name and status - Activation of given theme by themeId -- Mutations to activate and deactive a module. -- Prevention of deactivation of certain modules mentioned in modules_blocklist.yaml. +- Mutations to de/activate a module. +- Prevention of de/activation of certain modules mentioned in modules_blocklist.yaml. ## [1.1.0] - 2024-07-05 This is stable release for v1.1.0. No changes have been made since v1.1.0-rc.1. diff --git a/README.md b/README.md index 857803e..0d4aa83 100644 --- a/README.md +++ b/README.md @@ -64,10 +64,10 @@ $ vendor/bin/oe-console oe:module:activate oe_graphql_configuration_access A good starting point is to check the [How to use section in the GraphQL Base Module](https://github.com/OXID-eSales/graphql-base-module/#how-to-use) -## Blocking modules from deactivation via GraphQL +## Blocking modules from de/activation via GraphQL The file module_blockilst.yaml contains a list of modules which are necessary to handle configurations or de/activate -modules via GraphQL or should be blocked for deactivation via GraphQL in general. Modules like ``oe_graphql_base`` and +modules via GraphQL or should be blocked for de/activation via GraphQL in general. Modules like ``oe_graphql_base`` and ``oe_graphql_configuration_access`` are listed there. ## Testing diff --git a/src/Module/Exception/ModuleActivationBlockedException.php b/src/Module/Exception/ModuleActivationBlockedException.php new file mode 100644 index 0000000..a2dc549 --- /dev/null +++ b/src/Module/Exception/ModuleActivationBlockedException.php @@ -0,0 +1,22 @@ +moduleBlocklistService->isModuleBlocked($moduleId)) { + throw new ModuleActivationBlockedException($moduleId); + } + $shopId = $this->context->getCurrentShopId(); try { diff --git a/tests/Unit/Module/Service/ModuleActivationsServiceTest.php b/tests/Unit/Module/Service/ModuleActivationsServiceTest.php index 3dd7dde..f5a8b14 100644 --- a/tests/Unit/Module/Service/ModuleActivationsServiceTest.php +++ b/tests/Unit/Module/Service/ModuleActivationsServiceTest.php @@ -12,6 +12,7 @@ use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface; use OxidEsales\EshopCommunity\Internal\Framework\Module\Setup\Bridge\ModuleActivationBridgeInterface; use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleActivationException; +use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleActivationBlockedException; use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleDeactivationBlockedException; use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleDeactivationException; use OxidEsales\GraphQL\ConfigurationAccess\Module\Service\ModuleActivationService; @@ -26,7 +27,7 @@ class ModuleActivationsServiceTest extends UnitTestCase /** * @dataProvider activationDataProvider */ - public function testModuleActivationAndDeactivation( + public function testModuleActivationAndDeactivationSuccess( string $method, ): void { $shopId = 1; @@ -55,7 +56,7 @@ public function testModuleActivationAndDeactivation( /** * @dataProvider exceptionDataProvider */ - public function testModuleActivationAndDeactivationExceptions( + public function testModuleActivationAndDeactivationThrowsExceptions( string $method, mixed $exceptionClass ): void { @@ -76,8 +77,13 @@ public function testModuleActivationAndDeactivationExceptions( ($method === 'activate') ? $sut->activateModule($moduleId) : $sut->deactivateModule($moduleId); } - public function testModuleDeactivationBlockedException() - { + /** + * @dataProvider moduleBlockedExceptionDataProvider + */ + public function testModuleActivationAndDeactivationBlockedException( + string $method, + mixed $exceptionClass + ) { $moduleId = uniqid(); $moduleBlockListServiceMock = $this->createMock(ModuleBlocklistServiceInterface::class); $moduleBlockListServiceMock @@ -89,8 +95,23 @@ public function testModuleDeactivationBlockedException() moduleBlocklistService: $moduleBlockListServiceMock ); - $this->expectException(ModuleDeactivationBlockedException::class); - $sut->deactivateModule($moduleId); + $this->expectException($exceptionClass); + ($method === 'activate') ? $sut->activateModule($moduleId) : $sut->deactivateModule($moduleId); + } + + public static function moduleBlockedExceptionDataProvider(): \Generator + { + yield 'test activate module blocked exception' => [ + 'method' => 'activate', + 'exceptionClass' => ModuleActivationBlockedException::class + + ]; + + yield 'test deactivate module blocked exception' => [ + 'method' => 'deactivate', + 'exceptionClass' => ModuleDeactivationBlockedException::class + + ]; } public static function activationDataProvider(): \Generator