Compare commits

...

2 Commits

Author SHA1 Message Date
5a6bee81cd redirect home page by permission 2022-07-10 14:15:13 +01:00
c790e6af61 added specific permission 4 "add new things" menu 2022-07-10 14:02:53 +01:00
4 changed files with 72 additions and 4 deletions

View File

@ -2,4 +2,8 @@ use opencase:
title: 'Use OpenCase' title: 'Use OpenCase'
description: 'Use the OpenCase case management system' description: 'Use the OpenCase case management system'
restrict access: true restrict access: true
view opencase add new things menu:
title: 'View OpenCase "add new things" menu'
description: 'View OpenCase "add new things" menu'
restrict access: true

View File

@ -5,12 +5,12 @@ opencase.opencase_admin_menu:
opencase.opencase_cases_menu: opencase.opencase_cases_menu:
path: '/' path: '/'
requirements: requirements:
_permission: 'use opencase' _permission: 'view all published case entities'
opencase.opencase_add_new_things_menu: opencase.opencase_add_new_things_menu:
path: '/' path: '/'
requirements: requirements:
_permission: 'use opencase' _permission: 'view add new things menu'
opencase.opencase_reporting_menu: opencase.opencase_reporting_menu:
path: '/' path: '/'
requirements: requirements:
_permission: 'use opencase' _permission: 'view reporting menu'

View File

@ -6,3 +6,8 @@ services:
# Priority determines the order in which Breadcrumb services run. # Priority determines the order in which Breadcrumb services run.
tags: tags:
- { name: breadcrumb_builder, priority: 100 } - { name: breadcrumb_builder, priority: 100 }
opencase.subscriber:
class: Drupal\opencase\EventSubscriber\OpencaseSubscriber
tags:
- { name: event_subscriber }

View File

@ -0,0 +1,59 @@
<?php
namespace Drupal\opencase\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Drupal\Core\Url;
/**
* Class OpencaseSubscriber.
*
* @package Drupal\opencase\EventSubscriber
*/
class OpencaseSubscriber implements EventSubscriberInterface {
private $alternativeHomePage = '/opencase/actors/client';
/**
* Registers the methods in this class that should be listeners.
*
* @return array
* An array of event listener definitions.
*/
public static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = ['onRequest'];
return $events;
}
/**
* Manipulates the request object.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The Event to process.
*/
public function onRequest(GetResponseEvent $event): void {
if ($this->requestIsForHomePage($event) && $this->currentUserShouldBeDirectedToAlternativeHomePage()){
$this->redirectToAlternativeHomePage($event);
}
}
private function requestIsForHomePage($event):bool {
return $event->getRequest()->getRequestUri() == '/';
}
private function currentUserShouldBeDirectedToAlternativeHomePage():bool {
return $this->currentUserCanSeeAllCases();
}
private function currentUserCanSeeAllCases():bool {
return \Drupal::currentUser()->hasPermission('view all published case entities');
}
private function redirectToAlternativeHomePage(GetResponseEvent $event):void {
$redirect_target_url = Url::fromUserInput($this->alternativeHomePage);
$response = new RedirectResponse($redirect_target_url->setAbsolute()->toString());
$event->setResponse($response);
}
}