Skip to content

Commit

Permalink
feat: VOL-5239 create transport consultant reg journey
Browse files Browse the repository at this point in the history
feat: add signup journey catering for consultants
  • Loading branch information
ilindsay authored and fibble committed Aug 23, 2024
1 parent 5208e68 commit 5e377ff
Show file tree
Hide file tree
Showing 26 changed files with 973 additions and 34 deletions.
1 change: 1 addition & 0 deletions app/api/module/Api/config/command-map.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@
TransferCommand\User\UpdatePartner::class => CommandHandler\User\UpdatePartner::class,
TransferCommand\User\DeletePartner::class => CommandHandler\User\DeletePartner::class,
TransferCommand\User\UpdateUserLastLoginAt::class => CommandHandler\User\UpdateUserLastLoginAt::class,
TransferCommand\User\RegisterConsultantAndOperator::class => CommandHandler\User\RegisterConsultantAndOperator::class,

// Transfer - Team
TransferCommand\Team\CreateTeam::class => CommandHandler\Team\CreateTeam::class,
Expand Down
1 change: 1 addition & 0 deletions app/api/module/Api/config/validation-map/user.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
CommandHandler\User\RegisterUserSelfserve::class => NoValidationRequired::class,
CommandHandler\User\RegisterUserSelfserveFactory::class => NoValidationRequired::class,
CommandHandler\User\RemindUsernameSelfserve::class => NoValidationRequired::class,
CommandHandler\User\RegisterConsultantAndOperator::class => NoValidationRequired::class,
CommandHandler\User\UpdatePartner::class => IsInternalUser::class,
CommandHandler\User\CreateUserSelfserve::class => CanManageUser::class,
CommandHandler\User\CreateUserSelfServeFactory::class => CanManageUser::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
namespace Dvsa\Olcs\Api\Domain\CommandHandler\Email;

use Dvsa\Olcs\Api\Domain\Command\Result;
use Dvsa\Olcs\Api\Domain\ToggleAwareInterface;
use Dvsa\Olcs\Api\Domain\ToggleAwareTrait;
use Dvsa\Olcs\Api\Entity\System\FeatureToggle;
use Dvsa\Olcs\Transfer\Command\CommandInterface;
use Dvsa\Olcs\Api\Domain\CommandHandler\AbstractCommandHandler;

/**
* Send User Registered Email
*/
final class SendUserRegistered extends AbstractCommandHandler implements \Dvsa\Olcs\Api\Domain\EmailAwareInterface
final class SendUserRegistered extends AbstractCommandHandler implements \Dvsa\Olcs\Api\Domain\EmailAwareInterface, ToggleAwareInterface
{
use \Dvsa\Olcs\Api\Domain\EmailAwareTrait;
use ToggleAwareTrait;

protected $repoServiceName = 'User';

Expand All @@ -35,9 +39,13 @@ public function handleCommand(CommandInterface $command)

$message->setTranslateToWelsh($user->getTranslateToWelsh());

$template = $this->toggleService->isEnabled(
FeatureToggle::TRANSPORT_CONSULTANT_ROLE)
? 'user-registered-tc' : 'user-registered';

$this->sendEmailTemplate(
$message,
'user-registered',
$template,
[
'orgName' => $user->getRelatedOrganisationName(),
'loginId' => $user->getLoginId(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* Register Operator and Consultant
*/

namespace Dvsa\Olcs\Api\Domain\CommandHandler\User;

use Dvsa\Olcs\Api\Domain\CommandHandler\AbstractUserCommandHandler;
use Dvsa\Olcs\Api\Domain\CommandHandler\TransactionedInterface;
use Dvsa\Olcs\Transfer\Command\CommandInterface;
use Dvsa\Olcs\Transfer\Command\User\RegisterUserSelfserve as RegisterUserSelfServeCommand;

final class RegisterConsultantAndOperator extends AbstractUserCommandHandler implements TransactionedInterface
{
protected $repoServiceName = 'User';

public function handleCommand(CommandInterface $command)
{
// Register the operator first, a new Org will be created.
$this->result->merge($this->handleSideEffect(RegisterUserSelfServeCommand::create($command->getOperatorDetails())));

// Get the newly created user entity
$user = $this->getRepo()->fetchById($this->result->getId('user'));

// Add the org ID of the newly created user/org to the consultant details, then register the consultant
$consultantDetails = $command->getConsultantDetails();
$consultantDetails['organisation'] = $user->getOrganisationUsers()->first()->getOrganisation()->getId();

$this->result->merge($this->handleSideEffect(RegisterUserSelfServeCommand::create($consultantDetails)));

return $this->result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public function handleCommand(CommandInterface $command)
} elseif (!empty($data['organisationName'])) {
// create organisation and link with it
$data['organisations'] = [$this->createOrganisation($data)];
} elseif (!empty($data['organisation'])) {
// link with the organisation
$data['organisations'] = [$this->getRepo('Organisation')->fetchById($data['organisation'])];
}

if (empty($data['organisations'])) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<p>Hello,</p>

<p>You've been added to the Vehicle Operator Licensing service for <?php echo $this->escapeHtml($this->orgName); ?>.</p>

<p>Your username is: <?php echo $this->escapeHtml($this->loginId); ?></p>

<p>You'll receive a second email with a temporary password in the next two hours. If it doesn't arrive email notification@vehicle-operator-licensing.service.gov.uk</p>

<p>
<a href="<?php echo $this->escapeHtml($this->url); ?>">Sign in</a>
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Hello,

You've been added to the Vehicle Operator Licensing service for <?php echo $this->orgName; ?>.

Your username is: <?php echo $this->loginId; ?></p>

You'll receive a second email with a temporary password in the next two hours. If it doesn't arrive email notification@vehicle-operator-licensing.service.gov.uk

Sign in at <?php echo $this->url; ?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Dvsa\OlcsTest\Api\Domain\CommandHandler\User;

use Dvsa\Olcs\Api\Domain\CommandHandler\User\RegisterConsultantAndOperator;
use Dvsa\Olcs\Api\Domain\Repository\User as UserRepo;
use Dvsa\Olcs\Api\Entity\User\User as UserEntity;
use Dvsa\Olcs\Transfer\Command\User\RegisterConsultantAndOperator as RegisterConsultantAndOperatorCommand;
use Dvsa\Olcs\Transfer\Command\User\RegisterUserSelfserve as RegisterUserSelfServeCommand;
use Dvsa\OlcsTest\Api\Domain\CommandHandler\AbstractCommandHandlerTestCase;
use Dvsa\Olcs\Api\Domain\Command\Result;
use Mockery as m;

class RegisterConsultantAndOperatorTest extends AbstractCommandHandlerTestCase
{
public function setUp(): void
{
$this->sut = new RegisterConsultantAndOperator();
$this->mockRepo('User', UserRepo::class);

$mockAuthService = m::mock(\LmcRbacMvc\Service\AuthorizationService::class);
$this->mockedSmServices['LmcRbacMvc\Service\AuthorizationService'] = $mockAuthService;

parent::setUp();
}

public function testHandleCommand()
{
$operatorDetails = ['organisationName' => 'Operator Org',];

$command = RegisterConsultantAndOperatorCommand::create(
[
'operatorDetails' => $operatorDetails,
'consultantDetails' => []
]);

$operatorResult = new Result();
$operatorResult->addId('user', 100)->addMessage('User created successfully');

$this->expectedSideEffect(
RegisterUserSelfServeCommand::class,
$operatorDetails,
$operatorResult
);

$organisationId = 200;
$organisation = m::mock();
$organisation->shouldReceive('getId')->andReturn($organisationId);

$organisationUser = m::mock();
$organisationUser->shouldReceive('getOrganisation')->andReturn($organisation);

$user = m::mock(UserEntity::class)->makePartial();
$user->shouldReceive('getOrganisationUsers->first')->andReturn($organisationUser);

$this->repoMap['User']->shouldReceive('fetchById')->with(100)->andReturn($user);

$consultantDetails['organisation'] = $organisationId;

$consultantResult = new Result();
$consultantResult->addId('user', 101)->addMessage('User created successfully');

$this->expectedSideEffect(
RegisterUserSelfServeCommand::class,
$consultantDetails,
$consultantResult
);

$result = $this->sut->handleCommand($command);
$this->assertEquals(['User created successfully', 'User created successfully'], $result->getMessages());
}
}
58 changes: 54 additions & 4 deletions app/selfserve/module/Olcs/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,50 @@
'route' => '/register[/]',
'defaults' => [
'controller' => UserRegistrationController::class,
'action' => 'add'
'action' => 'start'
]
],
'may_terminate' => true,
'child_routes' => [
'operator' => [
'type' => 'segment',
'options' => [
'route' => 'operator[/]',
'defaults' => [
'controller' => UserRegistrationController::class,
'action' => 'add'
]
]
],
'operator-representation' => [
'type' => 'segment',
'options' => [
'route' => 'operator-representation[/]',
'defaults' => [
'controller' => UserRegistrationController::class,
'action' => 'operatorRepresentation'
]
]
],
'register-for-operator' => [
'type' => 'segment',
'options' => [
'route' => 'register-for-operator[/]',
'defaults' => [
'controller' => UserRegistrationController::class,
'action' => 'registerForOperator'
]
]
],
'register-consultant-account' => [
'type' => 'segment',
'options' => [
'route' => 'register-consultant-account[/]',
'defaults' => [
'controller' => UserRegistrationController::class,
'action' => 'registerConsultantAccount'
]
]
]
]
],
Expand Down Expand Up @@ -1434,7 +1477,9 @@
'CookieSettingsCookieNamesProvider' => CookieService\SettingsCookieNamesProvider::class,
'QaIrhpApplicationViewGenerator' => QaService\ViewGenerator\IrhpApplicationViewGenerator::class,
'QaIrhpPermitApplicationViewGenerator' => QaService\ViewGenerator\IrhpPermitApplicationViewGenerator::class,
LicenceVehicleManagement::class => LicenceVehicleManagement::class
LicenceVehicleManagement::class => LicenceVehicleManagement::class,
\Olcs\Session\ConsultantRegistration::class => \Olcs\Session\ConsultantRegistration::class,

],
'abstract_factories' => [
\Laminas\Cache\Service\StorageCacheAbstractServiceFactory::class,
Expand Down Expand Up @@ -1668,7 +1713,7 @@
'verify/process-response' => ['*'],
'search*' => ['*'],
'index' => ['*'],
'user-registration' => ['*'],
'user-registration*' => ['*'],
'user-forgot-username' => ['*'],
'cookies*' => ['*'],
'privacy-notice' => ['*'],
Expand Down Expand Up @@ -1701,5 +1746,10 @@
'options_default_plus_cancel' => \Permits\Form\Model\Fieldset\SubmitOrCancelApplication::class,
'options_bilateral' => \Permits\Form\Model\Fieldset\SubmitOnly::class,
]
]
],
'validators' => [
'factories' => [
\Olcs\Form\Validator\UniqueConsultantDetails::class => \Olcs\Form\Validator\Factory\UniqueConsultantDetailsFactory::class,
],
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Common\Service\Helper\UrlHelperService;
use Common\Service\Script\ScriptFactory;
use Dvsa\Olcs\Utils\Translation\NiTextTranslation;
use Olcs\Session\ConsultantRegistration;
use Psr\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Olcs\Controller\UserRegistrationController;
Expand All @@ -30,6 +31,7 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
$translationHelper = $container->get(TranslationHelperService::class);
$urlHelper = $container->get(UrlHelperService::class);
$flashMessengerHelper = $container->get(FlashMessengerHelperService::class);
$consultantRegistrationSession = $container->get(ConsultantRegistration::class);

return new UserRegistrationController(
$niTextTranslationUtil,
Expand All @@ -38,7 +40,8 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
$scriptFactory,
$translationHelper,
$urlHelper,
$flashMessengerHelper
$flashMessengerHelper,
$consultantRegistrationSession
);
}
}
Loading

0 comments on commit 5e377ff

Please sign in to comment.