Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uw_cfg_common
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WCMS
uw_cfg_common
Commits
ddb2e84a
Commit
ddb2e84a
authored
3 years ago
by
Liam Morland
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-5085: Refactor UwNodeAccessCheck::access()
parent
23cce581
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!153
ISTWCMS-5085: Prevent non-admin access to menu add, edit, and delete
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Access/UwNodeAccessCheck.php
+19
-25
19 additions, 25 deletions
src/Access/UwNodeAccessCheck.php
with
19 additions
and
25 deletions
src/Access/UwNodeAccessCheck.php
+
19
−
25
View file @
ddb2e84a
...
@@ -27,37 +27,31 @@ class UwNodeAccessCheck implements AccessInterface {
...
@@ -27,37 +27,31 @@ class UwNodeAccessCheck implements AccessInterface {
* The access result.
* The access result.
*/
*/
public
function
access
(
RouteMatchInterface
$route_match
,
AccountInterface
$account
):
AccessResult
{
public
function
access
(
RouteMatchInterface
$route_match
,
AccountInterface
$account
):
AccessResult
{
$route_name
=
$route_match
->
getRouteName
();
switch
(
$route_match
->
getRouteName
())
{
// Menu link edit pages.
// Menu link edit pages.
case
'menu_ui.link_edit'
:
if
(
$route_name
===
'menu_ui.link_edit'
)
{
$menu_link_plugin
=
$route_match
->
getParameter
(
'menu_link_plugin'
);
$menu_link_plugin
=
$route_match
->
getParameter
(
'menu_link_plugin'
);
// Only those with permission may edit home page menu entry.
// Only those with permission may edit home page menu entry.
if
(
$menu_link_plugin
->
getPluginId
()
===
'uw_base_profile.front_page'
)
{
if
(
$menu_link_plugin
->
getPluginId
()
===
'uw_base_profile.front_page'
)
{
return
$account
->
hasPermission
(
'bypass home page protection'
)
?
AccessResult
::
allowed
()
:
AccessResult
::
forbidden
();
return
$account
->
hasPermission
(
'bypass home page protection'
)
?
AccessResult
::
allowed
()
:
AccessResult
::
forbidden
();
}
}
else
{
// Otherwise, default to access set in menu_admin_per_menu.
// Otherwise, default to access set in menu_admin_per_menu.
$menu_admin_per_menu
=
new
MenuAdminPerMenuAccess
();
$menu_admin_per_menu
=
new
MenuAdminPerMenuAccess
();
return
$menu_admin_per_menu
->
menuLinkAccess
(
$account
,
$menu_link_plugin
);
return
$menu_admin_per_menu
->
menuLinkAccess
(
$account
,
$menu_link_plugin
);
}
}
// Node delete pages.
// Node delete pages.
if
(
$route_name
===
'entity.node.delete_form'
)
{
case
'entity.node.delete_form'
:
$node
=
$route_match
->
getParameter
(
'node'
);
$node
=
$route_match
->
getParameter
(
'node'
);
// Only those with permission may delete the home page.
// Only those with permission may delete the home page.
if
(
$node
&&
UWService
::
nodeIsHomePage
((
int
)
$node
->
id
()))
{
if
(
$node
&&
UWService
::
nodeIsHomePage
((
int
)
$node
->
id
()))
{
return
$account
->
hasPermission
(
'bypass home page protection'
)
?
AccessResult
::
allowed
()
:
AccessResult
::
forbidden
();
return
$account
->
hasPermission
(
'bypass home page protection'
)
?
AccessResult
::
allowed
()
:
AccessResult
::
forbidden
();
}
}
else
{
return
AccessResult
::
allowed
();
return
AccessResult
::
allowed
();
}
}
// Dashboard config: admin/config/dashboards/dashboardssettings.
// Dashboard config: admin/config/dashboards/dashboardssettings.
if
(
$route_name
===
'dashboards.dashboards_settings_form'
)
{
case
'dashboards.dashboards_settings_form'
:
return
$account
->
hasPermission
(
'access dashboard config'
)
?
AccessResult
::
allowed
()
:
AccessResult
::
forbidden
();
return
$account
->
hasPermission
(
'access dashboard config'
)
?
AccessResult
::
allowed
()
:
AccessResult
::
forbidden
();
}
}
// Get the node object, which is in the route match variable.
// Get the node object, which is in the route match variable.
...
...
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