From d5ec492292ee0acaa53236c6e130e1718e76a204 Mon Sep 17 00:00:00 2001 From: Shaun Hare Date: Mon, 16 Dec 2024 13:30:22 +0000 Subject: [PATCH] fix: amend for testing --- .../module/Olcs/config/module.config.php | 2 +- .../ConsultantRegistrationController.php | 2 +- .../OperatorRegistrationControllerFactory.php | 5 +-- .../OperatorRegistrationController.php | 35 ++++++++----------- .../Controller/UserRegistrationController.php | 34 +++++++++++------- 5 files changed, 38 insertions(+), 40 deletions(-) diff --git a/app/selfserve/module/Olcs/config/module.config.php b/app/selfserve/module/Olcs/config/module.config.php index e43a6cfdbf..a2a23ac4b4 100644 --- a/app/selfserve/module/Olcs/config/module.config.php +++ b/app/selfserve/module/Olcs/config/module.config.php @@ -547,7 +547,7 @@ 'route' => 'operator-confirm[/]', 'defaults' => [ 'controller' => UserRegistrationController::class, - 'action' => 'operatorConfirm' + 'action' => 'add' ] ] ], diff --git a/app/selfserve/module/Olcs/src/Controller/ConsultantRegistrationController.php b/app/selfserve/module/Olcs/src/Controller/ConsultantRegistrationController.php index 9262715d3d..e272ae28c9 100644 --- a/app/selfserve/module/Olcs/src/Controller/ConsultantRegistrationController.php +++ b/app/selfserve/module/Olcs/src/Controller/ConsultantRegistrationController.php @@ -69,7 +69,7 @@ public function addAction() // no admin, move to operator representation but store licence number and admin state in session $this->consultantRegistrationSession->setExistingLicence($licenceNumber); $this->consultantRegistrationSession->setOperatorAdmin($checks['hasOperatorAdmin']); - $this->redirect()->toRoute('user-registration/operator'); + $this->redirect()->toRoute('user-registration/operator-confirm'); } else { $this->redirect()->toRoute('user-registration/contact-your-administrator'); } diff --git a/app/selfserve/module/Olcs/src/Controller/Factory/OperatorRegistrationControllerFactory.php b/app/selfserve/module/Olcs/src/Controller/Factory/OperatorRegistrationControllerFactory.php index ce08d7bebd..d909b6dfc1 100644 --- a/app/selfserve/module/Olcs/src/Controller/Factory/OperatorRegistrationControllerFactory.php +++ b/app/selfserve/module/Olcs/src/Controller/Factory/OperatorRegistrationControllerFactory.php @@ -12,7 +12,6 @@ use LmcRbacMvc\Service\AuthorizationService; use Olcs\Controller\Mapper\CreateAccountMapper; use Olcs\Controller\OperatorRegistrationController; -use Olcs\Session\ConsultantRegistration; use Psr\Container\ContainerInterface; class OperatorRegistrationControllerFactory implements FactoryInterface @@ -27,7 +26,6 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o $urlHelper = $container->get(UrlHelperService::class); $flashMessengerHelper = $container->get(FlashMessengerHelperService::class); $formatDataMapper = $container->get(CreateAccountMapper::class); - $consultantRegistrationSession = $container->get(ConsultantRegistration::class); return new OperatorRegistrationController( $niTextTranslationUtil, @@ -37,8 +35,7 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o $translationHelper, $urlHelper, $flashMessengerHelper, - $formatDataMapper, - $consultantRegistrationSession + $formatDataMapper ); } } diff --git a/app/selfserve/module/Olcs/src/Controller/OperatorRegistrationController.php b/app/selfserve/module/Olcs/src/Controller/OperatorRegistrationController.php index 12176ac614..be0d4c12d0 100644 --- a/app/selfserve/module/Olcs/src/Controller/OperatorRegistrationController.php +++ b/app/selfserve/module/Olcs/src/Controller/OperatorRegistrationController.php @@ -15,21 +15,20 @@ use LmcRbacMvc\Service\AuthorizationService; use Olcs\Controller\Mapper\CreateAccountMapper; use Olcs\Form\Model\Form\RegisterOperatorAccount; -use Olcs\Session\ConsultantRegistration; class OperatorRegistrationController extends AbstractController { public function __construct( - NiTextTranslation $niTextTranslationUtil, - AuthorizationService $authService, - protected FormHelperService $formHelper, - protected ScriptFactory $scriptFactory, - protected TranslationHelperService $translationHelper, - protected UrlHelperService $urlHelper, + NiTextTranslation $niTextTranslationUtil, + AuthorizationService $authService, + protected FormHelperService $formHelper, + protected ScriptFactory $scriptFactory, + protected TranslationHelperService $translationHelper, + protected UrlHelperService $urlHelper, protected FlashMessengerHelperService $flashMessengerHelper, - protected CreateAccountMapper $formatDataMapper, - protected ConsultantRegistration $consultantRegistrationSession - ) { + protected CreateAccountMapper $formatDataMapper + ) + { parent::__construct($niTextTranslationUtil, $authService); } @@ -41,22 +40,16 @@ public function addAction(): Response|ViewModel $form->setData($postData); if ($form->isValid()) { $formattedOperatorData = $this->formatDataMapper->formatSaveData($form->getData()); - if (!$this->consultantRegistrationSession->getOperatorAdmin()) { - $formattedOperatorData['licenceNumber'] = $this->consultantRegistrationSession->getExistingLicence(); - } - $response = $this->handleCommand( RegisterUserSelfserve::create($formattedOperatorData) ); if ($response->isOk()) { - if( !$this->consultantRegistrationSession->getOperatorAdmin()) { - return $this->redirect()->toRoute('user-registration/operator-confirm'); - } - return $this->prepareView('olcs/user-registration/check-email', [ - 'emailAddress' => $formattedOperatorData['contactDetails']['emailAddress'], - 'pageTitle' => 'user-registration.page.check-email.title' - ]); + + return $this->prepareView('olcs/user-registration/check-email', [ + 'emailAddress' => $formattedOperatorData['contactDetails']['emailAddress'], + 'pageTitle' => 'user-registration.page.check-email.title' + ]); } $this->flashMessengerHelper->addErrorMessage('There was an error registering your account. Please try again.'); diff --git a/app/selfserve/module/Olcs/src/Controller/UserRegistrationController.php b/app/selfserve/module/Olcs/src/Controller/UserRegistrationController.php index 0c4414636d..41d830e242 100644 --- a/app/selfserve/module/Olcs/src/Controller/UserRegistrationController.php +++ b/app/selfserve/module/Olcs/src/Controller/UserRegistrationController.php @@ -26,16 +26,17 @@ class UserRegistrationController extends AbstractController { public function __construct( - NiTextTranslation $niTextTranslationUtil, - AuthorizationService $authService, - protected FormHelperService $formHelper, - protected ScriptFactory $scriptFactory, - protected TranslationHelperService $translationHelper, - protected UrlHelperService $urlHelper, + NiTextTranslation $niTextTranslationUtil, + AuthorizationService $authService, + protected FormHelperService $formHelper, + protected ScriptFactory $scriptFactory, + protected TranslationHelperService $translationHelper, + protected UrlHelperService $urlHelper, protected FlashMessengerHelperService $flashMessengerHelper, - protected CreateAccountMapper $formatDataMapper, - protected ConsultantRegistration $consultantRegistrationSession - ) { + protected CreateAccountMapper $formatDataMapper, + protected ConsultantRegistration $consultantRegistrationSession + ) + { parent::__construct($niTextTranslationUtil, $authService); } @@ -46,11 +47,11 @@ public function __construct( */ public function startAction() { - if($this->handleQuery( + if ($this->handleQuery( IsEnabledQry::create(['ids' => [FeatureToggle::TRANSPORT_CONSULTANT_ROLE]]) )->getResult()['isEnabled']) { // If the feature toggle is enabled, start the TC journey in new controller - return $this->forward()->dispatch(ConsultantRegistrationController::class, ['action' => 'add', 'params' => $this->params()->fromQuery()]); + return $this->forward()->dispatch(ConsultantRegistrationController::class, ['action' => 'add', 'params' => $this->params()->fromQuery()]); } else { // If disabled, start the normal add journey in this controller return $this->forward()->dispatch(static::class, ['action' => 'add']); @@ -58,7 +59,6 @@ public function startAction() } - /** * Method used for the registration form page * @@ -120,6 +120,11 @@ protected function alterForm(Form $form) $termsAgreed->setLabel($label); + if ($this->consultantRegistrationSession->getOperatorAdmin() === false) { + $form->get('fields')->get('licenceNumber')->setValue($this->consultantRegistrationSession->getExistingLicence())->setAttribute('type', 'hidden'); + $form->get('fields')->get('isLicenceHolder')->setValue('Y')->setAttribute('type', 'hidden'); + $form->get('fields')->get('isLicenceHolder')->setLabel(''); + } return $form; } @@ -127,7 +132,7 @@ protected function alterForm(Form $form) * Generate content for user registration * * @param array $formData Form data - * @param array $errors Errors from ZF Validation Chain + * @param array $errors Errors from ZF Validation Chain * * @return ViewModel */ @@ -161,6 +166,7 @@ private function generateContentForUserRegistration(array $formData = [], array return $view; } + public function operatorConfirmAction(): ViewModel { $existingLicence = $this->consultantRegistrationSession->getExistingLicence(); @@ -171,6 +177,7 @@ public function operatorConfirmAction(): ViewModel ] ]); } + /** * Process user registration form data * @@ -248,6 +255,7 @@ private function showLicence($formData) ]; } + return $this->generateContentForUserRegistration($formData, $errors); }