Problem/Motivation

Currently menu module registering services to check access for menu and menu link entities deletion
This custom access should be moved to corresponding access controllers

Proposed resolution

Implement

  • MenuLinkAccessController
  • MenuAccessController

to encapsulate specific access for delete operations and extent them in #1842850: Untangle menu_link access control from _menu_link_translate() and friends for _menu_link_translate()

While menu entity lives in system module it's access controlled should stay there

API changes

No

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andypost’s picture

Status: Needs review » Needs work
Issue tags: -Entity Access, -Entity Field API

The last submitted patch, access-controllers-2012916-1.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review

#1: access-controllers-2012916-1.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Entity Access, +Entity Field API

The last submitted patch, access-controllers-2012916-1.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review

Test passes locally

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me as a first step. We can deal with gutting _menu_link_translate() in the other issue.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Looks good to me, following the other issue. Committed/pushed to 8.x.

andypost’s picture

Status: Fixed » Reviewed & tested by the community

This one was not pushed

catch’s picture

Status: Reviewed & tested by the community » Fixed

git errored out on me with access denied... Now pushed.

andypost’s picture

now ok

Berdir’s picture

Title: Implement access controller for the menu and menu link entity » HEAD BROKEN: Implement access controller for the menu and menu link entity
Status: Fixed » Needs review
FileSize
2.08 KB

Not so ok :)

Wasn't retested and conflicted with AccountInterface. This should fix it, but it's untested.

catch’s picture

Status: Needs review » Fixed

Whoops and thanks, committed/pushed.

catch’s picture

Status: Fixed » Needs work

Actually reverted both the follow-up and the original patch, let's start back from this morning...

tim.plunkett’s picture

Title: HEAD BROKEN: Implement access controller for the menu and menu link entity » Implement access controller for the menu and menu link entity
Berdir’s picture

Status: Needs work » Needs review
FileSize
10.42 KB

Combined the two patches.

andypost’s picture

andypost’s picture

patches are identical

andypost’s picture

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Patches are identical so Retest berdir's one

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Needs a reroll...

curl https://drupal.org/files/access-controllers-2012916-15.patch | git a
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10669  100 10669    0     0   7739      0  0:00:01  0:00:01 --:--:--  9126
error: patch failed: core/modules/menu/menu.routing.yml:17
error: core/modules/menu/menu.routing.yml: patch does not apply
pwieck’s picture

Working on reroll of #15

pwieck’s picture

Status: Needs work » Needs review
FileSize
10.39 KB

rerolled.

Berdir’s picture

+++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkAccessController.phpundefined
@@ -0,0 +1,33 @@
+    $access = user_access('administer menu', $account);
+    if ($access && $operation == 'delete') {
+      // Only items created by the menu module can be deleted.
+      return $entity->module == 'menu';

Hm, so we have code for menu.module in the required menu_link.module.

We introduced a generic hook_$type_access() in the access controller base class, wondering if menu.module could implement this through that hook. Although I'm not quite sure how, maybe disallow delete by default and then menu.module allows to delete it's own menu links?

amateescu’s picture

maybe disallow delete by default and then menu.module allows to delete it's own menu links?

Yes, I think that's a good plan.

Berdir’s picture

Status: Needs review » Needs work
Issue tags: -Needs reroll

Let's do that then :)

andypost’s picture

Status: Needs work » Needs review
FileSize
11.34 KB
3.03 KB

New patch, reverted this questionable place to previous implementation!
... and removed deprecated user_access() calls

#24 Not sure it possible because 'administer menus' permission is defined in menu module which depends on menu_link

+++ /dev/nullundefined
@@ -1,37 +0,0 @@
-class DeleteLinkAccessCheck implements AccessCheckInterface {
...
-  public function access(Route $route, Request $request) {
-    if (user_access('administer menu') && $menu_link = $request->attributes->get('menu_link')) {
-      // Links defined via hook_menu may not be deleted. Updated items are an
-      // exception, as they can be broken.
-      return $menu_link->module !== 'system' || $menu_link->updated;

so it's a conversion

andypost’s picture

access check for delete now lives in EntityListController

andypost’s picture

Digging deeper I found that _menu_overview_tree_form() uses different permissions. So introduced them and cleaned-up useless code.

Status: Needs review » Needs work
Issue tags: -Entity Access, -Entity Field API

The last submitted patch, access-controllers-2012916-28.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
Issue tags: +Entity Access, +Entity Field API
tim.plunkett’s picture

This looks like it overlaps with the RTBC #1984702: Convert menu.module's page callbacks to Controllers

Status: Needs review » Needs work

The last submitted patch, access-controllers-2012916-28.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
FileSize
12.54 KB
1.24 KB

Broken test should pass now

@tim.plunkett I think it's ok, I'll re-roll if this one goes first

andypost’s picture

Status: Needs review » Needs work

The last submitted patch, access-controllers-2012916-34.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
FileSize
12.16 KB
470 bytes

we need stop to mix edit and update

Status: Needs review » Needs work

The last submitted patch, access-controllers-2012916-36.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
FileSize
12.42 KB
2.08 KB

should be fine mostly

dawehner’s picture

@@ -0,0 +1,48 @@
+ * @see \Drupal\menu_link\Plugin\Core\Entity\MenuLink

Potentially we should also typehint the MenuLinkInterface

@@ -0,0 +1,34 @@
+    if ($operation == 'delete') {
...
+      $system_menus = menu_list_system_menus();
+      return !isset($system_menus[$entity->id()]);

Just wondering why we do not check for 'administer menu' as well.

@@ -0,0 +1,34 @@
+    return user_access('administer menu', $account);

This should be $account->hasPermission.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Looks great to me.

amateescu’s picture

Status: Reviewed & tested by the community » Needs work

Except that I didn't catch that user_access() call.

andypost’s picture

Status: Needs work » Needs review
Issue tags: +CodeSprintCIS
FileSize
12.67 KB
1.58 KB

MenuAccessController should live in system module where the entity defined, so moved current implementation with clean-up

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 972406d and pushed to 8.x. Thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.