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
f9712587
Commit
f9712587
authored
4 years ago
by
Liam Morland
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-4229: Protect menu link edit page for home page
parent
bee083a8
No related branches found
No related tags found
1 merge request
!63
ISTWCMS-4229: Protect home page
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Access/UwNodeAccessCheck.php
+16
-0
16 additions, 0 deletions
src/Access/UwNodeAccessCheck.php
src/Routing/UwNodeAccessRouteSubscriber.php
+2
-0
2 additions, 0 deletions
src/Routing/UwNodeAccessRouteSubscriber.php
with
18 additions
and
0 deletions
src/Access/UwNodeAccessCheck.php
+
16
−
0
View file @
f9712587
...
@@ -6,6 +6,7 @@ use Drupal\Core\Access\AccessResult;
...
@@ -6,6 +6,7 @@ use Drupal\Core\Access\AccessResult;
use
Drupal\Core\Routing\Access\AccessInterface
;
use
Drupal\Core\Routing\Access\AccessInterface
;
use
Drupal\Core\Routing\RouteMatchInterface
;
use
Drupal\Core\Routing\RouteMatchInterface
;
use
Drupal\Core\Session\AccountInterface
;
use
Drupal\Core\Session\AccountInterface
;
use
Drupal\menu_admin_per_menu
\Access\MenuAdminPerMenuAccess
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
/**
/**
...
@@ -25,6 +26,21 @@ class UwNodeAccessCheck implements AccessInterface {
...
@@ -25,6 +26,21 @@ 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
();
// Menu link edit pages.
if
(
$route_name
===
'menu_ui.link_edit'
)
{
$menu_link_plugin
=
$route_match
->
getParameter
(
'menu_link_plugin'
);
// Only those with permission may edit home page menu entry.
if
(
$menu_link_plugin
->
getPluginId
()
===
'uw_base_profile.front_page'
)
{
return
$account
->
hasPermission
(
'bypass home page protection'
)
?
AccessResult
::
allowed
()
:
AccessResult
::
forbidden
();
}
else
{
// Otherwise, default to access set in menu_admin_per_menu.
$menu_admin_per_menu
=
new
MenuAdminPerMenuAccess
();
return
$menu_admin_per_menu
->
menuLinkAccess
(
$account
,
$menu_link_plugin
);
}
}
// Get the node object, which is in the route match variable.
// Get the node object, which is in the route match variable.
$node
=
$route_match
->
getParameter
(
'node'
);
$node
=
$route_match
->
getParameter
(
'node'
);
...
...
This diff is collapsed.
Click to expand it.
src/Routing/UwNodeAccessRouteSubscriber.php
+
2
−
0
View file @
f9712587
...
@@ -18,6 +18,8 @@ class UwNodeAccessRouteSubscriber extends RouteSubscriberBase {
...
@@ -18,6 +18,8 @@ class UwNodeAccessRouteSubscriber extends RouteSubscriberBase {
$access_route_names
=
[
$access_route_names
=
[
// Node pages (/node/{nid}).
// Node pages (/node/{nid}).
'entity.node.canonical'
,
'entity.node.canonical'
,
// Menu link edit pages.
'menu_ui.link_edit'
,
];
];
foreach
(
$access_route_names
as
$route_name
)
{
foreach
(
$access_route_names
as
$route_name
)
{
if
(
$route
=
$collection
->
get
(
$route_name
))
{
if
(
$route
=
$collection
->
get
(
$route_name
))
{
...
...
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