diff --git a/app/selfserve/module/Olcs/src/Controller/UserController.php b/app/selfserve/module/Olcs/src/Controller/UserController.php index 673b8eaf13..59cc6e7745 100644 --- a/app/selfserve/module/Olcs/src/Controller/UserController.php +++ b/app/selfserve/module/Olcs/src/Controller/UserController.php @@ -4,6 +4,7 @@ use Common\Controller\Lva\AbstractController; use Common\Controller\Lva\Traits\CrudTableTrait; +use Common\FeatureToggle; use Common\Form\Form; use Common\Service\Helper\FlashMessengerHelperService; use Common\Service\Helper\FormHelperService; @@ -13,6 +14,7 @@ use Dvsa\Olcs\Transfer\Command\User\CreateUserSelfserve as CreateDto; use Dvsa\Olcs\Transfer\Command\User\DeleteUserSelfserve as DeleteDto; use Dvsa\Olcs\Transfer\Command\User\UpdateUserSelfserve as UpdateDto; +use Dvsa\Olcs\Transfer\Query\FeatureToggle\IsEnabled as IsEnabledQry; use Dvsa\Olcs\Transfer\Query\User\UserListSelfserve as ListDto; use Dvsa\Olcs\Transfer\Query\User\UserSelfserve as ItemDto; use Dvsa\Olcs\Utils\Translation\NiTextTranslation; @@ -196,6 +198,13 @@ protected function save() */ public function alterForm($form, $data) { + // Hide TC option when feature toggle is disabled + if (!$this->handleQuery(IsEnabledQry::create(['ids' => [FeatureToggle::TRANSPORT_CONSULTANT_ROLE]]))->getResult()['isEnabled']) { + $form->get('main') + ->get('permission') + ->unsetValueOption('tc'); + } + if (!isset($data['main']['currentPermission']) || ($data['main']['currentPermission'] !== 'tm')) { // the option should only be available if editing already TM user $form->get('main') diff --git a/app/selfserve/test/Olcs/src/Controller/UserControllerTest.php b/app/selfserve/test/Olcs/src/Controller/UserControllerTest.php index 81f08f45c2..1123b0b877 100644 --- a/app/selfserve/test/Olcs/src/Controller/UserControllerTest.php +++ b/app/selfserve/test/Olcs/src/Controller/UserControllerTest.php @@ -5,6 +5,7 @@ namespace OlcsTest\Controller; use Common\Form\Form; +use Common\Service\Cqrs\Response; use Common\Service\Helper\FlashMessengerHelperService; use Common\Service\Helper\FormHelperService; use Common\Service\Helper\GuidanceHelperService; @@ -243,6 +244,12 @@ public function testSaveExistingRecord(): void $this->mockFormHelper ->shouldReceive('createFormWithRequest')->with('User', $this->mockRequest)->andReturn($this->mockForm); + $mockIsEnabledResponse = m::mock(Response::class); + $mockIsEnabledResponse->shouldReceive('getResult')->andReturn([ + 'isEnabled' => true, + ]); + $this->sut->shouldReceive('handleQuery')->with(m::type(TransferQry\FeatureToggle\IsEnabled::class))->andReturn($mockIsEnabledResponse); + $view = $this->sut->editAction(); $this->assertInstanceOf(Form::class, $view->getVariable('form')); @@ -433,6 +440,13 @@ public function testSaveExistingRecordLocksNameFields(): void ->with($this->mockForm, 'main->loginId') ->once(); + $mockIsEnabledResponse = m::mock(Response::class); + $mockIsEnabledResponse->shouldReceive('getResult')->andReturn([ + 'isEnabled' => true, + ]); + $this->sut->shouldReceive('handleQuery')->with(m::type(TransferQry\FeatureToggle\IsEnabled::class))->andReturn($mockIsEnabledResponse); + + $view = $this->sut->editAction(); $this->assertInstanceOf(Form::class, $view->getVariable('form'));