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.
Remaining tasks
N/A
User interface changes
N/A
Introduced terminology
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | WhatsApp Image 2021-02-03 at 07.28.27.jpeg | 119.84 KB | ilgnerfagundes |
Issue fork drupal-3196245
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3196245-userpermissionsform-should-not
changes, plain diff MR !11330
Comments
Comment #2
prudloff commentedThe attached patch loads the permissions without overrides.
Comment #3
ilgnerfagundes commentedI applied the patch and did some tests and for me it's working.
Comment #4
longwavePatch in #2 has the wrong path and doesn't apply.
Comment #9
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
Tagging for tests to show the issue.
Did not test.
Comment #10
prudloff commentedComment #13
prudloff commentedI added some tests.
Comment #14
smustgrave commentedSmall comments on the MR.
Thank you for starting with test coverage, guarantees this will probably get done faster
If you are another contributor eager to jump in, please allow the previous poster at least 48 hours to respond to feedback first, so they have the opportunity to finish what they started!
Comment #15
prudloff commentedI committed the type suggestions.
Comment #16
smustgrave commentedFeedback appears to be addressed.
Comment #17
catchOne comment on the MR.
Comment #18
berdirAgreed with @catch, also making this a child issue of #2910353: Prevent saving config entities when configuration overrides are applied which is about enforcing this in the long-term for all config.
Comment #19
prudloff commentedComment #20
berdirThanks, looks good to me now, one small step toward resolving the parent issue.
Comment #21
berdirI had a look at the subclasses as well now that this overides getRoles(), it should be fine.
I didn't verify it, but \Drupal\user\Form\UserPermissionsRoleSpecificForm::getRoles() uses the already loaded route from the route, that _should_ be the one without overrides thanks to \Drupal\Core\ParamConverter\AdminPathConfigEntityConverter.
Comment #25
catchCommitted/pushed to 11.x and cherry-picked to 11.1.x, 10.5.x and 10.4.x, thanks!