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.ymlaggregator.permissions.ymlban.permissions.ymlblock.permissions.ymlbook.permissions.ymlcomment.permissions.ymlconfig.permissions.ymlconfig_translation.permissions.ymlcontact.permissions.ymlcontent_translation.permissions.ymlcontextual.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.
| Comment | File | Size | Author |
|---|---|---|---|
| #68 | user-proper-machine-2309869-68.patch | 200.12 KB | chaitanyadessai |
| #41 | user-proper-machine-2309869-41.patch | 200.12 KB | gaurav.goyal |
| #41 | interdiff-39-41.txt | 29.86 KB | gaurav.goyal |
| #39 | use_proper_machine-2309869-39.patch | 177.11 KB | gaurav.goyal |
| #39 | interdiff-32-39.txt | 23.18 KB | gaurav.goyal |
Comments
Comment #1
xjmComment #2
xjmJust a note that the first thing we'd probably want to change would be:
'restrict access': TRUEComment #3
xjmComment #4
geerlingguy commentedIs the
restrict access/restrict_accesschange out of scope for this issue, though? It's not a permission name, just a key for defined permissions...Comment #5
dawehnerI think it should not be out of scope ... given that we have to touch nearly all permissions.
Comment #6
xjmOr 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. :)
Comment #7
geerlingguy commentedUpdating issue status based on #2295469: Add support for static permission definitions with *.permissions.yml being committed (yay!).
Comment #8
geerlingguy commentedEek... still postponed until #2328411: Convert all permissions to yml files and permission callbacks is complete.
Comment #9
dawehnerGiven that you can have keys without any quotes in YML I wonder whether we still want to proceed with this issue.
Comment #10
sunI 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
Comment #11
geerlingguy commentedChanging 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
myuser.groups.add: [groups/users]publish_posts)$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...
Comment #12
xjmSo 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.
Comment #13
dawehner100% 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.
Comment #14
Crell commentedI 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.
Comment #15
andrewmacpherson commentedPer comment #8, #2328411: Convert all permissions to yml files and permission callbacks is complete and this is also tagged RC deadline, so marking active.
Comment #16
andrewmacpherson commentedupdating remaining tasks in issue summary.
Comment #17
cilefen commentedOf the module permissions, I got through the first four:
action.permissions.ymlaggregator.permissions.ymlban.permissions.ymlblock.permissions.ymlComment #18
cilefen commentedI think it makes sense to throw an exception in PermissionHandler if a non-machine name permission key is set.
Comment #19
cilefen commentedThis 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.
Comment #21
cilefen commentedI 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.
Comment #22
cilefen commentedI added the custom exception.
Comment #24
gaurav.goyal commentedchanging permissions for comment.permissions.yml file.
Comment #25
mcdruid commentedworking on permissions in config.permissions.yml
Comment #26
gaurav.goyal commentedcomment.permissions.yml permissions changed.
Comment #27
gaurav.goyal commentedHere are the correct patch, Please ignore previous one.
Comment #30
mcdruid commentedconfig.permissions.yml changed
Comment #31
gaurav.goyal commentedchanging config_translation.permissions.yml permissions
Comment #32
gaurav.goyal commentedconfig_translation.permissions.yml changed.
Comment #33
gaurav.goyal commentedComment #37
cilefen commentedIf anyone wants the tests to pass, comment out this line. Just remember to put it back later.
Comment #38
gaurav.goyal commentedconverting contact.permissions.yml
Comment #39
gaurav.goyal commentedwrt 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
Comment #41
gaurav.goyal commentedChanges 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.
Comment #43
gaurav.goyal commentedComment #44
cilefen commented+1 for postponing until Drupal 9.
Comment #45
webchickI'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.
Comment #46
geerlingguy commentedIt 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(!)).
Comment #47
webchickHm? 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.
Comment #48
geerlingguy commentedSorry... 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 :)
Comment #49
dani3lr0se commentedAlthough 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.
Comment #50
cilefen commented@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.
Comment #51
dani3lr0se commented@cilefen definitely a +1 from me and I appreciate the words of encouragement.
Comment #52
catchThis looks like the right status.
Comment #53
xjmUnder 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!
Comment #55
anoopjohn commentedShould there be some kind of naming convention for permissions to avoid collisions?
Comment #61
smustgrave commentedCurious if this is still valid?
Comment #62
berdirDefine 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.
Comment #63
smustgrave commentedthat 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?
Comment #66
chi commentedSetting proper issues status per above conversation.
Comment #67
chi commentedCan 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.
Comment #68
chaitanyadessai commentedAdded patch
Comment #69
smustgrave commented#67 should be answered.
Comment #70
volkswagenchickRemoving novice tag for now as it looks like a question of policy change was asked.
Comment #71
berdirRe #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.