Skip to content

Commit

Permalink
CDPT-1939: Splash page (#800)
Browse files Browse the repository at this point in the history
* CDPT-1939: Splash page
- Redirect users to a simplified version of the agency switcher when they don't have a cookie set.
- Allow users access to the accessibility and privacy policy pages before setting a cookie, but use the simplified header

* CDPT-1939: Splash page
- Redirect users to a simplified version of the agency switcher when they don't have a cookie set.
- Allow users access to the accessibility and privacy policy pages before setting a cookie, but use the simplified header

* CDPT-1939: Splash page
- Redirect users to a simplified version of the agency switcher when they don't have a cookie set.
- Allow users access to the accessibility and privacy policy pages before setting a cookie, but use the simplified header

* CDPT-1939: Splash page
- Refine agency-switcher function and separate internal and external agencies
- Add param to redirect users once they've selected an agency
- Update the agency list to reflect hardcoded agency-switcher values
- Wrap agency switcher list in <nav>

* CDPT-1939: Splash page
- Add ima to agency switcher

* CDPT-1939: Splash page
- Validate send_back url
- Move comments to docblock

* CDPT-1939: Splash page
- Remove HTTP_REFERER as it doesn't appear to do anything

* CDPT-1939: Splash page
- Reverse if condition
  • Loading branch information
EmilyHazlehurst authored Jan 31, 2025
1 parent b04afa5 commit d0c8941
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 101 deletions.
27 changes: 21 additions & 6 deletions public/app/themes/clarity/agency-switcher.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
<?php

use MOJ\Intranet\Agency;

/*
* Agency switcher
*/
get_header();
?>

<main id="maincontent" class="u-wrapper l-main t-agency-switcher" role="main">
<h1 class="o-title o-title--page">Choose your agency or body</h1>
<p>Other agencies and bodies have their own specific intranet content available to view by visiting the links below. HMPPS and YJB links are external intranet websites not managed by this central MoJ intranet.</p>
<?php get_template_part('src/components/c-intranet-switcher/view'); ?>
</main>
$oAgency = new Agency();
$simpleHeader = !$oAgency->hasAgencyCookie();

$heading = 'Choose the version of the intranet you want to see';
$body = null;
// If we're using the simple header, assume a new user and change the intro text to reflect this
if ($simpleHeader) {
$heading = 'Welcome to the Ministry of Justice intranet';
$body = '<p>Choose the version you want to see.</p><p>You can change this at any time using the "Switch to other
intranet" link at the top of any page.</p>';
}
?>
<main id="maincontent" class="u-wrapper l-main t-agency-switcher" role="main">
<h1 class="o-title o-title--page">
<?= $heading ?>
</h1>
<?= $body ? "<p>$body</p>" : '' ?>
<?php get_template_part('src/components/c-intranet-switcher/view'); ?>
</main>
<?php
get_footer();
52 changes: 43 additions & 9 deletions public/app/themes/clarity/inc/agency.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function getList()
* - label (string) - Text label for the link
* - classes (string) (optional) - Classes for the HTML element
* - is_external (boolean) - Is this a link to an external site?
* - main (boolean) - Should this link be used for the agency switcher?
* - has_archive (boolean) (optional) - is the intranet archive available for this agency?
*/

Expand Down Expand Up @@ -72,8 +73,9 @@ public function getList()
'is_integrated' => false,
'links' => [
[
'url' => 'https://intranet.noms.gsi.gov.uk/',
'url' => 'https://justiceuk.sharepoint.com/sites/HMPPSIntranet',
'label' => 'HM Prison & Probation Service intranet',
'main' => true,
'is_external' => true
]
]
Expand All @@ -90,14 +92,8 @@ public function getList()
'shortcode' => 'law-commission',
'label' => 'Law Commission',
'abbreviation' => 'LawCom',
'is_integrated' => false,
'links' => [
[
'url' => 'http://lawcommission.intranet.service.justice.gov.uk/',
'label' => 'Law Commission intranet',
'is_external' => true
]
]
'is_integrated' => true,
'links' => []
],
'laa' => [
'shortcode' => 'laa',
Expand Down Expand Up @@ -155,6 +151,36 @@ public function getList()
'is_integrated' => true,
'contact_email_address' => '[email protected]',
'links' => []
],
'ima' => [
'shortcode' => 'ima',
'label' => 'Independent Monitoring Authority',
'abbreviation' => 'IMA',
'is_integrated' => false,
'contact_email_address' => '',
'links' => [
[
'url' => 'https://myima.ima-citizensrights.org.uk',
'label' => 'Independent Monitoring Authority intranet',
'main' => true,
'is_external' => true
]
]
],
'yjbrh' => [
'shortcode' => 'yjbrh',
'label' => 'Youth Justice Board Resource Hub',
'abbreviation' => 'YJBRH',
'is_integrated' => false,
'contact_email_address' => '',
'links' => [
[
'url' => 'https://yjresourcehub.uk/',
'label' => 'Youth Justice Board Resource Hub intranet',
'main' => true,
'is_external' => true
]
]
]
];

Expand All @@ -169,6 +195,14 @@ public function getList()
return $agencies_array;
}

/*
* Check if the agency cookie is set
*/
public function hasAgencyCookie(): bool
{
return !empty($_COOKIE['dw_agency']);
}

/***
* Get the agency from cookie, and make sure it's in
* the list, otherwise default to HQ
Expand Down
48 changes: 31 additions & 17 deletions public/app/themes/clarity/inc/cookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*/
add_action('wp', function () {
$agency_default = 'hq';
$agency = $_GET['agency'] ?? false;
$agency_param = $_GET['agency'] ?? false;
$agencies = new Agency();

$options = [
'expires' => time() + (3650 * DAY_IN_SECONDS),
Expand All @@ -20,30 +21,43 @@
if (!empty($_SERVER["HTTPS"])) {
$options['secure'] = true;
}
// If the agency param is set, set the dw_agency cookie and return
if ($agency_param) {
$agency = trim($agency_param);

$agencies = new Agency();
if ($agency) {
// tidy up
$agency = trim($agency);

// If the agency is not valid, set it to the default agency ('hq')
if (!$agencies->agencyExists($agency)) {
$agency = $agency_default;
}

// set a cookie with an agency defined by the user
setcookie('dw_agency', $agency, $options);
$_COOKIE['dw_agency'] = $agency;

// else fires if agency is false and
// a dw_agency cookie does not exist
} else {
$agency = $_COOKIE['dw_agency'] ?? '';

if (!$agencies->agencyExists($agency)) {
setcookie('dw_agency', $agency_default, $options);
$_COOKIE['dw_agency'] = $agency_default;
}
// Return
return;
}
// Otherwise, check if the agency cookie is already set
$agency = $_COOKIE['dw_agency'] ?? '';
$slug = get_post_field('post_name');

if (
// If the agency cookie is set and is a valid agency
$agencies->agencyExists($agency) ||
// Or the current page is the agency switcher, privacy notice, or accessibility page
in_array($slug, ['agency-switcher', 'privacy-notice', 'accessibility'], true) ||
// Or the user is logged in
is_user_logged_in() ||
// Or we are in the admin area
(is_admin() || wp_doing_ajax() || wp_doing_cron())
) {
// Do nothing and return
return;
}
$url = '/agency-switcher';
// Set the send_back param so that we can send the user back to the current page after selecting an agency
$url = add_query_arg(['send_back' => urlencode(get_permalink())], $url);
// Redirect to the agency switcher page
wp_safe_redirect($url);
exit;
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@

.c-header-container {
margin-bottom: $spacing;

&--underlined {
border-bottom: 10px solid $defaultAgencyColour;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
<header class="c-header-container" role="banner">
<?php

use MOJ\Intranet\Agency;

$oAgency = new Agency();

// Show a simplified header if the user has not yet chosen an agency
$simpleHeader = !$oAgency->hasAgencyCookie();

?>
<header class="c-header-container<?= $simpleHeader ? " c-header-container--underlined" : ""?>" role="banner">

<?php
// Hide the search bar and main nav bar if hideHeader is set, e.g. on first login before the user has chosen an agency
get_template_part('src/components/c-logo-bar/view');
get_template_part('src/components/c-search-bar/view');
get_template_part('src/components/c-main-nav-bar/view');
?>

if (!$simpleHeader) {
get_template_part('src/components/c-search-bar/view');
get_template_part('src/components/c-main-nav-bar/view');
}
?>
<!--[if lte IE 9]>
<div class="u-message u-message--warning">
You are using an old browser that may impact your web browsing experience. It is recommended you switch to use Firefox or a modern version of Internet Explorer if possible.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
clearfix();
&__switch {
margin-bottom: $spacing;
+above(m) {
column(1, $cycle: 1)
}

a {
display: block;
//background-color: $boxBg;
padding: $spacing*.5;
padding-left: 0;
color: $text-colour;
//border: 2px solid $boxBg;
font-size: $outerCore;
Expand All @@ -28,10 +26,16 @@
//border: 2px solid $boxBg;
}
}


}



&__list-element {
margin-bottom: $spacing*2;
&:last-child {
margin-bottom: 0;
}
}
&__heading {
font-size: $outerCore;
margin-bottom: 0 !important;
}
}
Loading

0 comments on commit d0c8941

Please sign in to comment.