Skip to content

Commit

Permalink
Merge branch '11.x' of https://github.com/SU-SWS/stanford_profile int…
Browse files Browse the repository at this point in the history
…o 10.x
  • Loading branch information
pookmish committed Oct 20, 2023
2 parents 60af0bd + 7378e51 commit 8e1d298
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/EventSubscriber/EventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,17 @@ public function onKernelRequest(RequestEvent $event) {
protected static function redirectUser() {
$current_user = \Drupal::currentUser();
$cache = \Drupal::cache();
if ($cache_data = $cache->get('su_renew_site:' . $current_user->id())) {
return $cache_data->data;
}

/** @var \Drupal\Core\Routing\CurrentRouteMatch $route_match */
$route_match = \Drupal::service('current_route_match');
$name = $route_match->getCurrentRouteMatch()->getRouteName();
if (in_array($name, ['system.css_asset', 'system.js_asset'])) {
return FALSE;
}

if ($cache_data = $cache->get('su_renew_site:' . $current_user->id())) {
return $cache_data->data;
}

/** @var \Drupal\config_pages\ConfigPagesLoaderServiceInterface $config_page_loader */
$config_page_loader = \Drupal::service('config_pages.loader');
Expand All @@ -153,9 +157,8 @@ protected static function redirectUser() {

$site_manager = $current_user->hasPermission('edit stanford_basic_site_settings config page entity') && !in_array('administrator', $current_user->getRoles());

$ignore_routes = ['system.css_asset', 'system.js_asset'];
// If the renewal date has passed, they should be redirected.
$needs_renewal = !in_array($name, $ignore_routes) && !getenv('CI') && $site_manager && (strtotime($renewal_date) - time() < 60 * 60 * 24);
$needs_renewal = !getenv('CI') && $site_manager && (strtotime($renewal_date) - time() < 60 * 60 * 24);
$cache->set('su_renew_site:' . $current_user->id(), $needs_renewal, time() + 60 * 60 * 24);

return $needs_renewal;
Expand Down

0 comments on commit 8e1d298

Please sign in to comment.