diff --git a/api/app/tests/Behat/bootstrap/v2/Common/AuthTrait.php b/api/app/tests/Behat/bootstrap/v2/Common/AuthTrait.php index a3670e0603..3d8c6a32f4 100644 --- a/api/app/tests/Behat/bootstrap/v2/Common/AuthTrait.php +++ b/api/app/tests/Behat/bootstrap/v2/Common/AuthTrait.php @@ -552,4 +552,20 @@ private function getActiveClientIds(): void } } } + + /** + * @Then I should see the NDR report on the reports page + */ + public function theyShouldBeOnNDRReportPage(): void + { + $this->assertPageContainsText('New deputy report'); + } + + /** + * @Then I should not see the NDR report on the reports page + */ + public function theyShouldNotBeOnNDRReportPage(): void + { + $this->assertPageNotContainsText('New deputy report'); + } } diff --git a/api/app/tests/Behat/bootstrap/v2/Common/IShouldBeOnFrontendTrait.php b/api/app/tests/Behat/bootstrap/v2/Common/IShouldBeOnFrontendTrait.php index 0f0126f658..39bed2feba 100644 --- a/api/app/tests/Behat/bootstrap/v2/Common/IShouldBeOnFrontendTrait.php +++ b/api/app/tests/Behat/bootstrap/v2/Common/IShouldBeOnFrontendTrait.php @@ -148,14 +148,6 @@ public function iAmOnLayMainPage(): bool return $this->iAmOnPage('/client\/.*/'); } - /** - * @Then I should be on the Ndr Lay homepage - */ - public function iAmOnNdrLayMainPage(): bool - { - return $this->iAmOnPage('/ndr$/'); - } - /** * @Then I should be on the Lay reports overview page */ diff --git a/api/app/tests/Behat/bootstrap/v2/Common/UserExistsTrait.php b/api/app/tests/Behat/bootstrap/v2/Common/UserExistsTrait.php index d9c9859e81..4d7208e0c3 100644 --- a/api/app/tests/Behat/bootstrap/v2/Common/UserExistsTrait.php +++ b/api/app/tests/Behat/bootstrap/v2/Common/UserExistsTrait.php @@ -59,4 +59,32 @@ public function aProfessionalTeamDeputyExists() $this->interactingWithUserDetails = $this->profTeamDeputyNotStartedHealthWelfareDetails; } + + /** + * @Given a Multi-client Lay Deputy exists and I select the non-primary user + * + * @throws BehatException + */ + public function aMultiClientLayDeputyExists() + { + if (empty($this->layPfaHighNotStartedMultiClientDeputyNonPrimaryUser)) { + throw new BehatException('It looks like fixtures are not loaded - missing $layPfaHighNotStartedMultiClientDeputyNonPrimaryUser'); + } + + $this->interactingWithUserDetails = $this->layPfaHighNotStartedMultiClientDeputyNonPrimaryUser; + } + + /** + * @Given a Multi-client Lay Deputy exists and I select the primary user with NDR + * + * @throws BehatException + */ + public function aMultiClientLayDeputyExistsWithNDR() + { + if (empty($this->layPfaHighNotStartedMultiClientDeputyPrimaryUser)) { + throw new BehatException('It looks like fixtures are not loaded - missing $layPfaHighNotStartedMultiClientDeputyPrimaryUser'); + } + + $this->interactingWithUserDetails = $this->layPfaHighNotStartedMultiClientDeputyPrimaryUser; + } } diff --git a/api/app/tests/Behat/bootstrap/v2/DeputyManagement/DeputyManagementTrait.php b/api/app/tests/Behat/bootstrap/v2/DeputyManagement/DeputyManagementTrait.php index c6dddec76c..c8dc50ee98 100644 --- a/api/app/tests/Behat/bootstrap/v2/DeputyManagement/DeputyManagementTrait.php +++ b/api/app/tests/Behat/bootstrap/v2/DeputyManagement/DeputyManagementTrait.php @@ -189,4 +189,30 @@ public function iShouldNotBeAbleToAccessClientDetailsLink() { $this->assertElementNotOnPage('govuk-link behat-link-client-show'); } + + /** + * @Then /^I enable the NDR for this user$/ + */ + public function iShouldBeAbleToToggleNdrEnabled() + { + $this->iVisitAdminEditUserPageForInteractingWithUser(); + + $this->checkOption('admin_ndrEnabled'); + + $this->pressButton('Update user'); + $this->em->clear(); + } + + /** + * @Then /^I disable the NDR for this user$/ + */ + public function iShouldBeDisableNdrEnabled() + { + $this->iVisitAdminEditUserPageForInteractingWithUser(); + + $this->uncheckOption('admin_ndrEnabled'); + + $this->pressButton('Update user'); + $this->em->clear(); + } } diff --git a/api/app/tests/Behat/bootstrap/v2/Helpers/FixtureHelper.php b/api/app/tests/Behat/bootstrap/v2/Helpers/FixtureHelper.php index cd42444d67..c817dcca74 100644 --- a/api/app/tests/Behat/bootstrap/v2/Helpers/FixtureHelper.php +++ b/api/app/tests/Behat/bootstrap/v2/Helpers/FixtureHelper.php @@ -934,7 +934,7 @@ public function createLayNdrNotStarted(string $testRunId, ?string $caseNumber = null, $caseNumber, true, - false, + true, $deputyUid ); diff --git a/api/app/tests/Behat/features-v2/acl/login/login.feature b/api/app/tests/Behat/features-v2/acl/login/login.feature index a5a975e125..005101b944 100644 --- a/api/app/tests/Behat/features-v2/acl/login/login.feature +++ b/api/app/tests/Behat/features-v2/acl/login/login.feature @@ -126,3 +126,23 @@ Feature: Users logging into the service And they discharge the deputy from "2" secondary client(s) Then a Lay Deputy tries to login with their "primary" email address Then they should be on the add your client page + + @super-admin @lay-pfa-high-not-started-multi-client-deputy + Scenario: A user logs into the service with their primary account and ticks the NDR checkbox attached to non-primary account + Given a super admin user accesses the admin app + When a Multi-client Lay Deputy exists and I select the non-primary user + And I enable the NDR for this user + Then a Lay Deputy tries to login with their "primary" email address + When they choose their "non-primary" Client + Then they should be on the "non-primary" Client's dashboard + And I should see the NDR report on the reports page + + @super-admin @lay-pfa-high-not-started-multi-client-deputy-with-ndr + Scenario: A user logs into the service with their primary account and unticks the NDR checkbox attached to primary account + Given a super admin user accesses the admin app + When a Multi-client Lay Deputy exists and I select the primary user with NDR + And I disable the NDR for this user + Then a Lay Deputy tries to login with their "primary" email address + When they choose their "primary" Client + Then they should be on the "primary" Client's dashboard + And I should not see the NDR report on the reports page diff --git a/api/app/tests/Behat/features-v2/registration/activate.ndr.feature b/api/app/tests/Behat/features-v2/registration/activate.ndr.feature index d6eb6bb7e6..680e9fd0ab 100644 --- a/api/app/tests/Behat/features-v2/registration/activate.ndr.feature +++ b/api/app/tests/Behat/features-v2/registration/activate.ndr.feature @@ -12,7 +12,7 @@ Feature: Activate user account - Lay users (NDR) Then the partially registered users 'active flag' should 'not be' set And the partially registered users 'registration date' should 'not be' set When the user completes the final registration step - Then I should be on the Ndr Lay homepage + Then I should be on the Lay homepage And an admin user accesses the admin app Then the partially registered users 'active flag' should 'be' set And the partially registered users 'registration date' should 'be' set diff --git a/client/app/src/Controller/ClientController.php b/client/app/src/Controller/ClientController.php index 33eb2bdc50..1941be2de0 100644 --- a/client/app/src/Controller/ClientController.php +++ b/client/app/src/Controller/ClientController.php @@ -65,7 +65,7 @@ public function showClientDetailsAction(Redirector $redirector, int $clientId) $client = $this->clientApi->getById($clientId); - $deputyHasMultiClients = $this->getUser()->isLayDeputy() && $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()); + $deputyHasMultiClients = $this->clientApi->checkDeputyHasMultiClients($user); return [ 'client' => $client, @@ -95,7 +95,7 @@ public function editAction(Request $request) public function editClientDetailsAction(Request $request, int $clientId) { $user = $this->userApi->getUserWithData(); - $deputyHasMultiClients = $this->getUser()->isLayDeputy() && $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()); + $deputyHasMultiClients = $this->clientApi->checkDeputyHasMultiClients($user); $from = $request->get('from'); $preUpdateClient = $this->clientApi->getById($clientId); @@ -193,7 +193,7 @@ public function addAction(Request $request, Redirector $redirector, TranslatorIn $this->clientApi->updateDeputy($response['id'], $deputyResponse['id']); $url = $currentUser->isNdrEnabled() - ? $this->generateUrl('ndr_index') + ? $this->generateUrl('lay_home', ['clientId' => $response['id']]) : $this->generateUrl('report_create', ['clientId' => $response['id']]); if ($currentUser->isNdrEnabled()) { diff --git a/client/app/src/Controller/CoDeputyController.php b/client/app/src/Controller/CoDeputyController.php index 7c0670af37..92fdbac53d 100644 --- a/client/app/src/Controller/CoDeputyController.php +++ b/client/app/src/Controller/CoDeputyController.php @@ -175,9 +175,7 @@ public function addAction(Request $request, Redirector $redirector) $invitedUser = new User(); $form = $this->createForm(FormDir\CoDeputyInviteType::class, $invitedUser); - $backLink = $loggedInUser->isNdrEnabled() ? - $this->generateUrl('ndr_index') - : $this->generateUrl('lay_home', ['clientId' => $loggedInUser->getFirstClient()->getId()]); + $backLink = $this->generateUrl('lay_home', ['clientId' => $loggedInUser->getFirstClient()->getId()]); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { @@ -229,9 +227,7 @@ public function resendActivationAction(Request $request, string $email) $form = $this->createForm(FormDir\CoDeputyInviteType::class, $existingCoDeputy); - $backLink = $loggedInUser->isNdrEnabled() ? - $this->generateUrl('ndr_index') - : $this->generateUrl('lay_home', ['clientId' => $loggedInUser->getFirstClient()->getId()]); + $backLink = $this->generateUrl('lay_home', ['clientId' => $loggedInUser->getFirstClient()->getId()]); $form->handleRequest($request); diff --git a/client/app/src/Controller/Ndr/ActionController.php b/client/app/src/Controller/Ndr/ActionController.php index 73a10865a9..6ba34b4082 100644 --- a/client/app/src/Controller/Ndr/ActionController.php +++ b/client/app/src/Controller/Ndr/ActionController.php @@ -3,7 +3,9 @@ namespace App\Controller\Ndr; use App\Controller\AbstractController; +use App\Entity\User; use App\Form as FormDir; +use App\Service\Client\Internal\ClientApi; use App\Service\Client\Internal\ReportApi; use App\Service\Client\RestClient; use App\Service\NdrStatusService; @@ -36,27 +38,36 @@ class ActionController extends AbstractController 'ndr-action-more-info', ]; + /** + * @var ClientApi + */ + private $clientApi; + public function __construct( ReportApi $reportApi, RestClient $restClient, - StepRedirector $stepRedirector + StepRedirector $stepRedirector, + ClientApi $clientApi ) { $this->reportApi = $reportApi; $this->restClient = $restClient; $this->stepRedirector = $stepRedirector; + $this->clientApi = $clientApi; } /** * @Route("/ndr/{ndrId}/actions", name="ndr_actions") - * @Template("@App/Ndr/Action/start.html.twig") * - * @param Request $request - * @param $ndrId + * @Template("@App/Ndr/Action/start.html.twig") * * @return array|RedirectResponse */ public function startAction($ndrId) { + /** @var User $user */ + $user = $this->getUser(); + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); + $ndr = $this->reportApi->getNdrIfNotSubmitted($ndrId, self::$jmsGroups); if (NdrStatusService::STATE_NOT_STARTED != $ndr->getStatusService()->getActionsState()['state']) { return $this->redirectToRoute('ndr_actions_summary', ['ndrId' => $ndrId]); @@ -64,11 +75,13 @@ public function startAction($ndrId) return [ 'ndr' => $ndr, + 'isMultiClientDeputy' => $isMultiClientDeputy, ]; } /** * @Route("/ndr/{ndrId}/actions/step/{step}", name="ndr_actions_step") + * * @Template("@App/Ndr/Action/step.html.twig") */ public function stepAction(Request $request, $ndrId, $step) @@ -115,6 +128,7 @@ public function stepAction(Request $request, $ndrId, $step) /** * @Route("/ndr/{ndrId}/actions/summary", name="ndr_actions_summary") + * * @Template("@App/Ndr/Action/summary.html.twig") */ public function summaryAction(Request $request, $ndrId) diff --git a/client/app/src/Controller/Ndr/AssetController.php b/client/app/src/Controller/Ndr/AssetController.php index 770ec89e19..71c28de82f 100644 --- a/client/app/src/Controller/Ndr/AssetController.php +++ b/client/app/src/Controller/Ndr/AssetController.php @@ -4,7 +4,9 @@ use App\Controller\AbstractController; use App\Entity as EntityDir; +use App\Entity\User; use App\Form as FormDir; +use App\Service\Client\Internal\ClientApi; use App\Service\Client\Internal\ReportApi; use App\Service\Client\RestClient; use App\Service\NdrStatusService; @@ -33,26 +35,36 @@ class AssetController extends AbstractController */ private $stepRedirector; + /** + * @var ClientApi + */ + private $clientApi; + public function __construct( ReportApi $reportApi, RestClient $restClient, - StepRedirector $stepRedirector + StepRedirector $stepRedirector, + ClientApi $clientApi ) { $this->reportApi = $reportApi; $this->restClient = $restClient; $this->stepRedirector = $stepRedirector; + $this->clientApi = $clientApi; } /** * @Route("/ndr/{ndrId}/assets", name="ndr_assets") - * @Template("@App/Ndr/Asset/start.html.twig") * - * @param $ndrId + * @Template("@App/Ndr/Asset/start.html.twig") * * @return array|RedirectResponse */ public function startAction($ndrId) { + /** @var User $user */ + $user = $this->getUser(); + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); + $ndr = $this->reportApi->getNdrIfNotSubmitted($ndrId, self::$jmsGroups); if (NdrStatusService::STATE_NOT_STARTED != $ndr->getStatusService()->getAssetsState()['state']) { return $this->redirectToRoute('ndr_assets_summary', ['ndrId' => $ndrId]); @@ -60,11 +72,13 @@ public function startAction($ndrId) return [ 'ndr' => $ndr, + 'isMultiClientDeputy' => $isMultiClientDeputy, ]; } /** * @Route("/ndr/{ndrId}/assets/exist", name="ndr_assets_exist") + * * @Template("@App/Ndr/Asset/exist.html.twig") */ public function existAction(Request $request, $ndrId) @@ -85,7 +99,7 @@ public function existAction(Request $request, $ndrId) switch ($ndr->getNoAssetToAdd()) { case 0: // yes return $this->redirectToRoute('ndr_assets_type', ['ndrId' => $ndrId]); - case 1: //no + case 1: // no $this->restClient->put('ndr/'.$ndrId, $ndr, ['noAssetsToAdd']); return $this->redirectToRoute('ndr_assets_summary', ['ndrId' => $ndrId]); @@ -106,6 +120,7 @@ public function existAction(Request $request, $ndrId) /** * @Route("/ndr/{ndrId}/assets/step-type", name="ndr_assets_type") + * * @Template("@App/Ndr/Asset/type.html.twig") */ public function typeAction(Request $request, $ndrId) @@ -135,6 +150,7 @@ public function typeAction(Request $request, $ndrId) /** * @Route("/ndr/{ndrId}/assets/other/{title}/add", name="ndr_asset_other_add") + * * @Template("@App/Ndr/Asset/Other/add.html.twig") */ public function otherAddAction(Request $request, $ndrId, $title) @@ -166,6 +182,7 @@ public function otherAddAction(Request $request, $ndrId, $title) /** * @Route("/ndr/{ndrId}/assets/other/edit/{assetId}", name="ndr_asset_other_edit") + * * @Template("@App/Ndr/Asset/Other/edit.html.twig") */ public function otherEditAction(Request $request, $ndrId, $assetId = null) @@ -199,6 +216,7 @@ public function otherEditAction(Request $request, $ndrId, $assetId = null) /** * @Route("/ndr/{ndrId}/assets/add_another", name="ndr_assets_add_another") + * * @Template("@App/Ndr/Asset/addAnother.html.twig") */ public function addAnotherAction(Request $request, $ndrId) @@ -225,6 +243,7 @@ public function addAnotherAction(Request $request, $ndrId) /** * @Route("/ndr/{ndrId}/assets/property/step{step}/{assetId}", name="ndr_assets_property_step", requirements={"step":"\d+"}) + * * @Template("@App/Ndr/Asset/Property/step.html.twig") */ public function propertyStepAction(Request $request, $ndrId, $step, $assetId = null) @@ -346,9 +365,8 @@ public function propertyStepAction(Request $request, $ndrId, $step, $assetId = n /** * @Route("/ndr/{ndrId}/assets/summary", name="ndr_assets_summary") - * @Template("@App/Ndr/Asset/summary.html.twig") * - * @param $ndrId + * @Template("@App/Ndr/Asset/summary.html.twig") * * @return array|RedirectResponse */ @@ -366,6 +384,7 @@ public function summaryAction($ndrId) /** * @Route("/ndr/{ndrId}/assets/{assetId}/delete", name="ndr_asset_delete") + * * @Template("@App/Common/confirmDelete.html.twig") * * @return array|RedirectResponse diff --git a/client/app/src/Controller/Ndr/BankAccountController.php b/client/app/src/Controller/Ndr/BankAccountController.php index ff64e74307..d72aac84eb 100644 --- a/client/app/src/Controller/Ndr/BankAccountController.php +++ b/client/app/src/Controller/Ndr/BankAccountController.php @@ -4,7 +4,9 @@ use App\Controller\AbstractController; use App\Entity as EntityDir; +use App\Entity\User; use App\Form as FormDir; +use App\Service\Client\Internal\ClientApi; use App\Service\Client\Internal\ReportApi; use App\Service\Client\RestClient; use App\Service\NdrStatusService; @@ -32,27 +34,33 @@ class BankAccountController extends AbstractController * @var StepRedirector */ private $stepRedirector; + private $clientApi; public function __construct( ReportApi $reportApi, RestClient $restClient, - StepRedirector $stepRedirector + StepRedirector $stepRedirector, + ClientApi $clientApi ) { $this->reportApi = $reportApi; $this->restClient = $restClient; $this->stepRedirector = $stepRedirector; + $this->clientApi = $clientApi; } /** * @Route("/ndr/{ndrId}/bank-accounts", name="ndr_bank_accounts") - * @Template("@App/Ndr/BankAccount/start.html.twig") * - * @param $ndrId + * @Template("@App/Ndr/BankAccount/start.html.twig") * * @return array|RedirectResponse */ public function startAction($ndrId) { + /** @var User $user */ + $user = $this->getUser(); + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); + $ndr = $this->reportApi->getNdrIfNotSubmitted($ndrId, self::$jmsGroups); if (NdrStatusService::STATE_NOT_STARTED != $ndr->getStatusService()->getBankAccountsState()['state']) { return $this->redirectToRoute('ndr_bank_accounts_summary', ['ndrId' => $ndrId]); @@ -60,15 +68,15 @@ public function startAction($ndrId) return [ 'ndr' => $ndr, + 'isMultiClientDeputy' => $isMultiClientDeputy, ]; } /** * @Route("/ndr/{ndrId}/bank-account/step{step}/{accountId}", name="ndr_bank_accounts_step", requirements={"step":"\d+"}) + * * @Template("@App/Ndr/BankAccount/step.html.twig") * - * @param $ndrId - * @param $step * @param null $accountId * * @return array|RedirectResponse @@ -164,6 +172,7 @@ public function stepAction(Request $request, $ndrId, $step, $accountId = null) /** * @Route("/ndr/{ndrId}/bank-accounts/add_another", name="ndr_bank_accounts_add_another") + * * @Template("@App/Ndr/BankAccount/add_another.html.twig") */ public function addAnotherAction(Request $request, $ndrId) @@ -191,7 +200,6 @@ public function addAnotherAction(Request $request, $ndrId) /** * @Route("/ndr/{ndrId}/bank-accounts/summary", name="ndr_bank_accounts_summary") * - * @param $ndrId * @Template("@App/Ndr/BankAccount/summary.html.twig") * * @return array|RedirectResponse @@ -210,10 +218,8 @@ public function summaryAction($ndrId) /** * @Route("/ndr/{ndrId}/bank-account/{accountId}/delete", name="ndr_bank_account_delete") - * @Template("@App/Common/confirmDelete.html.twig") * - * @param $ndrId - * @param $accountId + * @Template("@App/Common/confirmDelete.html.twig") * * @return array|RedirectResponse */ diff --git a/client/app/src/Controller/Ndr/DebtController.php b/client/app/src/Controller/Ndr/DebtController.php index 188bdef95c..7c7edebfb6 100644 --- a/client/app/src/Controller/Ndr/DebtController.php +++ b/client/app/src/Controller/Ndr/DebtController.php @@ -3,7 +3,9 @@ namespace App\Controller\Ndr; use App\Controller\AbstractController; +use App\Entity\User; use App\Form as FormDir; +use App\Service\Client\Internal\ClientApi; use App\Service\Client\Internal\ReportApi; use App\Service\Client\RestClient; use App\Service\NdrStatusService; @@ -25,20 +27,33 @@ class DebtController extends AbstractController */ private $restClient; + /** + * @var ClientApi + */ + private $clientApi; + public function __construct( ReportApi $reportApi, - RestClient $restClient + RestClient $restClient, + ClientApi $clientApi ) { $this->reportApi = $reportApi; $this->restClient = $restClient; + $this->clientApi = $clientApi; } /** * @Route("/ndr/{ndrId}/debts", name="ndr_debts") + * * @Template("@App/Ndr/Debt/start.html.twig") */ public function startAction(Request $request, $ndrId) { + /** @var User $user */ + $user = $this->getUser(); + + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); + $ndr = $this->reportApi->getNdrIfNotSubmitted($ndrId, self::$jmsGroups); if (NdrStatusService::STATE_NOT_STARTED != $ndr->getStatusService()->getDebtsState()['state']) { return $this->redirectToRoute('ndr_debts_summary', ['ndrId' => $ndr->getId()]); @@ -46,11 +61,13 @@ public function startAction(Request $request, $ndrId) return [ 'ndr' => $ndr, + 'isMultiClientDeputy' => $isMultiClientDeputy, ]; } /** * @Route("/ndr/{ndrId}/debts/exist", name="ndr_debts_exist") + * * @Template("@App/Ndr/Debt/exist.html.twig") */ public function existAction(Request $request, $ndrId) @@ -89,6 +106,7 @@ public function existAction(Request $request, $ndrId) * List debts. * * @Route("/ndr/{ndrId}/debts/edit", name="ndr_debts_edit") + * * @Template("@App/Ndr/Debt/edit.html.twig") */ public function editAction(Request $request, $ndrId) @@ -126,6 +144,7 @@ public function editAction(Request $request, $ndrId) * How debts are managed question. * * @Route("/ndr/{ndrId}/debts/management", name="ndr_debts_management") + * * @Template("@App/Ndr/Debt/management.html.twig") */ public function managementAction(Request $request, $ndrId) @@ -164,6 +183,7 @@ public function managementAction(Request $request, $ndrId) * List debts. * * @Route("/ndr/{ndrId}/debts/summary", name="ndr_debts_summary") + * * @Template("@App/Ndr/Debt/summary.html.twig") */ public function summaryAction(Request $request, $ndrId) diff --git a/client/app/src/Controller/Ndr/DeputyExpenseController.php b/client/app/src/Controller/Ndr/DeputyExpenseController.php index b2f1e7099c..8bcfcafd46 100644 --- a/client/app/src/Controller/Ndr/DeputyExpenseController.php +++ b/client/app/src/Controller/Ndr/DeputyExpenseController.php @@ -4,7 +4,9 @@ use App\Controller\AbstractController; use App\Entity as EntityDir; +use App\Entity\User; use App\Form as FormDir; +use App\Service\Client\Internal\ClientApi; use App\Service\Client\Internal\ReportApi; use App\Service\Client\RestClient; use App\Service\NdrStatusService; @@ -29,27 +31,33 @@ class DeputyExpenseController extends AbstractController /** @var RouterInterface */ private $router; + private $clientApi; public function __construct( ReportApi $reportApi, RestClient $restClient, - RouterInterface $router + RouterInterface $router, + ClientApi $clientApi ) { $this->reportApi = $reportApi; $this->restClient = $restClient; $this->router = $router; + $this->clientApi = $clientApi; } /** * @Route("/ndr/{ndrId}/deputy-expenses", name="ndr_deputy_expenses") - * @Template("@App/Ndr/DeputyExpense/start.html.twig") * - * @param $ndrId + * @Template("@App/Ndr/DeputyExpense/start.html.twig") * * @return array|RedirectResponse */ public function startAction($ndrId) { + /** @var User $user */ + $user = $this->getUser(); + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); + $ndr = $this->reportApi->getNdrIfNotSubmitted($ndrId, self::$jmsGroups); if (NdrStatusService::STATE_NOT_STARTED != $ndr->getStatusService()->getExpensesState()['state']) { @@ -58,11 +66,13 @@ public function startAction($ndrId) return [ 'ndr' => $ndr, + 'isMultiClientDeputy' => $isMultiClientDeputy, ]; } /** * @Route("/ndr/{ndrId}/deputy-expenses/exist", name="ndr_deputy_expenses_exist") + * * @Template("@App/Ndr/DeputyExpense/exist.html.twig") */ public function existAction(Request $request, $ndrId) @@ -102,9 +112,8 @@ public function existAction(Request $request, $ndrId) /** * @Route("/ndr/{ndrId}/deputy-expenses/add", name="ndr_deputy_expenses_add") - * @Template("@App/Ndr/DeputyExpense/add.html.twig") * - * @param $ndrId + * @Template("@App/Ndr/DeputyExpense/add.html.twig") * * @return array|RedirectResponse */ @@ -145,6 +154,7 @@ public function addAction(Request $request, $ndrId) /** * @Route("/ndr/{ndrId}/deputy-expenses/add_another", name="ndr_deputy_expenses_add_another") + * * @Template("@App/Ndr/DeputyExpense/addAnother.html.twig") */ public function addAnotherAction(Request $request, $ndrId) @@ -171,6 +181,7 @@ public function addAnotherAction(Request $request, $ndrId) /** * @Route("/ndr/{ndrId}/deputy-expenses/edit/{expenseId}", name="ndr_deputy_expenses_edit") + * * @Template("@App/Ndr/DeputyExpense/edit.html.twig") */ public function editAction(Request $request, $ndrId, $expenseId) @@ -199,9 +210,8 @@ public function editAction(Request $request, $ndrId, $expenseId) /** * @Route("/ndr/{ndrId}/deputy-expenses/summary", name="ndr_deputy_expenses_summary") - * @Template("@App/Ndr/DeputyExpense/summary.html.twig") * - * @param $ndrId + * @Template("@App/Ndr/DeputyExpense/summary.html.twig") * * @return array|RedirectResponse */ @@ -219,9 +229,8 @@ public function summaryAction($ndrId) /** * @Route("/ndr/{ndrId}/deputy-expenses/{expenseId}/delete", name="ndr_deputy_expenses_delete") - * @Template("@App/Common/confirmDelete.html.twig") * - * @param int $id + * @Template("@App/Common/confirmDelete.html.twig") * * @return array|RedirectResponse */ diff --git a/client/app/src/Controller/Ndr/IncomeBenefitController.php b/client/app/src/Controller/Ndr/IncomeBenefitController.php index 80a0ba1650..6e154fd39a 100644 --- a/client/app/src/Controller/Ndr/IncomeBenefitController.php +++ b/client/app/src/Controller/Ndr/IncomeBenefitController.php @@ -4,7 +4,9 @@ use App\Controller\AbstractController; use App\Entity\Ndr\Ndr; +use App\Entity\User; use App\Form as FormDir; +use App\Service\Client\Internal\ClientApi; use App\Service\Client\Internal\ReportApi; use App\Service\Client\RestClient; use App\Service\NdrStatusService; @@ -38,27 +40,33 @@ class IncomeBenefitController extends AbstractController * @var StepRedirector */ private $stepRedirector; + private $clientApi; public function __construct( ReportApi $reportApi, RestClient $restClient, - StepRedirector $stepRedirector + StepRedirector $stepRedirector, + ClientApi $clientApi ) { $this->reportApi = $reportApi; $this->restClient = $restClient; $this->stepRedirector = $stepRedirector; + $this->clientApi = $clientApi; } /** * @Route("/ndr/{ndrId}/income-benefits", name="ndr_income_benefits") - * @Template("@App/Ndr/IncomeBenefit/start.html.twig") * - * @param $ndrId + * @Template("@App/Ndr/IncomeBenefit/start.html.twig") * * @return array|RedirectResponse */ public function startAction($ndrId) { + /** @var User $user */ + $user = $this->getUser(); + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); + $ndr = $this->reportApi->getNdrIfNotSubmitted($ndrId, self::$jmsGroups); if (NdrStatusService::STATE_NOT_STARTED != $ndr->getStatusService()->getIncomeBenefitsState()['state']) { return $this->redirectToRoute('ndr_income_benefits_summary', ['ndrId' => $ndrId]); @@ -66,11 +74,13 @@ public function startAction($ndrId) return [ 'ndr' => $ndr, + 'isMultiClientDeputy' => $isMultiClientDeputy, ]; } /** * @Route("/ndr/{ndrId}/income-benefits/step/{step}", name="ndr_income_benefits_step") + * * @Template("@App/Ndr/IncomeBenefit/step.html.twig") */ public function stepAction(Request $request, $ndrId, $step, TranslatorInterface $translator) @@ -130,6 +140,7 @@ public function stepAction(Request $request, $ndrId, $step, TranslatorInterface /** * @Route("/ndr/{ndrId}/income-benefits/summary", name="ndr_income_benefits_summary") + * * @Template("@App/Ndr/IncomeBenefit/summary.html.twig") */ public function summaryAction(Request $request, $ndrId) diff --git a/client/app/src/Controller/Ndr/NdrController.php b/client/app/src/Controller/Ndr/NdrController.php index 5726cde53e..49aee82c15 100644 --- a/client/app/src/Controller/Ndr/NdrController.php +++ b/client/app/src/Controller/Ndr/NdrController.php @@ -11,13 +11,11 @@ use App\Model as ModelDir; use App\Service\Client\Internal\ClientApi; use App\Service\Client\Internal\NdrApi; -use App\Service\Client\Internal\PreRegistrationApi; use App\Service\Client\Internal\SatisfactionApi; use App\Service\Client\Internal\UserApi; use App\Service\File\S3FileUploader; use App\Service\HtmlToPdfGenerator; use App\Service\NdrStatusService; -use App\Service\ParameterStoreService; use App\Service\Redirector; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -55,7 +53,6 @@ class NdrController extends AbstractController public function __construct( private UserApi $userApi, private ClientApi $clientApi, - private PreRegistrationApi $preRegistrationApi, private SatisfactionApi $satisfactionApi, private NdrApi $ndrApi, private HtmlToPdfGenerator $htmlToPdf @@ -63,40 +60,16 @@ public function __construct( } /** - * //TODO move view into Ndr directory when branches are integrated. - * - * @Route("/ndr", name="ndr_index") + * @Route("/ndr", name="ndr_index_deprecated") * * @Template("@App/Ndr/Ndr/index.html.twig") * * @return array|RedirectResponse */ - public function indexAction(Redirector $redirector) + public function indexAction() { - // redirect if user has missing details or is on wrong page - $user = $this->userApi->getUserWithData(array_merge(self::$ndrGroupsForValidation, ['status'])); - - $route = $redirector->getCorrectRouteIfDifferent($user, 'ndr_index'); - - if (is_string($route)) { - return $this->redirectToRoute($route); - } - - $clients = $user->getClients(); - $client = !empty($clients) ? $clients[0] : null; - - $clientWithCoDeputies = $this->clientApi->getWithUsersV2($client->getId()); - $coDeputies = $clientWithCoDeputies->getCoDeputies(); - - return [ - 'client' => $client, - 'coDeputies' => $coDeputies, - 'clientHasCoDeputies' => $this->preRegistrationApi->clientHasCoDeputies($client->getCaseNumber()), - 'ndr' => $client->getNdr(), - 'reportsSubmitted' => $client->getSubmittedReports(), - 'reportActive' => $client->getActiveReport(), - 'ndrStatus' => new NdrStatusService($client->getNdr()), - ]; + // Moved to ReportController::clientHomepageAction() + return $this->redirectToRoute('homepage'); } /** @@ -106,7 +79,7 @@ public function indexAction(Redirector $redirector) * * @return array|RedirectResponse */ - public function overviewAction(Redirector $redirector, ParameterStoreService $parameterStore) + public function overviewAction(Redirector $redirector, int $ndrId) { // redirect if user has missing details or is on wrong page $user = $this->userApi->getUserWithData(); @@ -116,24 +89,28 @@ public function overviewAction(Redirector $redirector, ParameterStoreService $pa return $this->redirectToRoute($route); } - $client = $this->clientApi->getFirstClient(self::$ndrGroupsForValidation); + $ndr = $this->ndrApi->getNdr($ndrId, array_merge(self::$ndrGroupsForValidation, ['ndr-client', 'client-id'])); + + $clientId = $ndr->getClient()->getId(); + $client = $this->clientApi->getById($clientId); if (is_null($client)) { throw $this->createNotFoundException(); } - $ndr = $client->getNdr(); - if ($ndr->getSubmitted()) { throw new ReportSubmittedException(); } $ndrStatus = new NdrStatusService($ndr); + $deputyHasMultiClients = !$user->isDeputyOrg() && count($this->clientApi->getAllClientsByDeputyUid($user->getDeputyUid())) > 1; + return [ 'client' => $client, 'ndr' => $ndr, 'ndrStatus' => $ndrStatus, + 'deputyHasMultiClients' => $deputyHasMultiClients, ]; } @@ -144,41 +121,49 @@ public function overviewAction(Redirector $redirector, ParameterStoreService $pa * * @Template("@App/Ndr/Ndr/review.html.twig") */ - public function reviewAction($ndrId) + public function reviewAction(int $ndrId) { - $client = $this->clientApi->getFirstClient(self::$ndrGroupsForValidation); + $ndr = $this->ndrApi->getNdr($ndrId, array_merge(self::$ndrGroupsForValidation, ['ndr-client', 'client-id'])); + + $clientId = $ndr->getClient()->getId(); + $client = $this->clientApi->getById($clientId); if (is_null($client)) { throw $this->createNotFoundException(); } - $ndr = $client->getNdr(); - $ndr->setClient($client); - // check status $ndrStatusService = new NdrStatusService($ndr); + /** @var User $user */ + $user = $this->getUser(); + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); + + $backLink = $this->generateUrl('lay_home', ['clientId' => $clientId]); + return [ 'ndr' => $ndr, - 'deputy' => $this->getUser(), + 'deputy' => $user, 'ndrStatus' => $ndrStatusService, + 'isMultiClientDeputy' => $isMultiClientDeputy, + 'backLink' => $backLink, ]; } /** * @Route("/ndr/{ndrId}/deputyndr.pdf", name="ndr_pdf") */ - public function pdfViewAction($ndrId) + public function pdfViewAction(int $ndrId) { - $client = $this->clientApi->getFirstClient(self::$ndrGroupsForValidation); + $ndr = $this->ndrApi->getNdr($ndrId, array_merge(self::$ndrGroupsForValidation, ['ndr-client', 'client-id'])); + + $clientId = $ndr->getClient()->getId(); + $client = $this->clientApi->getById($clientId); if (is_null($client)) { throw $this->createNotFoundException(); } - $ndr = $client->getNdr(); - $ndr->setClient($client); - $pdfBinary = $this->getPdfBinaryContent($ndr); $response = new Response($pdfBinary); @@ -217,17 +202,17 @@ private function getPdfBinaryContent($ndr) * * @throws \Exception */ - public function declarationAction(Request $request, $ndrId, S3FileUploader $fileUploader) + public function declarationAction(Request $request, int $ndrId, S3FileUploader $fileUploader) { - $client = $this->clientApi->getFirstClient(self::$ndrGroupsForValidation); + $ndr = $this->ndrApi->getNdr($ndrId, array_merge(self::$ndrGroupsForValidation, ['ndr-client', 'client-id'])); + + $clientId = $ndr->getClient()->getId(); + $client = $this->clientApi->getById($clientId); if (is_null($client)) { throw $this->createNotFoundException(); } - $ndr = $client->getNdr(); - $ndr->setClient($client); - // check status $ndrStatus = new NdrStatusService($ndr); if (!$ndrStatus->isReadyToSubmit()) { @@ -237,6 +222,10 @@ public function declarationAction(Request $request, $ndrId, S3FileUploader $file throw new ReportSubmittedException(); } + /** @var User $currentUser */ + $currentUser = $this->getUser(); + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($currentUser); + $form = $this->createForm(FormDir\Ndr\ReportDeclarationType::class, $ndr); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { @@ -261,6 +250,7 @@ public function declarationAction(Request $request, $ndrId, S3FileUploader $file 'ndr' => $ndr, 'client' => $client, 'form' => $form->createView(), + 'isMultiClientDeputy' => $isMultiClientDeputy, ]; } @@ -271,19 +261,20 @@ public function declarationAction(Request $request, $ndrId, S3FileUploader $file * * @Template("@App/Ndr/Ndr/submitConfirmation.html.twig") */ - public function submitConfirmationAction(Request $request, $ndrId) + public function submitConfirmationAction(Request $request, int $ndrId) { - $client = $this->clientApi->getFirstClient(self::$ndrGroupsForValidation); + $ndr = $this->ndrApi->getNdr($ndrId, array_merge(self::$ndrGroupsForValidation, ['ndr-client', 'client-id'])); + + $clientId = $ndr->getClient()->getId(); + $client = $this->clientApi->getById($clientId); if (is_null($client)) { throw $this->createNotFoundException(); } - $ndr = $client->getNdr(); if ($ndr->getId() != $ndrId) { throw $this->createAccessDeniedException('Not authorised to access this Report'); } - $ndr->setClient($client); if (!$ndr->getSubmitted()) { throw new ReportNotSubmittedException(); @@ -312,26 +303,25 @@ public function submitConfirmationAction(Request $request, $ndrId) * * @Template("@App/Report/Report/submitFeedback.html.twig") */ - public function submitFeedbackAction($ndrId) + public function submitFeedbackAction(int $ndrId) { - $client = $this->clientApi->getFirstClient(self::$ndrGroupsForValidation); + $ndr = $this->ndrApi->getNdr($ndrId, array_merge(self::$ndrGroupsForValidation, ['ndr-client', 'client-id'])); + + $clientId = $ndr->getClient()->getId(); + $client = $this->clientApi->getById($clientId); if (is_null($client)) { throw $this->createNotFoundException(); } - $ndr = $client->getNdr(); if ($ndr->getId() != $ndrId) { throw $this->createAccessDeniedException('Not authorised to access this Report'); } - $ndr->setClient($client); if (!$ndr->getSubmitted()) { throw new ReportNotSubmittedException(); } - $ndrStatus = new NdrStatusService($ndr); - return [ 'ndr' => $ndr, 'client' => $client, diff --git a/client/app/src/Controller/Ndr/OtherInfoController.php b/client/app/src/Controller/Ndr/OtherInfoController.php index b6a2dc9715..eb4cf88e1b 100644 --- a/client/app/src/Controller/Ndr/OtherInfoController.php +++ b/client/app/src/Controller/Ndr/OtherInfoController.php @@ -3,7 +3,9 @@ namespace App\Controller\Ndr; use App\Controller\AbstractController; +use App\Entity\User; use App\Form as FormDir; +use App\Service\Client\Internal\ClientApi; use App\Service\Client\Internal\ReportApi; use App\Service\Client\RestClient; use App\Service\NdrStatusService; @@ -33,22 +35,34 @@ class OtherInfoController extends AbstractController */ private $stepRedirector; + /** + * @var ClientApi + */ + private $clientApi; + public function __construct( ReportApi $reportApi, RestClient $restClient, - StepRedirector $stepRedirector + StepRedirector $stepRedirector, + ClientApi $clientApi ) { $this->reportApi = $reportApi; $this->restClient = $restClient; $this->stepRedirector = $stepRedirector; + $this->clientApi = $clientApi; } /** * @Route("/ndr/{ndrId}/any-other-info", name="ndr_other_info") + * * @Template("@App/Ndr/OtherInfo/start.html.twig") */ public function startAction(Request $request, $ndrId) { + /** @var User $user */ + $user = $this->getUser(); + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); + $ndr = $this->reportApi->getNdrIfNotSubmitted($ndrId, self::$jmsGroups); if (NdrStatusService::STATE_NOT_STARTED != $ndr->getStatusService()->getOtherInfoState()['state']) { return $this->redirectToRoute('ndr_other_info_summary', ['ndrId' => $ndrId]); @@ -56,16 +70,18 @@ public function startAction(Request $request, $ndrId) return [ 'ndr' => $ndr, + 'isMultiClientDeputy' => $isMultiClientDeputy, ]; } /** * @Route("/ndr/{ndrId}/any-other-info/step/{step}", name="ndr_other_info_step") + * * @Template("@App/Ndr/OtherInfo/step.html.twig") */ public function stepAction(Request $request, $ndrId, $step) { - $totalSteps = 1; //only one step but convenient to reuse the "step" logic and keep things aligned/simple + $totalSteps = 1; // only one step but convenient to reuse the "step" logic and keep things aligned/simple if ($step < 1 || $step > $totalSteps) { return $this->redirectToRoute('ndr_other_info_summary', ['ndrId' => $ndrId]); } @@ -105,6 +121,7 @@ public function stepAction(Request $request, $ndrId, $step) /** * @Route("/ndr/{ndrId}/any-other-info/summary", name="ndr_other_info_summary") + * * @Template("@App/Ndr/OtherInfo/summary.html.twig") */ public function summaryAction(Request $request, $ndrId) diff --git a/client/app/src/Controller/Ndr/VisitsCareController.php b/client/app/src/Controller/Ndr/VisitsCareController.php index 6d4608fdd0..6336d6a081 100644 --- a/client/app/src/Controller/Ndr/VisitsCareController.php +++ b/client/app/src/Controller/Ndr/VisitsCareController.php @@ -4,7 +4,9 @@ use App\Controller\AbstractController; use App\Entity as EntityDir; +use App\Entity\User; use App\Form as FormDir; +use App\Service\Client\Internal\ClientApi; use App\Service\Client\Internal\ReportApi; use App\Service\Client\RestClient; use App\Service\NdrStatusService; @@ -36,26 +38,36 @@ class VisitsCareController extends AbstractController */ private $stepRedirector; + /** + * @var StepRedirector + */ + private $clientApi; + public function __construct( ReportApi $reportApi, RestClient $restClient, - StepRedirector $stepRedirector + StepRedirector $stepRedirector, + ClientApi $clientApi ) { $this->reportApi = $reportApi; $this->restClient = $restClient; $this->stepRedirector = $stepRedirector; + $this->clientApi = $clientApi; } /** * @Route("/ndr/{ndrId}/visits-care", name="ndr_visits_care") - * @Template("@App/Ndr/VisitsCare/start.html.twig") * - * @param $ndrId + * @Template("@App/Ndr/VisitsCare/start.html.twig") * * @return array|RedirectResponse */ public function startAction(Request $request, $ndrId) { + /** @var User $user */ + $user = $this->getUser(); + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); + $ndr = $this->reportApi->getNdrIfNotSubmitted($ndrId, self::$jmsGroups); if (NdrStatusService::STATE_NOT_STARTED != $ndr->getStatusService()->getVisitsCareState()['state']) { return $this->redirectToRoute('ndr_visits_care_summary', ['ndrId' => $ndrId]); @@ -63,15 +75,14 @@ public function startAction(Request $request, $ndrId) return [ 'ndr' => $ndr, + 'isMultiClientDeputy' => $isMultiClientDeputy, ]; } /** * @Route("/ndr/{ndrId}/visits-care/step/{step}", name="ndr_visits_care_step") - * @Template("@App/Ndr/VisitsCare/step.html.twig") * - * @param $ndrId - * @param $step + * @Template("@App/Ndr/VisitsCare/step.html.twig") * * @return array|RedirectResponse */ @@ -137,9 +148,8 @@ public function stepAction(Request $request, $ndrId, $step, TranslatorInterface /** * @Route("/ndr/{ndrId}/visits-care/summary", name="ndr_visits_care_summary") - * @Template("@App/Ndr/VisitsCare/summary.html.twig") * - * @param $ndrId + * @Template("@App/Ndr/VisitsCare/summary.html.twig") * * @return array|RedirectResponse */ diff --git a/client/app/src/Controller/Report/ActionController.php b/client/app/src/Controller/Report/ActionController.php index a883d723f6..0f56cf322a 100644 --- a/client/app/src/Controller/Report/ActionController.php +++ b/client/app/src/Controller/Report/ActionController.php @@ -51,7 +51,7 @@ public function startAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); if (EntityDir\Report\Status::STATE_NOT_STARTED != $report->getStatus()->getActionsState()['state']) { @@ -133,7 +133,7 @@ public function summaryAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $fromPage = $request->get('from'); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); diff --git a/client/app/src/Controller/Report/AssetController.php b/client/app/src/Controller/Report/AssetController.php index 672b37dec8..5b55b6c732 100644 --- a/client/app/src/Controller/Report/AssetController.php +++ b/client/app/src/Controller/Report/AssetController.php @@ -41,7 +41,7 @@ public function startAction($reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); if (Report\Status::STATE_NOT_STARTED != $report->getStatus()->getAssetsState()['state']) { @@ -354,7 +354,7 @@ public function summaryAction($reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); if (Report\Status::STATE_NOT_STARTED == $report->getStatus()->getAssetsState()['state']) { diff --git a/client/app/src/Controller/Report/BalanceController.php b/client/app/src/Controller/Report/BalanceController.php index 5be9743a61..0f508371a7 100644 --- a/client/app/src/Controller/Report/BalanceController.php +++ b/client/app/src/Controller/Report/BalanceController.php @@ -54,7 +54,7 @@ public function balanceAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); $form = $this->createForm(FormDir\Report\ReasonForBalanceType::class, $report); diff --git a/client/app/src/Controller/Report/BankAccountController.php b/client/app/src/Controller/Report/BankAccountController.php index f760430d1b..aff1788152 100644 --- a/client/app/src/Controller/Report/BankAccountController.php +++ b/client/app/src/Controller/Report/BankAccountController.php @@ -43,7 +43,7 @@ public function startAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); if (EntityDir\Report\Status::STATE_NOT_STARTED != $report->getStatus()->getBankAccountsState()['state']) { @@ -210,7 +210,7 @@ public function summaryAction($reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); if (EntityDir\Report\Status::STATE_NOT_STARTED == $report->getStatus()->getBankAccountsState()['state']) { diff --git a/client/app/src/Controller/Report/ClientBenefitsCheckController.php b/client/app/src/Controller/Report/ClientBenefitsCheckController.php index 92cd748634..ff88489e50 100644 --- a/client/app/src/Controller/Report/ClientBenefitsCheckController.php +++ b/client/app/src/Controller/Report/ClientBenefitsCheckController.php @@ -57,9 +57,9 @@ public function start(int $reportId, string $reportOrNdr) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); - $report = ('ndr' === $reportOrNdr) ? $this->ndrApi->getNdr($reportId, array_merge(self::$jmsGroups, ['ndr-client'])) : + $report = ('ndr' === $reportOrNdr) ? $this->ndrApi->getNdr($reportId, array_merge(self::$jmsGroups, ['ndr-client', 'client-id'])) : $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); $status = ('ndr' === $reportOrNdr) ? $report->getStatusService()->getClientBenefitsCheckState()['state'] : @@ -108,7 +108,7 @@ public function step(Request $request, int $reportId, int $step, string $reportO ->setTotalSteps($totalSteps) ->setRouteBaseParams(['reportId' => $reportId, 'reportOrNdr' => $reportOrNdr]); - $report = ('ndr' === $reportOrNdr) ? $this->ndrApi->getNdr($reportId, array_merge(self::$jmsGroups, ['ndr-client', 'ndr-id', 'ndr'])) : + $report = ('ndr' === $reportOrNdr) ? $this->ndrApi->getNdr($reportId, array_merge(self::$jmsGroups, ['ndr-client', 'client-id', 'ndr-id', 'ndr'])) : $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); if ('ndr' === $reportOrNdr) { @@ -196,9 +196,9 @@ public function summary(int $reportId, string $reportOrNdr) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); - $report = ('ndr' === $reportOrNdr) ? $this->ndrApi->getNdr($reportId, array_merge(self::$jmsGroups, ['ndr-client'])) : + $report = ('ndr' === $reportOrNdr) ? $this->ndrApi->getNdr($reportId, array_merge(self::$jmsGroups, ['ndr-client', 'client-id'])) : $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); return [ diff --git a/client/app/src/Controller/Report/ContactController.php b/client/app/src/Controller/Report/ContactController.php index 4076b0f29c..f7a80f24b9 100644 --- a/client/app/src/Controller/Report/ContactController.php +++ b/client/app/src/Controller/Report/ContactController.php @@ -40,7 +40,7 @@ public function startAction($reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); @@ -210,7 +210,7 @@ public function summaryAction($reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); diff --git a/client/app/src/Controller/Report/DebtController.php b/client/app/src/Controller/Report/DebtController.php index afe42a2e41..40602289d1 100644 --- a/client/app/src/Controller/Report/DebtController.php +++ b/client/app/src/Controller/Report/DebtController.php @@ -41,7 +41,7 @@ public function startAction(Request $request, $reportId) /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); if (EntityDir\Report\Status::STATE_NOT_STARTED != $report->getStatus()->getDebtsState()['state']) { @@ -191,7 +191,7 @@ public function summaryAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $fromPage = $request->get('from'); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); diff --git a/client/app/src/Controller/Report/DecisionController.php b/client/app/src/Controller/Report/DecisionController.php index de2a6f876c..7ccd8ae146 100644 --- a/client/app/src/Controller/Report/DecisionController.php +++ b/client/app/src/Controller/Report/DecisionController.php @@ -42,7 +42,7 @@ public function startAction($reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); @@ -305,7 +305,7 @@ public function summaryAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $fromPage = $request->get('from'); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); diff --git a/client/app/src/Controller/Report/DeputyExpenseController.php b/client/app/src/Controller/Report/DeputyExpenseController.php index ac4a8753ec..def6c78a58 100644 --- a/client/app/src/Controller/Report/DeputyExpenseController.php +++ b/client/app/src/Controller/Report/DeputyExpenseController.php @@ -41,7 +41,7 @@ public function startAction($reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); @@ -243,7 +243,7 @@ public function summaryAction($reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); if (EntityDir\Report\Status::STATE_NOT_STARTED == $report->getStatus()->getExpensesState()['state']) { diff --git a/client/app/src/Controller/Report/DocumentController.php b/client/app/src/Controller/Report/DocumentController.php index 661028f8ec..94f06c77bc 100644 --- a/client/app/src/Controller/Report/DocumentController.php +++ b/client/app/src/Controller/Report/DocumentController.php @@ -63,7 +63,7 @@ public function startAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); @@ -356,7 +356,7 @@ public function summaryAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); if (EntityDir\Report\Status::STATE_NOT_STARTED == $report->getStatus()->getDocumentsState()['state']) { diff --git a/client/app/src/Controller/Report/GiftController.php b/client/app/src/Controller/Report/GiftController.php index 3861bc1a91..79106e0265 100644 --- a/client/app/src/Controller/Report/GiftController.php +++ b/client/app/src/Controller/Report/GiftController.php @@ -41,7 +41,7 @@ public function startAction($reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); @@ -214,7 +214,7 @@ public function summaryAction($reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); if (EntityDir\Report\Status::STATE_NOT_STARTED == $report->getStatus()->getGiftsState()['state']) { diff --git a/client/app/src/Controller/Report/LifestyleController.php b/client/app/src/Controller/Report/LifestyleController.php index 7aca9a230a..1dd6ea5994 100644 --- a/client/app/src/Controller/Report/LifestyleController.php +++ b/client/app/src/Controller/Report/LifestyleController.php @@ -41,7 +41,7 @@ public function startAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); if (EntityDir\Report\Status::STATE_NOT_STARTED != $report->getStatus()->getLifestyleState()['state']) { @@ -125,7 +125,7 @@ public function summaryAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $fromPage = $request->get('from'); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); diff --git a/client/app/src/Controller/Report/MoneyInController.php b/client/app/src/Controller/Report/MoneyInController.php index 3b117a7068..06492adb91 100644 --- a/client/app/src/Controller/Report/MoneyInController.php +++ b/client/app/src/Controller/Report/MoneyInController.php @@ -47,7 +47,7 @@ public function startAction($reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); if (Status::STATE_NOT_STARTED != $report->getStatus()->getMoneyInState()['state']) { @@ -330,7 +330,7 @@ public function summaryAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $fromPage = $request->get('from'); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); diff --git a/client/app/src/Controller/Report/MoneyInShortController.php b/client/app/src/Controller/Report/MoneyInShortController.php index a87127cbe1..fbdc072e73 100644 --- a/client/app/src/Controller/Report/MoneyInShortController.php +++ b/client/app/src/Controller/Report/MoneyInShortController.php @@ -42,7 +42,7 @@ public function startAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); @@ -395,7 +395,7 @@ public function summaryAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $fromPage = $request->get('from'); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); diff --git a/client/app/src/Controller/Report/MoneyOutController.php b/client/app/src/Controller/Report/MoneyOutController.php index eb3d9641ce..3467c57fca 100644 --- a/client/app/src/Controller/Report/MoneyOutController.php +++ b/client/app/src/Controller/Report/MoneyOutController.php @@ -47,7 +47,7 @@ public function startAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); if (Status::STATE_NOT_STARTED != $report->getStatus()->getMoneyOutState()['state']) { @@ -330,7 +330,7 @@ public function summaryAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $fromPage = $request->get('from'); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); diff --git a/client/app/src/Controller/Report/MoneyOutShortController.php b/client/app/src/Controller/Report/MoneyOutShortController.php index fdb6899935..e2d4da4c59 100644 --- a/client/app/src/Controller/Report/MoneyOutShortController.php +++ b/client/app/src/Controller/Report/MoneyOutShortController.php @@ -42,7 +42,7 @@ public function startAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); @@ -398,7 +398,7 @@ public function summaryAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $fromPage = $request->get('from'); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); diff --git a/client/app/src/Controller/Report/MoneyTransferController.php b/client/app/src/Controller/Report/MoneyTransferController.php index 50d832a506..4e20860aad 100644 --- a/client/app/src/Controller/Report/MoneyTransferController.php +++ b/client/app/src/Controller/Report/MoneyTransferController.php @@ -44,7 +44,7 @@ public function startAction($reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); if (!$report->enoughBankAccountForTransfers()) { @@ -236,7 +236,7 @@ public function summaryAction($reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); if (EntityDir\Report\Status::STATE_NOT_STARTED == $report->getStatus()->getMoneyTransferState()['state']) { diff --git a/client/app/src/Controller/Report/OtherInfoController.php b/client/app/src/Controller/Report/OtherInfoController.php index 7b3112edf2..945e08e634 100644 --- a/client/app/src/Controller/Report/OtherInfoController.php +++ b/client/app/src/Controller/Report/OtherInfoController.php @@ -41,7 +41,7 @@ public function startAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); if (EntityDir\Report\Status::STATE_NOT_STARTED != $report->getStatus()->getOtherInfoState()['state']) { @@ -112,7 +112,7 @@ public function summaryAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $fromPage = $request->get('from'); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); diff --git a/client/app/src/Controller/Report/ReportController.php b/client/app/src/Controller/Report/ReportController.php index 09530628f9..f35760eee0 100755 --- a/client/app/src/Controller/Report/ReportController.php +++ b/client/app/src/Controller/Report/ReportController.php @@ -25,6 +25,7 @@ use App\Service\Client\RestClient; use App\Service\Csv\TransactionsCsvGenerator; use App\Service\File\Storage\S3Storage; +use App\Service\NdrStatusService; use App\Service\Redirector; use App\Service\ReportSubmissionService; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; @@ -96,6 +97,31 @@ class ReportController extends AbstractController 'wish-to-provide-documentation', ]; + private static $ndrGroupsForValidation = [ + 'client', + 'client-ndr', + 'client-benefits-check', + 'client-case-number', + 'client-reports', + 'damages', + 'ndr', + 'ndr-action-give-gifts', + 'ndr-action-more-info', + 'ndr-action-property', + 'ndr-account', + 'ndr-asset', + 'ndr-debt', + 'ndr-debt-management', + 'ndr-expenses', + 'one-off', + 'pension', + 'report', + 'state-benefits', + 'user', + 'user-clients', + 'visits-care', + ]; + public function __construct( private RestClient $restClient, private ReportApi $reportApi, @@ -136,9 +162,22 @@ public function indexAction() */ public function clientHomepageAction(Redirector $redirector, string $clientId) { - // not ideal to specify both user-client and client-users, but can't fix this differently with DDPB-1711. Consider a separate call to get - // due to the way - $user = $this->userApi->getUserWithData(['user-clients', 'client', 'client-reports', 'report', 'status']); + $ndrEnabled = false; + $users = $this->clientApi->getWithUsersV2($clientId)->getUsers(); + + foreach ($users as $user) { + if ($user->isNdrEnabled()) { + $ndrEnabled = true; + } + } + + if ($ndrEnabled) { + $user = $this->userApi->getUserWithData(); + } else { + // not ideal to specify both user-client and client-users, but can't fix this differently with DDPB-1711. Consider a separate call to get + // due to the way + $user = $this->userApi->getUserWithData(['user-clients', 'client', 'client-reports', 'report', 'status']); + } // redirect back to log out page if signing in with non-primary account with primary email if (!$user->getIsPrimary()) { @@ -155,7 +194,7 @@ public function clientHomepageAction(Redirector $redirector, string $clientId) return $this->redirectToRoute('app_logout', ['notPrimaryAccount' => true]); } - $deputyHasMultiClients = $this->getUser()->isLayDeputy() && $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()); + $deputyHasMultiClients = $this->clientApi->checkDeputyHasMultiClients($user); // redirect if user has missing details or is on wrong page $route = $redirector->getCorrectRouteIfDifferent($user, 'lay_home'); @@ -166,13 +205,35 @@ public function clientHomepageAction(Redirector $redirector, string $clientId) $clientWithCoDeputies = $this->clientApi->getWithUsersV2($clientId); $coDeputies = $clientWithCoDeputies->getCoDeputies(); - return [ - 'user' => $user, - 'clientHasCoDeputies' => $this->preRegistrationApi->clientHasCoDeputies($clientWithCoDeputies->getCaseNumber()), - 'client' => $clientWithCoDeputies, + $resultsArray = [ 'coDeputies' => $coDeputies, + 'clientHasCoDeputies' => $this->preRegistrationApi->clientHasCoDeputies($clientWithCoDeputies->getCaseNumber()), 'deputyHasMultiClients' => $deputyHasMultiClients, ]; + + if ($ndrEnabled) { + $client = $this->clientApi->getById($clientId); + + $ndr = $this->reportApi->getNdr($client->getNdr()->getId(), self::$ndrGroupsForValidation); + + return array_merge([ + 'ndrEnabled' => true, + 'client' => $client, + 'ndr' => $client->getNdr(), + 'reportsSubmitted' => $client->getSubmittedReports(), + 'reportActive' => $client->getActiveReport(), + 'ndrStatus' => new NdrStatusService($ndr), + ], + $resultsArray + ); + } else { + return array_merge([ + 'ndrEnabled' => false, + 'client' => $clientWithCoDeputies, + ], + $resultsArray + ); + } } /** @@ -311,7 +372,10 @@ public function createAction(Request $request, $clientId, $action = false) return $this->redirect($this->generateUrl('homepage')); } - return ['form' => $form->createView()]; + return [ + 'form' => $form->createView(), + 'clientId' => $clientId, + ]; } /** @@ -367,9 +431,7 @@ public function overviewAction(Redirector $redirector, $reportId) $activeReport = $activeReportId ? $this->reportApi->getReportIfNotSubmitted($activeReportId, $reportJmsGroup) : null; - $deputyHasMultiClients = !$user->isDeputyOrg() && $this->clientApi->checkDeputyHasMultiClients( - $user->getDeputyUid() - ); + $deputyHasMultiClients = !$user->isDeputyOrg() && count($this->clientApi->getAllClientsByDeputyUid($user->getDeputyUid())) > 1; return $this->render($template, [ 'user' => $user, @@ -473,7 +535,7 @@ public function declarationAction(Request $request, $reportId, ReportSubmissionS return $this->redirect($this->generateUrl('report_submit_confirmation', ['reportId' => $report->getId()])); } - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $currentUser->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($currentUser->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($currentUser); return [ 'report' => $report, @@ -556,7 +618,7 @@ public function reviewAction($reportId) } } - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); return [ 'user' => $this->getUser(), diff --git a/client/app/src/Controller/Report/VisitsCareController.php b/client/app/src/Controller/Report/VisitsCareController.php index 9257cc2793..ce21f21137 100644 --- a/client/app/src/Controller/Report/VisitsCareController.php +++ b/client/app/src/Controller/Report/VisitsCareController.php @@ -42,7 +42,7 @@ public function startAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); if (EntityDir\Report\Status::STATE_NOT_STARTED != $report->getStatus()->getVisitsCareState()['state']) { @@ -134,7 +134,7 @@ public function summaryAction(Request $request, $reportId) { /** @var User $user */ $user = $this->getUser(); - $isMultiClientDeputy = 'ROLE_LAY_DEPUTY' == $user->getRoleName() ? $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()) : null; + $isMultiClientDeputy = $this->clientApi->checkDeputyHasMultiClients($user); $fromPage = $request->get('from'); $report = $this->reportApi->getReportIfNotSubmitted($reportId, self::$jmsGroups); diff --git a/client/app/src/Controller/SettingsController.php b/client/app/src/Controller/SettingsController.php index 96299dd46a..c01f90c3fc 100644 --- a/client/app/src/Controller/SettingsController.php +++ b/client/app/src/Controller/SettingsController.php @@ -99,7 +99,7 @@ public function indexAction(Redirector $redirector) return $this->redirectToRoute($route); } - $deputyHasMultiClients = $this->getUser()->isLayDeputy() && $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()); + $deputyHasMultiClients = $this->clientApi->checkDeputyHasMultiClients($user); return ['deputyHasMultiClients' => $deputyHasMultiClients]; } @@ -132,7 +132,7 @@ public function passwordEditAction(Request $request) return $this->redirect($this->generateUrl($successRoute)); } - $deputyHasMultiClients = $this->getUser()->isLayDeputy() && $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()); + $deputyHasMultiClients = $this->clientApi->checkDeputyHasMultiClients($user); return [ 'form' => $form->createView(), @@ -185,7 +185,7 @@ public function emailEditAction(Request $request) public function profileAction() { $user = $this->userApi->getUserWithData(); - $deputyHasMultiClients = $this->getUser()->isLayDeputy() && $this->clientApi->checkDeputyHasMultiClients($user->getDeputyUid()); + $deputyHasMultiClients = $this->clientApi->checkDeputyHasMultiClients($user); return [ 'user' => $this->getUser(), @@ -255,7 +255,7 @@ public function profileEditAction(Request $request) } } - $deputyHasMultiClients = $this->getUser()->isLayDeputy() && $this->clientApi->checkDeputyHasMultiClients($preUpdateDeputy->getDeputyUid()); + $deputyHasMultiClients = $this->clientApi->checkDeputyHasMultiClients($preUpdateDeputy); return [ 'user' => $preUpdateDeputy, diff --git a/client/app/src/Controller/UserResearchController.php b/client/app/src/Controller/UserResearchController.php index 8eafe47654..f81ca995ca 100644 --- a/client/app/src/Controller/UserResearchController.php +++ b/client/app/src/Controller/UserResearchController.php @@ -28,7 +28,7 @@ public function __construct( ReportApi $reportApi, TranslatorInterface $translator, FormFactoryInterface $formFactory, - NdrApi $ndrApi + NdrApi $ndrApi, ) { $this->userResearchApi = $userResearchApi; $this->reportApi = $reportApi; @@ -84,7 +84,7 @@ public function postSubmissionUserResearch(Request $request, ?int $reportId = nu */ public function userResearchSubmitted(?int $reportId = null, ?int $ndrId = null) { - $report = !is_null($reportId) ? $this->reportApi->getReport($reportId, ['report']) : $this->ndrApi->getNdr($ndrId, ['ndr']); + $report = !is_null($reportId) ? $this->reportApi->getReport($reportId, ['report']) : $this->ndrApi->getNdr($ndrId, ['ndr-client', 'client-id']); // check status if (!$report->getSubmitted()) { diff --git a/client/app/src/Service/Client/Internal/ClientApi.php b/client/app/src/Service/Client/Internal/ClientApi.php index 7704c39283..bbc58013a0 100644 --- a/client/app/src/Service/Client/Internal/ClientApi.php +++ b/client/app/src/Service/Client/Internal/ClientApi.php @@ -6,6 +6,7 @@ use App\Entity\Client; use App\Entity\Report\Report; +use App\Entity\User; use App\Event\ClientDeletedEvent; use App\Event\ClientUpdatedEvent; use App\EventDispatcher\ObservableEventDispatcher; @@ -250,8 +251,8 @@ public function getAllClientsByDeputyUid(int $deputyUid, $groups = []) ); } - public function checkDeputyHasMultiClients(int $deputyUid): bool + public function checkDeputyHasMultiClients(User $user): bool { - return count($this->getAllClientsByDeputyUid($deputyUid)) > 1; + return 'ROLE_LAY_DEPUTY' == $user->getRoleName() && count($this->getAllClientsByDeputyUid($user->getDeputyUid())) > 1; } } diff --git a/client/app/src/Service/Redirector.php b/client/app/src/Service/Redirector.php index 99e22d7f29..d2958a8cdf 100644 --- a/client/app/src/Service/Redirector.php +++ b/client/app/src/Service/Redirector.php @@ -99,27 +99,13 @@ public function getCorrectRouteIfDifferent(User $user, $currentRoute) { // Check if user has multiple clients $clients = !is_null($user->getDeputyUid()) ? $this->clientApi->getAllClientsByDeputyUid($user->getDeputyUid()) : []; - $multiClientDeputy = !is_null($clients) && count($clients) > 1; - - // Redirect to appropriate homepage - if (in_array($currentRoute, ['lay_home', 'ndr_index'])) { - if ($multiClientDeputy) { - $route = 'lay_home'; - } else { - $route = $user->isNdrEnabled() ? 'ndr_index' : 'lay_home'; - } - } // none of these corrections apply to admin if (!$user->hasAdminRole()) { if ($user->getIsCoDeputy()) { // already verified - shouldn't be on verification page if ('codep_verification' == $currentRoute && $user->getCoDeputyClientConfirmed()) { - if ($multiClientDeputy) { - $route = 'lay_home'; - } else { - $route = $user->isNdrEnabled() ? 'ndr_index' : 'lay_home'; - } + $route = 'lay_home'; } // unverified codeputy invitation @@ -169,7 +155,9 @@ private function getLayDeputyHomepage(User $user, $activeClientId = null, $enabl break; } - return $this->router->generate('report_create', ['clientId' => $user->getIdOfClientWithDetails()]); + if (!$user->isNdrEnabled()) { + return $this->router->generate('report_create', ['clientId' => $user->getIdOfClientWithDetails()]); + } } // check if last remaining active client is linked to non-primary account if so retrieve id diff --git a/client/app/templates/Ndr/Action/start.html.twig b/client/app/templates/Ndr/Action/start.html.twig index 783eaf1124..b2fdb13b48 100644 --- a/client/app/templates/Ndr/Action/start.html.twig +++ b/client/app/templates/Ndr/Action/start.html.twig @@ -10,7 +10,7 @@ {% block pageTitle %}{{ 'startPage.pageTitle' | trans }}{% endblock %} -{% block breadcrumbs %}{{ macros.breadcrumbs(ndr) }}{% endblock %} +{% block breadcrumbs %}{{ macros.breadcrumbs(ndr, isMultiClientDeputy) }}{% endblock %} {% block pageContent %} diff --git a/client/app/templates/Ndr/Asset/start.html.twig b/client/app/templates/Ndr/Asset/start.html.twig index 3ee5eaea1e..a7a207a377 100644 --- a/client/app/templates/Ndr/Asset/start.html.twig +++ b/client/app/templates/Ndr/Asset/start.html.twig @@ -10,7 +10,7 @@ {% block pageTitle %}{{ 'startPage.pageTitle' | trans }}{% endblock %} -{% block breadcrumbs %}{{ macros.breadcrumbs(ndr) }}{% endblock %} +{% block breadcrumbs %}{{ macros.breadcrumbs(ndr, isMultiClientDeputy) }}{% endblock %} {% block pageContent %} diff --git a/client/app/templates/Ndr/BankAccount/start.html.twig b/client/app/templates/Ndr/BankAccount/start.html.twig index e080088319..b77fe6daf3 100644 --- a/client/app/templates/Ndr/BankAccount/start.html.twig +++ b/client/app/templates/Ndr/BankAccount/start.html.twig @@ -10,7 +10,7 @@ {% block pageTitle %}{{ 'startPage.pageTitle' | trans(transOptions) }}{% endblock %} -{% block breadcrumbs %}{{ macros.breadcrumbs(ndr) }}{% endblock %} +{% block breadcrumbs %}{{ macros.breadcrumbs(ndr, isMultiClientDeputy) }}{% endblock %} {% block pageContent %} diff --git a/client/app/templates/Ndr/Debt/start.html.twig b/client/app/templates/Ndr/Debt/start.html.twig index 363b71e213..59ac23e848 100644 --- a/client/app/templates/Ndr/Debt/start.html.twig +++ b/client/app/templates/Ndr/Debt/start.html.twig @@ -11,7 +11,7 @@ {% block breadcrumbs %} - {{ macros.breadcrumbs(ndr) }} + {{ macros.breadcrumbs(ndr, isMultiClientDeputy) }} {% endblock %} {% block pageContent %} diff --git a/client/app/templates/Ndr/DeputyExpense/start.html.twig b/client/app/templates/Ndr/DeputyExpense/start.html.twig index 5a4a1968c0..793320023a 100644 --- a/client/app/templates/Ndr/DeputyExpense/start.html.twig +++ b/client/app/templates/Ndr/DeputyExpense/start.html.twig @@ -10,7 +10,7 @@ {% block pageTitle %}{{ 'startPage.pageTitle' | trans }}{% endblock %} -{% block breadcrumbs %}{{ macros.breadcrumbs(ndr) }}{% endblock %} +{% block breadcrumbs %}{{ macros.breadcrumbs(ndr, isMultiClientDeputy) }}{% endblock %} {% block pageContent %} diff --git a/client/app/templates/Ndr/IncomeBenefit/start.html.twig b/client/app/templates/Ndr/IncomeBenefit/start.html.twig index 1799a4b2dc..b17068d956 100644 --- a/client/app/templates/Ndr/IncomeBenefit/start.html.twig +++ b/client/app/templates/Ndr/IncomeBenefit/start.html.twig @@ -10,7 +10,7 @@ {% block pageTitle %}{{ 'startPage.pageTitle' | trans }}{% endblock %} -{% block breadcrumbs %}{{ macros.breadcrumbs(ndr) }}{% endblock %} +{% block breadcrumbs %}{{ macros.breadcrumbs(ndr, isMultiClientDeputy) }}{% endblock %} {% block pageContent %} diff --git a/client/app/templates/Ndr/Ndr/_review_buttons.html.twig b/client/app/templates/Ndr/Ndr/_review_buttons.html.twig index 4821f083cc..c6f9874db5 100644 --- a/client/app/templates/Ndr/Ndr/_review_buttons.html.twig +++ b/client/app/templates/Ndr/Ndr/_review_buttons.html.twig @@ -21,8 +21,8 @@ {% else %}
- {{ 'backToYourReports' | trans({}, 'common') }} + + {{ 'backToYourReports' | trans({}, 'common') }}
{% endif %} diff --git a/client/app/templates/Ndr/Ndr/declaration.html.twig b/client/app/templates/Ndr/Ndr/declaration.html.twig index f789d3b9b3..089951e037 100644 --- a/client/app/templates/Ndr/Ndr/declaration.html.twig +++ b/client/app/templates/Ndr/Ndr/declaration.html.twig @@ -12,6 +12,13 @@ {% block breadcrumbs %}