-
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.
feat: VOL-5664 welcome page now appears for external users to agree t…
…erms and conditions
- Loading branch information
Showing
21 changed files
with
455 additions
and
16 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
46 changes: 46 additions & 0 deletions
46
app/api/module/Api/src/Domain/CommandHandler/User/AgreeTerms.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,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dvsa\Olcs\Api\Domain\CommandHandler\User; | ||
|
||
use Dvsa\Olcs\Api\Domain\AuthAwareInterface; | ||
use Dvsa\Olcs\Api\Domain\AuthAwareTrait; | ||
use Dvsa\Olcs\Api\Domain\CacheAwareInterface; | ||
use Dvsa\Olcs\Api\Domain\CacheAwareTrait; | ||
use Dvsa\Olcs\Api\Domain\CommandHandler\AbstractCommandHandler; | ||
use Dvsa\Olcs\Api\Domain\Repository\User as UserRepository; | ||
use Dvsa\Olcs\Api\Entity\User\User; | ||
use Dvsa\Olcs\Transfer\Command\CommandInterface; | ||
|
||
final class AgreeTerms extends AbstractCommandHandler implements AuthAwareInterface, CacheAwareInterface | ||
{ | ||
use AuthAwareTrait; | ||
use CacheAwareTrait; | ||
|
||
public const SUCCESS_MSG = 'Terms and conditions accepted'; | ||
|
||
protected $repoServiceName = 'User'; | ||
|
||
public function handleCommand(CommandInterface $command) | ||
{ | ||
$userId = $this->getCurrentUser()->getId(); | ||
|
||
/** | ||
* @var UserRepository $repo | ||
* @var User $user | ||
*/ | ||
$repo = $this->getRepo(); | ||
|
||
$user = $repo->fetchById($userId); | ||
$user->agreeTermsAndConditions(); | ||
$repo->save($user); | ||
|
||
$this->clearUserCaches([$userId]); | ||
|
||
$this->result->addId('User', $userId); | ||
$this->result->addMessage(self::SUCCESS_MSG); | ||
|
||
return $this->result; | ||
} | ||
} |
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
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
63 changes: 63 additions & 0 deletions
63
app/api/test/module/Api/src/Domain/CommandHandler/User/AgreeTermsTest.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,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dvsa\OlcsTest\Api\Domain\CommandHandler\User; | ||
|
||
use Dvsa\Olcs\Api\Domain\Repository\User as UserRepository; | ||
use Dvsa\Olcs\Api\Entity\User\User as UserEntity; | ||
use Dvsa\Olcs\Transfer\Command\User\AgreeTerms as Cmd; | ||
use Dvsa\Olcs\Transfer\Service\CacheEncryption; | ||
use Dvsa\OlcsTest\Api\Domain\CommandHandler\AbstractCommandHandlerTestCase; | ||
use Dvsa\Olcs\Api\Domain\CommandHandler\User\AgreeTerms; | ||
use LmcRbacMvc\Service\AuthorizationService; | ||
use Mockery as m; | ||
|
||
class AgreeTermsTest extends AbstractCommandHandlerTestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
$this->sut = new AgreeTerms(); | ||
$this->mockRepo('User', UserRepository::class); | ||
|
||
$this->mockedSmServices = [ | ||
AuthorizationService::class => m::mock(AuthorizationService::class), | ||
CacheEncryption::class => m::mock(CacheEncryption::class), | ||
]; | ||
|
||
parent::setUp(); | ||
} | ||
|
||
public function testHandleCommand() | ||
{ | ||
$userId = 999; | ||
|
||
$command = Cmd::create([]); | ||
|
||
$loggedInUser = m::mock(UserEntity::class); | ||
$loggedInUser->expects('getId')->andReturn($userId); | ||
|
||
$this->mockedSmServices[AuthorizationService::class]->expects('getIdentity->getUser') | ||
->andReturn($loggedInUser); | ||
|
||
$this->mockedSmServices[CacheEncryption::class]->expects('removeCustomItems') | ||
->with(CacheEncryption::USER_ACCOUNT_IDENTIFIER, [$userId]); | ||
|
||
$userFromRepo = m::mock(UserEntity::class); | ||
$userFromRepo->expects('agreeTermsAndConditions')->withNoArgs(); | ||
|
||
$this->repoMap['User']->expects('fetchById')->with($userId)->andReturn($userFromRepo); | ||
$this->repoMap['User']->expects('save')->with($userFromRepo); | ||
|
||
$expectedResult = [ | ||
'id' => [ | ||
'User' => $userId, | ||
], | ||
'messages' => [ | ||
0 => AgreeTerms::SUCCESS_MSG | ||
], | ||
]; | ||
|
||
$this->assertEquals($expectedResult, $this->sut->handleCommand($command)->toArray()); | ||
} | ||
} |
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
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
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
app/selfserve/module/Olcs/src/Controller/WelcomeController.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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Olcs\Controller; | ||
|
||
use Common\Service\Helper\FormHelperService; | ||
use Common\Service\Helper\TranslationHelperService; | ||
use Common\Service\Table\TableFactory; | ||
use Dvsa\Olcs\Transfer\Command\User\AgreeTerms as AgreeTermsCmd; | ||
use Laminas\Http\Response; | ||
use Olcs\Form\Model\Form\AgreeTerms as AgreeTermsForm; | ||
use Permits\Data\Mapper\MapperManager; | ||
|
||
class WelcomeController extends AbstractSelfserveController | ||
{ | ||
protected $templateConfig = [ | ||
'generic' => 'pages/welcome', | ||
]; | ||
|
||
protected $formConfig = [ | ||
'generic' => [ | ||
'confirmationForm' => [ | ||
'formClass' => AgreeTermsForm::class | ||
] | ||
] | ||
]; | ||
|
||
protected $postConfig = [ | ||
'generic' => [ | ||
'command' => AgreeTermsCmd::class, | ||
'step' => 'index', | ||
'saveAndReturnStep' => 'index', | ||
], | ||
]; | ||
|
||
public function __construct( | ||
TranslationHelperService $translationHelper, | ||
FormHelperService $formHelper, | ||
TableFactory $tableBuilder, | ||
MapperManager $mapperManager | ||
) { | ||
parent::__construct($translationHelper, $formHelper, $tableBuilder, $mapperManager); | ||
} | ||
|
||
/** | ||
* @return Response|void | ||
*/ | ||
public function checkConditionalDisplay() | ||
{ | ||
if (isset($this->postParams['form-actions']['signOut'])) { | ||
return $this->conditionalDisplayNotMet('auth/logout'); | ||
} | ||
|
||
if ($this->currentUser()->getUserData()['termsAgreed'] === true) { | ||
return $this->conditionalDisplayNotMet('index'); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/selfserve/module/Olcs/src/Controller/WelcomeControllerFactory.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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Olcs\Controller; | ||
|
||
use Common\Service\Helper\FormHelperService; | ||
use Common\Service\Helper\TranslationHelperService; | ||
use Common\Service\Table\TableFactory; | ||
use Psr\Container\ContainerInterface; | ||
use Laminas\ServiceManager\Factory\FactoryInterface; | ||
use Permits\Data\Mapper\MapperManager; | ||
|
||
class WelcomeControllerFactory implements FactoryInterface | ||
{ | ||
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): WelcomeController | ||
{ | ||
$translationHelper = $container->get(TranslationHelperService::class); | ||
$formHelper = $container->get(FormHelperService::class); | ||
$tableBuilder = $container->get(TableFactory::class); | ||
$mapperManager = $container->get(MapperManager::class); | ||
return new WelcomeController($translationHelper, $formHelper, $tableBuilder, $mapperManager); | ||
} | ||
} |
Oops, something went wrong.