Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add/manage user TC role hidden when TC toggle disabled #393

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/selfserve/module/Olcs/src/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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')
Expand Down
14 changes: 14 additions & 0 deletions app/selfserve/test/Olcs/src/Controller/UserControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -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'));
Expand Down