Problem/Motivation

In times of decoupled drupal, site builders may decide that they don't really need the node module in their sites.

But there is a problem the access contentpermission is provided by the node module and there are several places where it is used to check access for non-node-related things.

In particular:

  • File module: '/file/progress/{key}'
  • System module: /machine_name/transliterate'
  • User module: The Who's new view.
  • Taxonomy module: The taxonomy module use it in TermAccessControlHandler which makes complicated to decouple it from the node module #2339235: Remove taxonomy hard dependency on node module

Proposed resolution

If the node module is not enabled the declare the access content permission in the system module.
This keeps the access content in the Node section of the permission where the other content permission are.

Remaining tasks

None.

User interface changes

None

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dagmar created an issue. See original summary.

dagmar’s picture

Status: Active » Needs review
FileSize
969 bytes

Let's see is this breaks something.

dagmar’s picture

Issue summary: View changes

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dagmar’s picture

Component: system.module » node system

Maybe this can be answered by the node maintainer. Btw, this is blocking my progress with: #2339235: Remove taxonomy hard dependency on node module

Wim Leers’s picture

Issue summary: View changes

IS refined.

Wim Leers’s picture

Component: node system » system.module
Status: Needs review » Reviewed & tested by the community
dawehner’s picture

+++ b/core/modules/system/system.permissions.yml
@@ -24,3 +24,5 @@ link to any page:
+  title: 'View published content'

❓ I'm wondering whether we could add a description which makes it clearer that this is not just about nodes

effulgentsia’s picture

Title: Move 'access content' permission from node module to system module » Core modules check node module's "access content" permission for displaying things that have nothing to do with nodes
Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs usability review
Parent issue: » #2870018: Should the 'access content' permission be used to control access to viewing configuration entities via REST

I'm not really sure we want to move the permission from node.module to system.module as #2 proposes. I haven't caught up on everything that's been written in #2870018: Should the 'access content' permission be used to control access to viewing configuration entities via REST yet, but for anyone else reviewing this, that would be a good place to start.

I do agree that it's currently a bug though for the places identified in this issue's Problem/Motivation section to be checking a permission that's defined in node.module. So we need to either move the permission, or else figure out one or more new permissions that would be more appropriate for those cases.

In trying to test what happens to those cases currently when node.module is uninstalled, I ran into the following quirks:

However, if I locally edit minimal.info.yml, comment out the - node dependency and install the profile that way, then I can get the following bugs:

  • Setup: Enable Views and add the Who's New block. Create a role and grant it all permissions. Create a user with that role and login as them.
  • Bug 1: This user can't see the Who's New block, because it requires "access content" permission, which was not granted during the setup,
    since node module isn't installed.
  • Bug 2: This user can create a new role, but on the page to do so, if they type in a role name with any non-ascii characters (such as from a non-English language), a machine name is not generated due to /machine_name/transliterate returning an access denied.
Wim Leers’s picture

or else figure out one or more new permissions that would be more appropriate for those cases.

This would be a BC break.

tedbow’s picture

I agree with #11 that creating new permissions for the current use cases would be BC break.

If we created new permissions we could in an update assign the new permissions to any role that currently role has 'access content' permission the new permissions we create. But I don't think that would cover BC concerns. Custom code and contrib could already have logic that checks for 'access content' permission for interacting with portions of their site that have to deal with viewing taxonomy with correct expectation that if they have that permission they will be able to view taxonomy terms.

Although I don't like the fact that we use 'access content' and we label nodes on the UI as 'content' and we use this permission for other things that aren't nodes I feel like we are stuck with it.

Wim Leers’s picture

Pinged yoroy on IRC. I'm tempted to move this back to RTBC, but #10 means we need sign-off from a usability maintainer.

yoroy’s picture

Not sure what to review. What's the decision or trade-off we're looking to make here?

seanB’s picture

Didn't even know all of the cases this permission was used. It is totally unclear that you grant access to other things than nodes when adding the permission for a user.
I agree separating the permission and creating new ones for the use cases that 'Access content' was abused is the real solution. I also see how this breaks BC.

If we are choosing to keep this permission and move it, I think we need to at least update the title as mentioned in #9.

One a side note:
Using 'Access content' for anything other than checking access to content (nodes) is wrong imho, so I wonder if we could think of a way to make this clear and fix this before Drupal 9.

Wim Leers’s picture

#14: short version: the reality is that the node module's access content permission is being used for a lot more than just granting access to nodes (== "content"). Therefore this issue proposes to move that permission from the node module to the system module, to reflect reality.
The question for you: is this okay from a usability POV?

#15: RE sidenote: no, fixing this before Drupal 9 would be a BC break. And fixing it not before 9, but in 9, would also be a BC break, per https://dri.es/making-drupal-upgrades-easy-forever.

yoroy’s picture

Issue tags: -Needs usability review

The issue summary says no user interface changes. If that's correct then I don't see how moving code around needs usability review. If it does change the UI or changes the meaning of what the permissions (don't) do or where people can find them then the issue summary needs an update.

tedbow’s picture

Issue summary: View changes
Issue tags: +Needs usability review

@yoroy re #17 I have updated summary to include the UI changes, namely a change on admin/people/permissions

Bojhan’s picture

Issue tags: -Needs usability review

I am not convinced this is good from a usability point of view. All content related permissions are there, and we would suddenly be splitting of just one - but the most binary one, to a different category - to support a >10% usecase.

I suggest we add logic, that in the case the "node" module is disabled, that we move it to "system".

tedbow’s picture

Updating with @Bojhan's suggestion.

I like this because it won't have an effect on vast majority of sites because most will have Node enabled.

Not providing a interdiff because no changes left from #2

Updated IS to reflect no "User interface changes" changes.

yoroy’s picture

Thanks for the review @bojhan, it captured my thoughts as well. Glad to see we can accomodate the suggested added logic, thanks @tedbow.

Status: Needs review » Needs work

The last submitted patch, 20: 2892821-20.patch, failed testing. View results

tedbow’s picture

Status: Needs work » Needs review
FileSize
475 bytes
2.11 KB
+++ b/core/modules/system/system.permissions.yml
@@ -24,3 +24,5 @@ link to any page:
+permission_callbacks:
+  - \Drupal\content_moderation\Permissions::transitionPermissions

Whoops copy/paste error forgot to update to reference new class in System module

Wim Leers’s picture

Status: Needs review » Needs work

Bojhan++ — that strikes a nice middle ground! ❤️

+++ b/core/modules/system/src/Permissions.php
@@ -0,0 +1,61 @@
+   * If the 'node' module is enabled this method will provide the

s/enabled/not installed/

tedbow’s picture

Status: Needs work » Needs review
FileSize
0 bytes
2.12 KB

@Wim Leers thanks for review. Fixed

tedbow’s picture

Issue summary: View changes

Update the summary to reflect the change to leave the permission in the node module but provide it in the system module if the node module is not enabled.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community
Wim Leers’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

I like the approach but it looks as though we're missing some test coverage.

+++ b/core/modules/system/src/Permissions.php
@@ -0,0 +1,61 @@
+        'title' => $this->t('View published content'),

Can of worms but the word "published" is extremely problematic here. I have no idea what to do about that.

Wim Leers’s picture

I like the approach but it looks as though we're missing some test coverage.

You'd like test coverage that shows that the access content permission is now available even when the node module is not yet installed, I think? Or is there something else you'd like to see tested?

Can of worms but the word "published" is extremely problematic here. I have no idea what to do about that.

Yes :( This is already problematic in HEAD. Legacy. Hard to fix. I do think this is out of scope here, since it's already a problem in HEAD. This issue/patch does not make the problem worse.

alexpott’s picture

Yep a test that shows the perm is still there when node is not is exactly what we need. And yes I agree that not dealing with the published can of worms is acceptable here.

zaporylie’s picture

Assigned: Unassigned » zaporylie

On it

zaporylie’s picture

The last submitted patch, 33: core_modules_check_node-2892821-33-test-only.patch, failed testing. View results

tedbow’s picture

@zaporylie thanks for the patch!

+++ b/core/modules/system/tests/src/Kernel/PermissionsTest.php
@@ -0,0 +1,45 @@
+    $permissions = $this->permissionHandler->getPermissions();
+    $this->assertArrayHasKey('access content', $permissions);

Instead of the checking for the check we could just check for
$permissions['access content']['provider'] === 'system'. Then we would still only need 1 assert but also confirm that system is providing it.

zaporylie’s picture

As you wish.

Probably no need to upload test-only patch again so I'm skipping it here for sake of DrupalCI.

tedbow’s picture

+++ b/core/modules/system/tests/src/Kernel/PermissionsTest.php
@@ -0,0 +1,45 @@
+/**
+ * @group Drupal
+ */

I think @group should be "system" here since Permissions.php is system module..

should we add @covers here?

zaporylie’s picture

I've used @group Drupal because neighbour test file within the same dir was using it (PathHooksTest.php). But I see now most of system Kernel tests use @group system so that should be probably changed. I'll add issue to address incorrect test group in PathHooksTest.php file.

Adding @covers for now - it can be removed on commit if not needed.

tedbow’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

@zaporylie looks great. RTBC again since was RTBC in #27

We now have tests per @alexpott's request in #29.

I agree with @Wim Leers in #29 that the 'View published content' permission string is existing problem and out of scope here

Wim Leers’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/system/tests/src/Kernel/PermissionsTest.php
@@ -0,0 +1,48 @@
+  public function testAccessContentPermission() {
+    $permissions = $this->permissionHandler->getPermissions();
+    $this->assertSame('system', $permissions['access content']['provider']);
+  }

I think this is a good start, but we want a bit more.

After this, install the node module, then check that the provider is 'node', not 'system'.

And then uninstall the node module, and check that the provider is again 'system'.

tedbow’s picture

Status: Needs work » Needs review
FileSize
1.37 KB
3.91 KB

@Wim Leers good point.

Here is this test changes. They aren't passing for me locally. I am not sure if I need to do anything besides install the module to get the permissions to reset.

Status: Needs review » Needs work

The last submitted patch, 41: 2892821-41.patch, failed testing. View results

Wim Leers’s picture

Status: Needs work » Needs review
FileSize
2.73 KB
3.95 KB

The reason #41 fails is pretty simple: you're using services from before the module was installed, i.e. without a rebuilt container. Converting this to a BrowserTestBase test will make that easier. Confusing indeed — I've pulled my hair out over this in the past.

Also fixed a bunch of nits.

Wim Leers’s picture

+++ b/core/modules/system/tests/src/Kernel/PermissionsTest.php
@@ -0,0 +1,44 @@
+   * Tests 'access content' permission existence.

Oh one more nit: s/existence/provider/

zaporylie’s picture

Status: Needs review » Needs work

Since you transformed Kernel test into Functional test, namespace should reflect that change.

alexpott’s picture

Status: Needs work » Needs review
FileSize
1.8 KB
3.78 KB

It can still be a KernelTestbBase - in fact it is slightly easier with a KTB because its container gets updated when the container is rebuilt via the module installer.

Fixed #44 too. And #45 - because it is a KTB again :)

alexpott’s picture

Just a comment on the earlier patches:

+++ b/core/modules/system/tests/src/Kernel/PermissionsTest.php
@@ -0,0 +1,65 @@
+    $this->permissionHandler = $this->container->get('user.permissions');
+    $this->moduleInstaller = $this->container->get('module_installer');

This type of storing a service on the test class is not a great pattern. It is super vulnerable to container rebuilds and things not being in-sync and not testing what you think it does.

zaporylie’s picture

Thanks @alexpott for your patch (#46), and even more for taking the time to comment on container handling in tests classes (#47) - much appreciated!

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

@alexpott++++++ I tried to achieve that for 10 minutes, but failed, figured that #43 was still a step forward :) Thanks for the explanation! ❤️

tedbow’s picture

ditto @alexpott++ thanks for the explanations!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

This is going to be tricky for #2026983: [regression] Grants for permissions defined by a module are not revoked / removed from Role config entities when that module is uninstalled / #2571235: [regression] Roles should depend on objects that are building the granted permissions since they are removing permissions when modules are uninstalled. At least for the version that uses proper config dependencies to manage this I think we might have to hard code something special.

It'd be best if the permission could just be in the system module - the whole moving to the node module so that to keep the tickbox in the node section when the node module is installed is a bit icky. Maybe we could move it to system and change the title? Not sure. Very tricky. Or maybe just hack the form to special case it and not do the whole shimmy with the code. In fact, thinking about it I'd way prefer the permission to always by provided by system and the weird logic to list in the node permissions to be in the form,

alexpott’s picture

The reason for my preference is once roles get proper config dependencies this will make everything much simpler.

alexpott’s picture

Status: Needs work » Needs review
FileSize
6.49 KB
5.72 KB

Here's a patch that maintains the position but ensures that the permission is always provided by system.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

WFM!

xjm’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

I'd ask for node access maintainer signoff; fortunately that's me. +1 for this approach.

I don't think there should be any BC impacts from this as System module can't be disabled, but let's provide a CR to inform developers?

alexpott’s picture

Priority: Normal » Major
Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs change record
Related issues: +#2571235: [regression] Roles should depend on objects that are building the granted permissions
xjm’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +Needs followup

Committed and pushed to 8.5.x, and published the change record.

Wim Leers’s picture

YAYYYYYYY!!!!!!!!!!!! I'm working on the follow-ups.

  • xjm committed a8e7de3 on 8.5.x
    Issue #2892821 by tedbow, zaporylie, alexpott, Wim Leers, dagmar, yoroy...
Anonymous’s picture

🙏 Great idea, implementation and commit! 🚀🚀🚀

Wim Leers’s picture

Wim Leers’s picture

Issue tags: -Needs followup

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.