UserPermissionsForm should not use overridden permissions

Created on 3 February 2021, almost 4 years ago
Updated 22 March 2023, almost 2 years ago

Problem/Motivation

When using a ConfigFactoryOverrideInterface to override permissions, these new permissions will be displayed on /admin/people/permissions. So when saving the form, the overridden permissions will be saved to the database.

Steps to reproduce

Implement a permission override in a module:


namespace Drupal\foo\Config;

use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryOverrideInterface;
use Drupal\Core\Config\StorageInterface;

/**
 * Example configuration override.
 */
class PermissionOverrides implements ConfigFactoryOverrideInterface {

  /**
   * {@inheritdoc}
   */
  public function loadOverrides($names) {
    $overrides = [];
    if (in_array('user.role.webmestre', $names)) {
      $overrides['user.role.webmestre']['permissions'][9999] = 'foo';
    }
    return $overrides;
  }

  /**
   * @return string
   */
  public function getCacheSuffix() {
    return 'foo';
  }

  /**
   * @param string $name
   *
   * @return \Drupal\Core\Cache\CacheableMetadata
   */
  public function getCacheableMetadata($name) {
    return new CacheableMetadata();
  }

  /**
   * @param mixed $name
   * @param string $collection
   *
   * @return \Drupal\Core\Config\StorableConfigBase|null
   */
  public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
    return NULL;
  }

}

Then browse to /admin/people/permissions and save the form.
The overridden permission is saved in the config.

Proposed resolution

UserPermissionsForm should load the permissions from the config without any override.

πŸ› Bug report
Status

Needs work

Version

9.5

Component
User moduleΒ  β†’

Last updated 7 days ago

Created by

πŸ‡«πŸ‡·France prudloff Lille

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.

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