Skip to content
Snippets Groups Projects
Commit 23a6b327 authored by Kunal Sachdev's avatar Kunal Sachdev Committed by Ted Bowman
Browse files

Issue #3270736 by kunal.sachdev: Ensure new, changed or removed permissions...

Issue #3270736 by kunal.sachdev:  Ensure new, changed or removed permissions are in the correct state after an update
parent 422fc626
No related branches found
No related tags found
1 merge request!235Issue #3270736: Ensure new, changed or removed permissions are in the correct state after an update
changed permission:
title: 'permission'
deleted permission:
title: 'deleted permission'
changed permission:
title: 'changed permission'
added permission:
title: 'added permission'
...@@ -5,5 +5,6 @@ services: ...@@ -5,5 +5,6 @@ services:
- '@package_manager.path_locator' - '@package_manager.path_locator'
- '@state' - '@state'
- '@router.no_access_checks' - '@router.no_access_checks'
- '@user.permissions'
tags: tags:
- { name: event_subscriber } - { name: event_subscriber }
...@@ -8,6 +8,7 @@ use Drupal\package_manager\Event\PostDestroyEvent; ...@@ -8,6 +8,7 @@ use Drupal\package_manager\Event\PostDestroyEvent;
use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\StageEvent; use Drupal\package_manager\Event\StageEvent;
use Drupal\package_manager\PathLocator; use Drupal\package_manager\PathLocator;
use Drupal\user\PermissionHandlerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Routing\RouterInterface;
...@@ -37,6 +38,13 @@ class SystemChangeRecorder implements EventSubscriberInterface { ...@@ -37,6 +38,13 @@ class SystemChangeRecorder implements EventSubscriberInterface {
*/ */
private $router; private $router;
/**
* The permission handler service.
*
* @var \Drupal\user\PermissionHandlerInterface
*/
private $permissionHandler;
/** /**
* Constructs a SystemChangeRecorder object. * Constructs a SystemChangeRecorder object.
* *
...@@ -46,11 +54,14 @@ class SystemChangeRecorder implements EventSubscriberInterface { ...@@ -46,11 +54,14 @@ class SystemChangeRecorder implements EventSubscriberInterface {
* The state service. * The state service.
* @param \Symfony\Component\Routing\RouterInterface $router * @param \Symfony\Component\Routing\RouterInterface $router
* The router service. * The router service.
* @param \Drupal\user\PermissionHandlerInterface $permissionHandler
* The permission handler service.
*/ */
public function __construct(PathLocator $path_locator, StateInterface $state, RouterInterface $router) { public function __construct(PathLocator $path_locator, StateInterface $state, RouterInterface $router, PermissionHandlerInterface $permissionHandler) {
$this->pathLocator = $path_locator; $this->pathLocator = $path_locator;
$this->state = $state; $this->state = $state;
$this->router = $router; $this->router = $router;
$this->permissionHandler = $permissionHandler;
} }
/** /**
...@@ -78,6 +89,13 @@ class SystemChangeRecorder implements EventSubscriberInterface { ...@@ -78,6 +89,13 @@ class SystemChangeRecorder implements EventSubscriberInterface {
// Check if a route added in the updated module is available. // Check if a route added in the updated module is available.
$results['new route exists'] = $route_collection->get('updated_module.added') ? 'exists' : 'not exists'; $results['new route exists'] = $route_collection->get('updated_module.added') ? 'exists' : 'not exists';
$permissions = $this->permissionHandler->getPermissions();
// Check if changes to an existing permission are picked up.
$results['title of changed permission'] = $permissions['changed permission']['title'];
// Check if a permission removed from the updated module is not available.
$results['deleted permission exists'] = array_key_exists('deleted permission', $permissions) ? 'exists' : 'not exists';
// Check if a permission added in the updated module is available.
$results['new permission exists'] = array_key_exists('added permission', $permissions) ? 'exists' : 'not exists';
$phase = $event instanceof PreApplyEvent ? 'pre' : 'post'; $phase = $event instanceof PreApplyEvent ? 'pre' : 'post';
$this->state->set("system_changes:$phase", $results); $this->state->set("system_changes:$phase", $results);
} }
......
...@@ -74,6 +74,9 @@ class PackageUpdateTest extends TemplateProjectTestBase { ...@@ -74,6 +74,9 @@ class PackageUpdateTest extends TemplateProjectTestBase {
'path of changed route' => '/updated-module/changed/pre', 'path of changed route' => '/updated-module/changed/pre',
'deleted route exists' => 'exists', 'deleted route exists' => 'exists',
'new route exists' => 'not exists', 'new route exists' => 'not exists',
'title of changed permission' => 'permission',
'deleted permission exists' => 'exists',
'new permission exists' => 'not exists',
]; ];
$this->assertSame($expected_pre_apply_results, $results['pre']); $this->assertSame($expected_pre_apply_results, $results['pre']);
...@@ -88,6 +91,12 @@ class PackageUpdateTest extends TemplateProjectTestBase { ...@@ -88,6 +91,12 @@ class PackageUpdateTest extends TemplateProjectTestBase {
'deleted route exists' => 'not exists', 'deleted route exists' => 'not exists',
// Routes added to the updated module should be available. // Routes added to the updated module should be available.
'new route exists' => 'exists', 'new route exists' => 'exists',
// Title of the existing permission should be changed.
'title of changed permission' => 'changed permission',
// Permissions deleted from the updated module should not be available.
'deleted permission exists' => 'not exists',
// Permissions added to the updated module should be available.
'new permission exists' => 'exists',
]; ];
$this->assertSame($expected_post_apply_results, $results['post']); $this->assertSame($expected_post_apply_results, $results['post']);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment