-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'b-7.2.x-change-module-status-OXDEV-8216' into b-7.2.x
- Loading branch information
Showing
17 changed files
with
505 additions
and
15 deletions.
There are no files selected for viewing
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
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,49 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\GraphQL\ConfigurationAccess\Module\Controller; | ||
|
||
use OxidEsales\GraphQL\ConfigurationAccess\Module\Service\ModuleActivationServiceInterface; | ||
use TheCodingMachine\GraphQLite\Annotations\Logged; | ||
use TheCodingMachine\GraphQLite\Annotations\Mutation; | ||
use TheCodingMachine\GraphQLite\Annotations\Right; | ||
|
||
class ModuleActivationController | ||
{ | ||
public function __construct( | ||
private readonly ModuleActivationServiceInterface $moduleActivationService | ||
) { | ||
} | ||
|
||
/** | ||
* Mutation of Configuration Access Module | ||
* @param string $moduleId | ||
* @return bool | ||
*/ | ||
#[Mutation] | ||
#[Logged] | ||
#[Right('ACTIVATE_MODULE')] | ||
public function activateModule(string $moduleId): bool | ||
{ | ||
return $this->moduleActivationService->activateModule(moduleId: $moduleId); | ||
} | ||
|
||
/** | ||
* Mutation of Configuration Access Module | ||
* @param string $moduleId | ||
* @return bool | ||
*/ | ||
#[Mutation] | ||
#[Logged] | ||
#[Right('ACTIVATE_MODULE')] | ||
public function deactivateModule(string $moduleId): bool | ||
{ | ||
return $this->moduleActivationService->deactivateModule(moduleId: $moduleId); | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\GraphQL\ConfigurationAccess\Module\Exception; | ||
|
||
use OxidEsales\GraphQL\Base\Exception\NotFound; | ||
|
||
final class ModuleActivationException extends NotFound | ||
{ | ||
private const EXCEPTION_MESSAGE = "An error occurred while activating the module."; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(self::EXCEPTION_MESSAGE); | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\GraphQL\ConfigurationAccess\Module\Exception; | ||
|
||
use OxidEsales\GraphQL\Base\Exception\NotFound; | ||
|
||
final class ModuleDeactivationException extends NotFound | ||
{ | ||
private const EXCEPTION_MESSAGE = "An error occurred while deactivating the module."; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(self::EXCEPTION_MESSAGE); | ||
} | ||
} |
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
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,56 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\GraphQL\ConfigurationAccess\Module\Service; | ||
|
||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setup\Bridge\ModuleActivationBridgeInterface; | ||
use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface; | ||
use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleActivationException; | ||
use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleDeactivationException; | ||
|
||
class ModuleActivationService implements ModuleActivationServiceInterface | ||
{ | ||
public function __construct( | ||
private readonly ContextInterface $context, | ||
private readonly ModuleActivationBridgeInterface $moduleActivationBridge | ||
) { | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function activateModule(string $moduleId): bool | ||
{ | ||
$shopId = $this->context->getCurrentShopId(); | ||
|
||
try { | ||
$this->moduleActivationBridge->activate(moduleId: $moduleId, shopId: $shopId); | ||
} catch (\Exception $exception) { | ||
throw new ModuleActivationException(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function deactivateModule(string $moduleId): bool | ||
{ | ||
$shopId = $this->context->getCurrentShopId(); | ||
|
||
try { | ||
$this->moduleActivationBridge->deactivate(moduleId: $moduleId, shopId: $shopId); | ||
} catch (\Exception $exception) { | ||
throw new ModuleDeactivationException(); | ||
} | ||
|
||
return true; | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
namespace OxidEsales\GraphQL\ConfigurationAccess\Module\Service; | ||
|
||
use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleActivationException; | ||
use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleDeactivationException; | ||
|
||
interface ModuleActivationServiceInterface | ||
{ | ||
/** | ||
* @throws ModuleActivationException | ||
*/ | ||
public function activateModule(string $moduleId): bool; | ||
|
||
/** | ||
* @throws ModuleDeactivationException | ||
*/ | ||
public function deactivateModule(string $moduleId): bool; | ||
} |
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
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
59 changes: 59 additions & 0 deletions
59
tests/Codeception/Acceptance/Module/ModuleActivationCest.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,59 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\GraphQL\ConfigurationAccess\Tests\Codeception\Acceptance\Module; | ||
|
||
use Codeception\Attribute\DataProvider; | ||
use OxidEsales\GraphQL\ConfigurationAccess\Tests\Codeception\Acceptance\BaseCest; | ||
use OxidEsales\GraphQL\ConfigurationAccess\Tests\Codeception\AcceptanceTester; | ||
|
||
/** | ||
* @group module_activation | ||
* @group theme_switch | ||
* @group setting_access | ||
* @group oe_graphql_configuration_access | ||
*/ | ||
final class ModuleActivationCest extends BaseCest | ||
{ | ||
#[DataProvider('moduleDeActivationDataProvider')] | ||
public function testModuleActivationAuthorized(AcceptanceTester $I, \Codeception\Example $example): void | ||
{ | ||
$I->login($this->getAdminUsername(), $this->getAdminPassword()); | ||
|
||
$result = $this->runModuleMutation( | ||
I: $I, | ||
queryName: $example['queryName'], | ||
field: $example['field'] | ||
); | ||
|
||
$I->assertNotSame('You do not have sufficient rights to access this field', $result['errors'][0]['message']); | ||
} | ||
|
||
private function runModuleMutation( | ||
AcceptanceTester $I, | ||
string $queryName, | ||
string $field | ||
): array { | ||
$I->login($this->getAdminUsername(), $this->getAdminPassword()); | ||
$I->sendGQLQuery( | ||
'mutation { | ||
' . $queryName . '(' . $field . ': "' . self::TEST_MODULE_ID . '") | ||
}' | ||
); | ||
|
||
$I->seeResponseIsJson(); | ||
return $I->grabJsonResponseAsArray(); | ||
} | ||
|
||
protected function moduleDeActivationDataProvider(): \Generator | ||
{ | ||
yield ['queryName' => 'activateModule', 'field' => 'moduleId']; | ||
yield ['queryName' => 'deactivateModule', 'field' => 'moduleId']; | ||
} | ||
} |
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.