Skip to content
Snippets Groups Projects
Commit a8e7de39 authored by Jess's avatar Jess
Browse files

Issue #2892821 by tedbow, zaporylie, alexpott, Wim Leers, dagmar, yoroy,...

Issue #2892821 by tedbow, zaporylie, alexpott, Wim Leers, dagmar, yoroy, effulgentsia, Bojhan: Core modules check node module's "access content" permission for displaying things that have nothing to do with nodes
parent 1e850835
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -12,8 +12,6 @@ administer nodes:
restrict access: true
access content overview:
title: 'Access the Content overview page'
access content:
title: 'View published content'
view own unpublished content:
title: 'View own unpublished content'
view all revisions:
......
......@@ -15,6 +15,10 @@ access site in maintenance mode:
view the administration theme:
title: 'View the administration theme'
description: 'This is only used when the site is configured to use a separate administration theme on the Appearance page.'
# Note that the 'access content' permission is moved to the Node section of the
# permission form when the Node module is enabled.
access content:
title: 'View published content'
access site reports:
title: 'View site reports'
restrict access: true
......
<?php
namespace Drupal\Tests\system\Kernel;
use Drupal\KernelTests\KernelTestBase;
/**
* @group system
*/
class PermissionsTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'system',
'user',
];
/**
* Tests the 'access content' permission is provided by the System module.
*/
public function testAccessContentPermission() {
// Uninstalling modules requires the users_data table to exist.
$this->installSchema('user', ['users_data']);
$permissions = $this->container->get('user.permissions')->getPermissions();
$this->assertSame('system', $permissions['access content']['provider']);
// Install the 'node' module, assert that it is now the 'node' module
// providing the 'access content' permission.
$this->container->get('module_installer')->install(['node']);
$permissions = $this->container->get('user.permissions')->getPermissions();
$this->assertSame('system', $permissions['access content']['provider']);
// Uninstall the 'node' module, assert that it is again the 'system' module.
$this->container->get('module_installer')->uninstall(['node']);
$permissions = $this->container->get('user.permissions')->getPermissions();
$this->assertSame('system', $permissions['access content']['provider']);
}
}
......@@ -129,6 +129,21 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$permissions_by_provider[$permission['provider']][$permission_name] = $permission;
}
// Move the access content permission to the Node module if it is installed.
if ($this->moduleHandler->moduleExists('node')) {
// Insert 'access content' before the 'view own unpublished content' key
// in order to maintain the UI even though the permission is provided by
// the system module.
$keys = array_keys($permissions_by_provider['node']);
$offset = (int) array_search('view own unpublished content', $keys);
$permissions_by_provider['node'] = array_merge(
array_slice($permissions_by_provider['node'], 0, $offset),
['access content' => $permissions_by_provider['system']['access content']],
array_slice($permissions_by_provider['node'], $offset)
);
unset($permissions_by_provider['system']['access content']);
}
foreach ($permissions_by_provider as $provider => $permissions) {
// Module name.
$form['permissions'][$provider] = [
......
......@@ -164,4 +164,24 @@ public function testUserRoleChangePermissions() {
$this->assertNotEqual($previous_permissions_hash, $current_permissions_hash, 'Permissions hash has changed.');
}
/**
* Verify 'access content' is listed in the correct location.
*/
public function testAccessContentPermission() {
$this->drupalLogin($this->adminUser);
// When Node is not installed the 'access content' permission is listed next
// to 'access site reports'.
$this->drupalGet('admin/people/permissions');
$next_row = $this->xpath('//tr[@data-drupal-selector=\'edit-permissions-access-content\']/following-sibling::tr[1]');
$this->assertEqual('edit-permissions-access-site-reports', $next_row[0]->attributes()['data-drupal-selector']);
// When Node is installed the 'access content' permission is listed next to
// to 'view own unpublished content'.
\Drupal::service('module_installer')->install(['node']);
$this->drupalGet('admin/people/permissions');
$next_row = $this->xpath('//tr[@data-drupal-selector=\'edit-permissions-access-content\']/following-sibling::tr[1]');
$this->assertEqual('edit-permissions-view-own-unpublished-content', $next_row[0]->attributes()['data-drupal-selector']);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment