summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxjm2017-11-07 05:04:50 -0600
committerxjm2017-11-07 05:04:50 -0600
commita8e7de393b2b628714929a075402d9290ff473e2 (patch)
tree240c1e0da744aae8545ba1bb60337780784f6b51
parent1e850835d993fa794e0da63ab3abc7fea46ca5d3 (diff)
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
-rw-r--r--core/modules/node/node.permissions.yml2
-rw-r--r--core/modules/system/system.permissions.yml4
-rw-r--r--core/modules/system/tests/src/Kernel/PermissionsTest.php44
-rw-r--r--core/modules/user/src/Form/UserPermissionsForm.php15
-rw-r--r--core/modules/user/src/Tests/UserPermissionsTest.php20
5 files changed, 83 insertions, 2 deletions
diff --git a/core/modules/node/node.permissions.yml b/core/modules/node/node.permissions.yml
index 289227c..e60102b 100644
--- a/core/modules/node/node.permissions.yml
+++ b/core/modules/node/node.permissions.yml
@@ -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:
diff --git a/core/modules/system/system.permissions.yml b/core/modules/system/system.permissions.yml
index 726c295..c2e668a 100644
--- a/core/modules/system/system.permissions.yml
+++ b/core/modules/system/system.permissions.yml
@@ -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
diff --git a/core/modules/system/tests/src/Kernel/PermissionsTest.php b/core/modules/system/tests/src/Kernel/PermissionsTest.php
new file mode 100644
index 0000000..fdd69f5
--- /dev/null
+++ b/core/modules/system/tests/src/Kernel/PermissionsTest.php
@@ -0,0 +1,44 @@
+<?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']);
+ }
+
+}
diff --git a/core/modules/user/src/Form/UserPermissionsForm.php b/core/modules/user/src/Form/UserPermissionsForm.php
index daa879a..7d3adaa 100644
--- a/core/modules/user/src/Form/UserPermissionsForm.php
+++ b/core/modules/user/src/Form/UserPermissionsForm.php
@@ -129,6 +129,21 @@ class UserPermissionsForm extends FormBase {
$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] = [
diff --git a/core/modules/user/src/Tests/UserPermissionsTest.php b/core/modules/user/src/Tests/UserPermissionsTest.php
index 4f9e260..51fdebe 100644
--- a/core/modules/user/src/Tests/UserPermissionsTest.php
+++ b/core/modules/user/src/Tests/UserPermissionsTest.php
@@ -164,4 +164,24 @@ class UserPermissionsTest extends WebTestBase {
$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']);
+ }
+
}