Postponed

According to #2350615: [policy, no patch] What changes can be accepted during the Drupal 8 beta phase?, this should be postponed to Drupal 9.
Changing the permission's machine name may require changes across many patches in order to make them consistent and it affects all contrib modules. It is essentially aesthetic.

Problem/Motivation

Drupal currently uses permission with machine names like access all views, and this is inconsistent with machine names found elsewhere in Drupal (where the convention is snake_case_with_underscores. To add to the confusion, some permissions have a mixture of spaces and underscores (such as permissions for particular node types, etc.).

Finally, as permissions are now defined in YAML (see #2295469: Add support for static permission definitions with *.permissions.yml), then permissions keys will need to be quoted, and will not match most other YAML keys as seen in Drupal configuration. #2328411: Convert all permissions to yml files and permission callbacks is going to do the full conversion from hook_permission() to YAML, so once that's complete, this issue can be opened.

Proposed resolution

Enforce proper machine names like access_all_views instead of the machine names with spaces for all permissions.

Remaining tasks

Convert all permission names to machine names. While doing a find-and-replace, pay special attention to comments. Be sure to rename direct references to the permission machine name only, not references to the permission. An imaginary example of the correct way: "Be sure the user can access nodes by granting the access_nodes permission.":

  • action.permissions.yml
  • aggregator.permissions.yml
  • ban.permissions.yml
  • block.permissions.yml
  • book.permissions.yml
  • comment.permissions.yml
  • config.permissions.yml
  • config_translation.permissions.yml
  • contact.permissions.yml
  • content_translation.permissions.yml
  • contextual.permissions.yml
  • field_test.permissions.yml
  • field_ui.permissions.yml
  • file.permissions.yml
  • filter.permissions.yml
  • forum.permissions.yml
  • image.permissions.yml
  • language.permissions.yml
  • locale.permissions.yml
  • menu_ui.permissions.yml
  • node.permissions.yml
  • node_access_test.permissions.yml
  • path.permissions.yml
  • quickedit.permissions.yml
  • responsive_image.permissions.yml
  • rest.permissions.yml
  • search.permissions.yml
  • shortcut.permissions.yml
  • simpletest.permissions.yml
  • statistics.permissions.yml
  • system.permissions.yml
  • entity_test.permissions.yml
  • form_test.permissions.yml
  • module_test.permissions.yml
  • router_test.permissions.yml
  • taxonomy.permissions.yml
  • toolbar.permissions.yml
  • tour.permissions.yml
  • user.permissions.yml
  • views_test_data.permissions.yml
  • views.permissions.yml
  • views_ui.permissions.yml

Create a custom exception for non-compliant permission names.

Document the requirements for machine names.

User interface changes

None.

API changes

Permissions should only use machine names.

Comments

xjm’s picture

Issue tags: +rc deadline
xjm’s picture

Just a note that the first thing we'd probably want to change would be:
'restrict access': TRUE

xjm’s picture

geerlingguy’s picture

Is the restrict access/restrict_access change out of scope for this issue, though? It's not a permission name, just a key for defined permissions...

dawehner’s picture

I think it should not be out of scope ... given that we have to touch nearly all permissions.

xjm’s picture

Or rather, it could be a separate issue before this one. But it doesn't make sense to change all the machine names to get rid of quoting/spaces for permissions if we're still using it for something that's rather more machine-y than the permission names. :)

geerlingguy’s picture

Issue summary: View changes
Status: Postponed » Active
Related issues: +#2328411: Convert all permissions to yml files and permission callbacks

Updating issue status based on #2295469: Add support for static permission definitions with *.permissions.yml being committed (yay!).

geerlingguy’s picture

Status: Active » Postponed
dawehner’s picture

Given that you can have keys without any quotes in YML I wonder whether we still want to proceed with this issue.

sun’s picture

I agree with #9. I think we should only consider to remove the quotes around the keys, but that's a separate issue/discussion.


That said, given that this issue seemingly suggested to change all permission names:

We once had a major proposal to properly namespace all permission IDs by owner/module and introduce a hierarchical notation; i.e.:

entity.user.register
entity.user.create
entity.user.edit.own
entity.user.edit.any
entity.user.delete
entity.user.cancel
entity.node.create
entity.node.edit.own
...

#381584: Hierarchical Permissions System
#1200572: Concept of a hierarchical permission system
https://groups.drupal.org/node/205928, https://groups.drupal.org/node/154054

geerlingguy’s picture

Changing from verb-subject names (like "do xyz") to hierarchical properties might make some sense (though the machine name would then be further divorced from their descriptions on the permissions page), but wouldn't necessarily be related to using machine names (no spaces) in general.

I'm split on whether this issue should exist anymore. I still contend that it's a major Drupalism to have permission machine names with spaces in them, and since Drupal 7 split the machine name from the label on the roles/permissions page, the spaces still grate on me :P

  • Django uses a hierarchical system (myuser.groups.add: [groups/users]
  • Wordpress uses a verb-subject machine name with snake_case (publish_posts)
  • MediaWiki uses a (somewhat strange) hierarchical system ($wgGroupPermissions['user']['read'] = true;

These were a few examples I found—it seems more 'designed' systems tend to favor the hierarchical definition, and it would also mesh well with the other config changes in Drupal 8.

Also, it seems I don't have permission to leave a comment on #1200572: Concept of a hierarchical permission system, but I think a proper comparison between Drupal and other CMSes would be helpful in that discussion...

xjm’s picture

So for some reason I failed to write out my reasoning for why it would be okay to break all the permission names right up until RC1, which is what my tagging would imply. Talk about a noisy change between betas! At least, it would be best to have this by beta 1 if we are going to do it, and it might actually be a beta deadline. But I'm not sure from #1 and #3 whether I discussed it with catch or not. xjm--

Dot namespaces are scope creep IMO. While I see the appeal and logic of the suggested patterns, we've already decided not to make the effort to do those conversions in other subsystems. Let's just replace the spaces with underscores and be done with it, if we want to do this at all.

dawehner’s picture

Dot namespaces are scope creep IMO. While I see the appeal and logic of the suggested patterns, we've already decided not to make the effort to do those conversions in other subsystems. Let's just replace the spaces with underscores and be done with it, if we want to do this at all.

100% agreed.

Well, one reason why this issue was started, was that we didn't knew that keys with spaces don't require quotes ... so writing those yml files is actually less hard, as well as the readability doesn't sucks
completely.

Crell’s picture

I had originally proposed hierarchical permissions years ago, but it never caught on. I agree that it's too late to do that for Drupal 8. Let's just s/ /_/ in the permission "machine name" for consistency and call it a day for now.

andrewmacpherson’s picture

Status: Postponed » Needs work

Per comment #8, #2328411: Convert all permissions to yml files and permission callbacks is complete and this is also tagged RC deadline, so marking active.

andrewmacpherson’s picture

Issue summary: View changes

updating remaining tasks in issue summary.

cilefen’s picture

Status: Needs work » Needs review
Issue tags: +Novice
StatusFileSize
new51.36 KB

Of the module permissions, I got through the first four:

  • action.permissions.yml
  • aggregator.permissions.yml
  • ban.permissions.yml
  • block.permissions.yml
cilefen’s picture

Status: Needs review » Needs work

I think it makes sense to throw an exception in PermissionHandler if a non-machine name permission key is set.

cilefen’s picture

Status: Needs work » Needs review
StatusFileSize
new1.14 KB
new52.61 KB

This patch actually enforces the machine name. I don't know the generally-accepted regex or if there is a core function already. It throws a simple exception. We should create a custom exception.

cilefen’s picture

Issue summary: View changes
StatusFileSize
new8.06 KB
new60.08 KB

I changed permissions for the book module. Note that it is normal for install to fail at this stage because the machine-name detection check introduced in this issue throws an exception.

cilefen’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: +Needs tests
StatusFileSize
new1.78 KB
new60.74 KB

I added the custom exception.

gaurav.goyal’s picture

Assigned: Unassigned » gaurav.goyal

changing permissions for comment.permissions.yml file.

mcdruid’s picture

working on permissions in config.permissions.yml

gaurav.goyal’s picture

Assigned: gaurav.goyal » Unassigned
Status: Needs work » Needs review
StatusFileSize
new86.35 KB
new86.35 KB

comment.permissions.yml permissions changed.

gaurav.goyal’s picture

StatusFileSize
new86.35 KB
new144.01 KB

Here are the correct patch, Please ignore previous one.

mcdruid’s picture

Issue summary: View changes
StatusFileSize
new153.16 KB
new8.68 KB

config.permissions.yml changed

gaurav.goyal’s picture

Assigned: Unassigned » gaurav.goyal

changing config_translation.permissions.yml permissions

gaurav.goyal’s picture

Assigned: gaurav.goyal » Unassigned
Issue summary: View changes
StatusFileSize
new158.99 KB
new6.92 KB

config_translation.permissions.yml changed.

gaurav.goyal’s picture

Status: Needs work » Needs review
cilefen’s picture

+++ b/core/modules/user/src/PermissionHandler.php
@@ -149,7 +150,8 @@ protected function buildPermissionsYaml() {
+        $this->checkValidPermissionName($permission_name);

If anyone wants the tests to pass, comment out this line. Just remember to put it back later.

gaurav.goyal’s picture

Assigned: Unassigned » gaurav.goyal

converting contact.permissions.yml

gaurav.goyal’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new23.18 KB
new177.11 KB

wrt https://www.drupal.org/node/2309869#comment-9293257 I have commented the line, so that this patch can be tested.

@cilefen : I think we should keep this line commented till all the permissions are changed, in this way we will be able to see the test result and once all the permissions are changed successfully, we will uncomment it again. Makes sense ?

Changed permissions for contact.permissions.yml

Status: Needs review » Needs work

The last submitted patch, 39: use_proper_machine-2309869-39.patch, failed testing.

gaurav.goyal’s picture

Assigned: gaurav.goyal » Unassigned
Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new29.86 KB
new200.12 KB

Changes in this patch :

1. content_translation.permissions.yml converted.
2. contextual.permissions.yml converted.
3. Test failed in the previous patch due to wrong conversion of permission is now fixed.

Status: Needs review » Needs work

The last submitted patch, 41: user-proper-machine-2309869-41.patch, failed testing.

gaurav.goyal’s picture

Issue summary: View changes
Status: Needs work » Postponed
cilefen’s picture

Issue summary: View changes

+1 for postponing until Drupal 9.

webchick’s picture

Version: 8.0.x-dev » 9.x-dev
Issue tags: -beta target, -rc deadline

I'd actually go one higher and call this "won't fix." :\ In addition to the huge disruption caused to existing modules trying to port to D8 (which means this is not post-beta material according to https://www.drupal.org/contribute/core/beta-changes), there's nothing inherent in YAML that prevents keys with spaces in them (http://www.yamllint.com/), and adding underscores makes the resulting code less natural to read.

For now just moving to 9.x though.

geerlingguy’s picture

there's nothing inherent in YAML that prevents keys with spaces in them

It may be valid, but there is no precedent—either in Drupal core, or in any other project I've seen using YAML. Keys for configuration items are almost always either snake_case or CamelCase, and I've never seen them as "space case" except in the case of Drupal permissions.

I agree that this would be a major pain now that we're in beta status... but I still think it's extremely worthwhile, if for no other reason to make Drupal consistently use one naming convention for machine names instead of "snake_case for everything... except permissions". IMO, this is primarily a DX/discoverability issue. I remember the first time I used hook_permission, I was bewildered by the use of spaces in the names.

Correct me if I'm wrong, but the only reason for the spaces is the permission names used to be used in Drupal <7 as the display names. (Thus some modules even have permissions with sentences with capitalization and periods(!)).

webchick’s picture

Hm? We already use spaces with keys in them elsewhere ('base theme' in themes, for example). Keys with spaces in them are used as examples in the YAML spec: http://yaml.org/spec/1.2/spec.html (see "not a number" and "Sammy Sosa" and others) as well as the Symfony YAML examples http://symfony.com/doc/current/components/yaml/yaml_format.html ("symfony 1.0" as a key). It's not unprecedented at all, though granted that "not-space" is more common.

And sorry, but this really clearly is not 8.x material anymore. See https://www.drupal.org/contribute/core/beta-changes. There's no way to justify the impact (addressing an inconsistency) being greater than the disruption (breaking every single module that touches permissions) here.

geerlingguy’s picture

Sorry... the wording in my previous comment was a bit off—I agree this has to go to 9.x now. I just think it's extremely worthwhile in a general sense :)

dani3lr0se’s picture

Although I don't have nearly enough experience as many of you all, I just wanted to point out that during a recent training in D7 module development, a co-worker pointed out this exact same issue, where some naming conventions had underscores while others didn't, i.e., permissions, etc.

This was slightly confusing to some of us as we were navigating through different functions and module files. @webchick and @geerlingguy, your explanations make it very clear as to why it is the way it is, but as @geerlingguy pointed out, it is definitely worthwhile to keep in mind in a general sense. From a newbie perspective, consistency is key when learning this type of stuff, as I'm sure you all can remember those days. ;)

Clearly this isn't exactly a big issue that needs to be addressed, but I would agree it is at least worth noting for 9.x.

Sorry for my lengthy explanation and hope I made some sense. As a newb it's a little intimidating to jump in these issue queues sometimes.

cilefen’s picture

@Daniel_Rose So that is a +1 from you. I like this issue too. But, it will just have to wait because as you read it is too disruptive now.

The issue queues are "intimidating"? Stick with us. That will wear off. Visit us at core mentoring hours to level up. We are nice—I promise.

dani3lr0se’s picture

@cilefen definitely a +1 from me and I appreciate the words of encouragement.

catch’s picture

Status: Postponed » Postponed (maintainer needs more info)
Issue tags: +Needs issue summary update

This looks like the right status.

xjm’s picture

Version: 9.x-dev » 8.8.x-dev

Under our continuous upgrade path and deprecation policy, feature and API additions should be added with backwards compatibility in minor releases, so moving to 8.8.x. Thanks!

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

anoopjohn’s picture

Should there be some kind of naming convention for permissions to avoid collisions?

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Curious if this is still valid?

berdir’s picture

Define valid. It certainly didn't happen elsewhere in the meantime, or we'd have all noticed :)

Not sure if the status is right, needs work/active would probably make more sense. It's basically set to this status to define a plan on how this could be a approached in a BC-compatible way, which is very much not straight forward which is why no one even tried.

The only way for this to become invalid would be if we decide to won't fix it. I'm not sure about that. Conceptually, I like this, but not convinced at all that the BC impact and amount would be worth it. And apparently nobody in the last 7 or so years thought otherwise and dared to pick this up.

smustgrave’s picture

that was more my question is if it's in the right status.

I agree this will break virtually everything most likely. Should this maybe be a target for D11?

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

chi’s picture

Status: Postponed (maintainer needs more info) » Needs work

Setting proper issues status per above conversation.

chi’s picture

Can we establish a new policy for the permission names and apply it only to new permissions? Contributed modules and custom modules would benefit from it right now because they will not have to follow this weird naming convention.

chaitanyadessai’s picture

Status: Needs work » Needs review
StatusFileSize
new200.12 KB

Added patch

smustgrave’s picture

Status: Needs review » Needs work

#67 should be answered.

volkswagenchick’s picture

Issue tags: -Novice

Removing novice tag for now as it looks like a question of policy change was asked.

berdir’s picture

Re #67, nobody is forced to do anything in contrib/custom code. permissions are just a string as far as core is concerned. It just happens to commonly use spaces instead of underscores.

The payment module for example uses a hierarchical permission names, separated by .: https://git.drupalcode.org/project/payment/-/blob/8.x-2.x/payment.permis...

IMHO, switching spaces to underscores without any other change like the patch in #68 is pretty pointless. It doesn't solve conflicts, it doesn't enable us to do anything we can't do now. The issue summary is also wrong in regards to YAML, spaces in keys do not need to be quoted as visible in those patches. If we were to introduce a change, it should be in context of #2919636: Design a better model for managing permissions IMHO and for example move us toward a hierarchical permission system.

So I'm changing my opinion of #62 and am voting in favor of closing this as a duplicate of that ideas issue.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.