From c8248d26683813cb60c5079f7372c737b7137146 Mon Sep 17 00:00:00 2001 From: Iqpal Mannan Date: Wed, 13 Nov 2024 14:45:42 +0000 Subject: [PATCH 01/38] NDR redirects to Lay Homepage --- client/app/src/Service/Redirector.php | 24 ++++++++++--------- .../tests/phpunit/Service/RedirectorTest.php | 8 +++---- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/client/app/src/Service/Redirector.php b/client/app/src/Service/Redirector.php index 99e22d7f29..9cb79f08a9 100644 --- a/client/app/src/Service/Redirector.php +++ b/client/app/src/Service/Redirector.php @@ -82,6 +82,8 @@ public function getFirstPageAfterLogin(SessionInterface $session) return $this->router->generate('org_dashboard'); } } elseif ($this->authChecker->isGranted(User::ROLE_LAY_DEPUTY)) { + file_put_contents('php://stderr', print_r('HELLOOOOO1: ', true)); + return $this->getCorrectLayHomepage(); } else { return $this->router->generate('access_denied'); @@ -103,11 +105,7 @@ public function getCorrectRouteIfDifferent(User $user, $currentRoute) // 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'; - } + $route = 'lay_home'; } // none of these corrections apply to admin @@ -115,11 +113,7 @@ public function getCorrectRouteIfDifferent(User $user, $currentRoute) 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 @@ -153,9 +147,13 @@ private function getLayDeputyHomepage(User $user, $activeClientId = null, $enabl { // checks if user has missing details or is NDR if ($route = $this->getCorrectRouteIfDifferent($user, 'lay_home')) { + file_put_contents('php://stderr', print_r('HELLOOOOO4: ', true)); + return $this->router->generate($route); } + file_put_contents('php://stderr', print_r('HELLOOOOO5: ', true)); + // last accessed url if ($enabledLastAccessedUrl && $lastUsedUri = $this->getLastAccessedUrl()) { return $lastUsedUri; @@ -169,7 +167,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 @@ -269,6 +269,8 @@ private function getCorrectLayHomepage() if (1 < count($clients)) { return $this->getChooseAClientHomepage($user); } else { + file_put_contents('php://stderr', print_r('HELLOOOOO3: ', true)); + return $this->getLayDeputyHomepage($user, $activeClientId); } } else { diff --git a/client/app/tests/phpunit/Service/RedirectorTest.php b/client/app/tests/phpunit/Service/RedirectorTest.php index d0ad8a750b..0225261aa7 100644 --- a/client/app/tests/phpunit/Service/RedirectorTest.php +++ b/client/app/tests/phpunit/Service/RedirectorTest.php @@ -105,17 +105,17 @@ public static function getCorrectRouteIfDifferentProvider() // ROLE, current_route, isCoDeputy, coDeputyClientConfirmed, isNdrEnabled, isDeputyOrg, clientKnown, hasAddress return [ // Same URLs never get redirected - ['ROLE_LAY_DEPUTY', 'ndr_index', false, false, true, false, true, true, false], + ['ROLE_LAY_DEPUTY', 'ndr_index', false, false, true, false, true, true, 'lay_home'], ['ROLE_LAY_DEPUTY', 'lay_home', false, false, false, false, true, true, false], // NDR deputy gets redirected to NDR index - ['ROLE_LAY_DEPUTY', 'lay_home', false, false, true, false, true, true, 'ndr_index'], + ['ROLE_LAY_DEPUTY', 'lay_home', false, false, true, false, true, true, false], // Lay deputy gets redirected to LAY ['ROLE_LAY_DEPUTY', 'ndr_index', false, false, false, false, true, true, 'lay_home'], // Correct URLs dont get redirected ['ROLE_LAY_DEPUTY', 'lay_home', false, false, false, false, true, true, false], - ['ROLE_LAY_DEPUTY', 'ndr_index', false, false, true, false, true, true, false], + ['ROLE_LAY_DEPUTY', 'ndr_index', false, false, true, false, true, true, 'lay_home'], // User without client gets redirected to client_add ['ROLE_LAY_DEPUTY', 'ndr_index', false, false, true, false, false, true, 'client_add'], @@ -130,7 +130,7 @@ public static function getCorrectRouteIfDifferentProvider() ['ROLE_LAY_DEPUTY', 'lay_home', true, false, false, false, true, false, 'codep_verification'], // Verified co deputies dont get redirected - ['ROLE_LAY_DEPUTY', 'ndr_index', true, true, true, true, true, false, false], + ['ROLE_LAY_DEPUTY', 'ndr_index', true, true, true, true, true, false, 'lay_home'], ['ROLE_LAY_DEPUTY', 'lay_home', true, true, false, false, true, false, false], // Admins are not redirected From 0423b908e9540f36c2cb0e8789349d4cb8f53ecc Mon Sep 17 00:00:00 2001 From: Iqpal Mannan Date: Wed, 13 Nov 2024 14:51:47 +0000 Subject: [PATCH 02/38] Combine NDR into Report Controller and Report index template --- .../Controller/Report/ReportController.php | 93 +++++++- .../templates/Report/Report/index.html.twig | 201 +++++++++++------- 2 files changed, 207 insertions(+), 87 deletions(-) diff --git a/client/app/src/Controller/Report/ReportController.php b/client/app/src/Controller/Report/ReportController.php index 388e49442b..74774c29d6 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,35 @@ 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(); + file_put_contents('php://stderr', print_r('USERS: ', true)); + file_put_contents('php://stderr', print_r($users, true)); + + // TEST WITH CO-DEPUTY AS WELL + foreach ($users as $user) { + if ($user->isNdrEnabled()) { + file_put_contents('php://stderr', print_r('NDR ENABLED: ', true)); + $ndrEnabled = true; + } + } + + // $hasReport = $this->clientApi->getById($clientId)->hasReport(); + // file_put_contents('php://stderr', print_r('ACTIVE REPORT: '. $hasReport, true)); + // + // if (!$hasReport) { + // } + + file_put_contents('php://stderr', print_r('NDR ENABLED VARIABLE: '.$ndrEnabled, true)); + + if ($ndrEnabled) { + $user = $this->userApi->getUserWithData(array_merge(self::$ndrGroupsForValidation, ['status'])); + } 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 +207,9 @@ 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->getUser()->isLayDeputy() && $this->clientApi->checkDeputyHasMultiClients( + $user->getDeputyUid() + ); // redirect if user has missing details or is on wrong page $route = $redirector->getCorrectRouteIfDifferent($user, 'lay_home'); @@ -163,16 +217,39 @@ public function clientHomepageAction(Redirector $redirector, string $clientId) return $this->redirectToRoute($route); } + if ($ndrEnabled) { + $clients = $user->getClients(); + $client = !empty($clients) ? $clients[0] : null; + } + $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) { + return array_merge([ + 'ndrEnabled' => true, + 'client' => $client, + 'ndr' => $client->getNdr(), + 'reportsSubmitted' => $client->getSubmittedReports(), + 'reportActive' => $client->getActiveReport(), + 'ndrStatus' => new NdrStatusService($client->getNdr()), + ], + $resultsArray + ); + } else { + return array_merge([ + 'ndrEnabled' => false, + 'client' => $clientWithCoDeputies, + ], + $resultsArray + ); + } } /** diff --git a/client/app/templates/Report/Report/index.html.twig b/client/app/templates/Report/Report/index.html.twig index a367fdc86b..b9ce7c2c83 100644 --- a/client/app/templates/Report/Report/index.html.twig +++ b/client/app/templates/Report/Report/index.html.twig @@ -20,90 +20,133 @@ {% block pageContent %} - {% if clientHasCoDeputies %} - {% include '@App/Report/Report/_codeputies.html.twig' with {coDeputies: coDeputies} %} - {% endif %} +{# ***** TRY INCLUDE NDR/INDEX.HTML.TWIG ******#} + {% if ndrEnabled %} + {% if clientHasCoDeputies %} + {% include '@App/Report/Report/_codeputies.html.twig' with {coDeputies: coDeputies} %} + {% endif %} - {% if client.unsubmittedReport %} - {% set report = client.unsubmittedReport %} - {% set status = report.status.status %} - {% set behatRegion = 'report-unsubmitted' %} - {% set buttonText = 'reviewReport' %} - {% set transOptions = { - '%startDate%': report.startDate | date("j F Y"), - '%endDate%': report.endDate | date("j F Y") - } %} -

{{ 'unsubmittedReport' | trans({}, 'common') }}

- {% embed '@App/Report/Report/_report_row.html.twig' %} - {% block bottomLeftContent %} - {{ (page ~ '.unsubmitted.reportPara') | trans(transOptions, translationDomain) }} - {% endblock %} - {% endembed %} - {% endif %} + {% if ndr.submitted %} - {# current report #} - {% if client.activeReport %} - {% set report = client.activeReport %} - {% set status = report.status.status %} - {% set behatRegion = 'report-active' %} - {% set buttonText = report.status.status != 'notStarted' ? 'continue' : 'startNow' %} - {% set transOptions = { - '%startDate%': report.startDate | date("j F Y"), - '%endDate%': report.endDate | date("j F Y") - } %} -

{{ 'currentDeputyReport' | trans({}, 'common') }}

- {% embed '@App/Report/Report/_report_row.html.twig' %} - {% block bottomLeftContent %} - {{ (page ~ '.editReportingPeriodPara') | trans(transOptions, translationDomain) }} - - {{ (page ~ '.editReportingPeriodLink') | trans({}, translationDomain) }} - - {% endblock %} - {% endembed %} - {% endif %} + {% if client.unsubmittedReport %} +

{{ 'unsubmittedReport' | trans({}, 'common') }}

+ {% include '@App/Ndr/Ndr/_report_row.html.twig' with { + reportActive: client.unsubmittedReport, + ndr: ndr, + } %} + {% endif %} + + {# always show the report row. If not created yet, a "Start" button will be shown #} +

{{ 'currentDeputyReport' | trans({}, 'common') }}

+ {% include '@App/Ndr/Ndr/_report_row.html.twig' with { + reportActive: reportActive, + ndr: ndr, + } %} + + {% include '@App/Ndr/Ndr/_report_history.html.twig' with { + reports: reportsSubmitted, + ndr: ndr, + } %} + + {% else %} + + {% include '@App/Ndr/Ndr/_ndr_row.html.twig' with { + reports: reportsSubmitted, + ndrStatus: ndrStatus, + } %} + +

{{ 'currentDeputyReport' | trans({}, 'common') }}

+ {% include '@App/Ndr/Ndr/_report_row.html.twig' with { + reportActive: reportActive, + ndr: ndr, + } %} + {% endif %} + {% else %} + {% if clientHasCoDeputies %} + {% include '@App/Report/Report/_codeputies.html.twig' with {coDeputies: coDeputies} %} + {% endif %} + + {% if client.unsubmittedReport %} + {% set report = client.unsubmittedReport %} + {% set status = report.status.status %} + {% set behatRegion = 'report-unsubmitted' %} + {% set buttonText = 'reviewReport' %} + {% set transOptions = { + '%startDate%': report.startDate | date("j F Y"), + '%endDate%': report.endDate | date("j F Y") + } %} +

{{ 'unsubmittedReport' | trans({}, 'common') }}

+ {% embed '@App/Report/Report/_report_row.html.twig' %} + {% block bottomLeftContent %} + {{ (page ~ '.unsubmitted.reportPara') | trans(transOptions, translationDomain) }} + {% endblock %} + {% endembed %} + {% endif %} + + {# current report #} + {% if client.activeReport %} + {% set report = client.activeReport %} + {% set status = report.status.status %} + {% set behatRegion = 'report-active' %} + {% set buttonText = report.status.status != 'notStarted' ? 'continue' : 'startNow' %} + {% set transOptions = { + '%startDate%': report.startDate | date("j F Y"), + '%endDate%': report.endDate | date("j F Y") + } %} +

{{ 'currentDeputyReport' | trans({}, 'common') }}

+ {% embed '@App/Report/Report/_report_row.html.twig' %} + {% block bottomLeftContent %} + {{ (page ~ '.editReportingPeriodPara') | trans(transOptions, translationDomain) }} + + {{ (page ~ '.editReportingPeriodLink') | trans({}, translationDomain) }} + + {% endblock %} + {% endembed %} + {% endif %} + + + {% if client.submittedReports %} +

{{ 'submittedReports' | trans({}, 'common') }}

- {% if client.submittedReports %} - -

{{ 'submittedReports' | trans({}, 'common') }}

- - - - - - - - - - - - {% for report in client.submittedReports %} - - - - - - - {% endfor %} - -
{{ (page ~ '.reportType') | trans }}{{ (page ~ '.reportingPeriod') | trans }}{{ (page ~ '.submissionDate') | trans }} - {{ 'actions' | trans({}, 'common') }} -
+ + + + + + + + + + + {% for report in client.submittedReports %} + + + + + + + {% endfor %} + +
{{ (page ~ '.reportType') | trans }}{{ (page ~ '.reportingPeriod') | trans }}{{ (page ~ '.submissionDate') | trans }} + {{ 'actions' | trans({}, 'common') }} +
+ {% endif %} {% endif %}