Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
3b8307bc
Commit
3b8307bc
authored
10 years ago
by
Angie Byron
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2329429
by dawehner: Fixed Permission page order is all wackadoo.
parent
12ee21a3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/modules/user/src/PermissionHandler.php
+9
-4
9 additions, 4 deletions
core/modules/user/src/PermissionHandler.php
core/modules/user/tests/src/PermissionHandlerTest.php
+52
-1
52 additions, 1 deletion
core/modules/user/tests/src/PermissionHandlerTest.php
with
61 additions
and
5 deletions
core/modules/user/src/PermissionHandler.php
+
9
−
4
View file @
3b8307bc
...
...
@@ -80,7 +80,7 @@ public function getPermissions() {
$all_permissions
+=
$this
->
buildPermissionsModules
();
return
$this
->
sortPermissions
ByProviderName
(
$all_permissions
);
return
$this
->
sortPermissions
(
$all_permissions
);
}
/**
...
...
@@ -138,7 +138,7 @@ protected function buildPermissionsModules() {
}
/**
* Sorts the given permissions by provider name.
* Sorts the given permissions by provider name
and title
.
*
* @param array $all_permissions
* The permissions to be sorted.
...
...
@@ -149,13 +149,18 @@ protected function buildPermissionsModules() {
* - description: The description of the permission, defaults to NULL.
* - provider: The provider of the permission.
*/
protected
function
sortPermissions
ByProviderName
(
array
$all_permissions
=
array
())
{
protected
function
sortPermissions
(
array
$all_permissions
=
array
())
{
// Get a list of all the modules providing permissions and sort by
// display name.
$modules
=
$this
->
getModuleNames
();
uasort
(
$all_permissions
,
function
(
array
$permission_a
,
array
$permission_b
)
use
(
$modules
)
{
return
$modules
[
$permission_a
[
'provider'
]]
>
$modules
[
$permission_b
[
'provider'
]];
if
(
$modules
[
$permission_a
[
'provider'
]]
==
$modules
[
$permission_b
[
'provider'
]])
{
return
$permission_a
[
'title'
]
>
$permission_b
[
'title'
];
}
else
{
return
$modules
[
$permission_a
[
'provider'
]]
>
$modules
[
$permission_b
[
'provider'
]];
}
});
return
$all_permissions
;
}
...
...
This diff is collapsed.
Click to expand it.
core/modules/user/tests/src/PermissionHandlerTest.php
+
52
−
1
View file @
3b8307bc
...
...
@@ -75,7 +75,7 @@ protected function mockModuleExtension($module, $name) {
* @covers ::getPermissions
* @covers ::buildPermissions
* @covers ::buildPermissionsModules
* @covers ::sortPermissions
ByProviderName
* @covers ::sortPermissions
* @covers ::getModuleNames
*/
public
function
testBuildPermissionsModules
()
{
...
...
@@ -124,6 +124,7 @@ public function testBuildPermissionsModules() {
$this
->
assertSame
(
array
(
'access_module_a'
,
'access_module_c'
,
'access module b'
),
array_keys
(
$actual_permissions
));
}
/**
* Tests permissions provided by YML files.
*
...
...
@@ -188,6 +189,56 @@ public function testBuildPermissionsYaml() {
$this
->
assertPermissions
(
$actual_permissions
);
}
/**
* Tests permissions sort inside a module.
*
* @covers ::__construct
* @covers ::getPermissions
* @covers ::buildPermissions
* @covers ::buildPermissionsYaml
* @covers ::sortPermissions
*/
public
function
testBuildPermissionsSortPerModule
()
{
vfsStreamWrapper
::
register
();
$root
=
new
vfsStreamDirectory
(
'modules'
);
vfsStreamWrapper
::
setRoot
(
$root
);
$this
->
moduleHandler
=
$this
->
getMock
(
'Drupal\Core\Extension\ModuleHandlerInterface'
);
$this
->
moduleHandler
->
expects
(
$this
->
once
())
->
method
(
'getModuleDirectories'
)
->
willReturn
([
'module_a'
=>
vfsStream
::
url
(
'modules/module_a'
),
]);
$url
=
vfsStream
::
url
(
'modules'
);
mkdir
(
$url
.
'/module_a'
);
file_put_contents
(
$url
.
'/module_a/module_a.permissions.yml'
,
"access_module_a2: single_description
access_module_a1: single_description"
);
$modules
=
[
'module_a'
];
$extensions
=
[
'module_a'
=>
$this
->
mockModuleExtension
(
'module_a'
,
'Module a'
),
];
$this
->
moduleHandler
->
expects
(
$this
->
any
())
->
method
(
'getImplementations'
)
->
with
(
'permission'
)
->
willReturn
([]);
$this
->
moduleHandler
->
expects
(
$this
->
any
())
->
method
(
'getModuleList'
)
->
willReturn
(
array_flip
(
$modules
));
$this
->
permissionHandler
=
new
TestPermissionHandler
(
$this
->
moduleHandler
,
$this
->
stringTranslation
);
// Setup system_rebuild_module_data().
$this
->
permissionHandler
->
setSystemRebuildModuleData
(
$extensions
);
$actual_permissions
=
$this
->
permissionHandler
->
getPermissions
();
$this
->
assertEquals
([
'access_module_a1'
,
'access_module_a2'
],
array_keys
(
$actual_permissions
));
}
/**
* Checks that the permissions are like expected.
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment