Issue #3039499 by alexpott, acbramley: Role permissions not sorted in config export
parent
465482a571
commit
6b5efdc116
|
@ -122,6 +122,7 @@ user.role.*:
|
||||||
permissions:
|
permissions:
|
||||||
type: sequence
|
type: sequence
|
||||||
label: 'Permissions'
|
label: 'Permissions'
|
||||||
|
orderby: value
|
||||||
sequence:
|
sequence:
|
||||||
type: string
|
type: string
|
||||||
label: 'Permission'
|
label: 'Permission'
|
||||||
|
|
|
@ -185,12 +185,6 @@ class Role extends ConfigEntityBase implements RoleInterface {
|
||||||
});
|
});
|
||||||
$this->weight = $max + 1;
|
$this->weight = $max + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->isSyncing()) {
|
|
||||||
// Permissions are always ordered alphabetically to avoid conflicts in the
|
|
||||||
// exported configuration.
|
|
||||||
sort($this->permissions);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -45,4 +45,16 @@ class UserRoleEntityTest extends KernelTestBase {
|
||||||
->save();
|
->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPermissionRevokeAndConfigSync() {
|
||||||
|
$role = Role::create(['id' => 'test_role', 'label' => 'Test role']);
|
||||||
|
$role->setSyncing(TRUE);
|
||||||
|
$role->grantPermission('a')
|
||||||
|
->grantPermission('b')
|
||||||
|
->grantPermission('c')
|
||||||
|
->save();
|
||||||
|
$this->assertSame(['a', 'b', 'c'], $role->getPermissions());
|
||||||
|
$role->revokePermission('b')->save();
|
||||||
|
$this->assertSame(['a', 'c'], $role->getPermissions());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
* Post update functions for User module.
|
* Post update functions for User module.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Drupal\Core\Config\Entity\ConfigEntityUpdater;
|
||||||
|
use Drupal\user\Entity\Role;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_removed_post_updates().
|
* Implements hook_removed_post_updates().
|
||||||
*/
|
*/
|
||||||
|
@ -14,3 +17,14 @@ function user_removed_post_updates() {
|
||||||
'user_post_update_update_roles' => '10.0.0',
|
'user_post_update_update_roles' => '10.0.0',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure permissions stored in role configuration are sorted using the schema.
|
||||||
|
*/
|
||||||
|
function user_post_update_sort_permissions(&$sandbox = NULL) {
|
||||||
|
\Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'user_role', function (Role $role) {
|
||||||
|
$permissions = $role->getPermissions();
|
||||||
|
sort($permissions);
|
||||||
|
return $permissions !== $role->getPermissions();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue