Use proper machine names for permissions

Created on 25 July 2014, over 10 years ago
Updated 6 June 2023, almost 2 years ago

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.":

  • l
  • 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

Document the requirements for machine names.

User interface changes

None.

API changes

Permissions should only use machine names.

📌 Task
Status

Needs work

Version

11.0 🔥

Component
User system 

Last updated 1 day ago

Created by

🇺🇸United States geerlingguy

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024