Data producer "menu_links" is not checking access

Created on 24 September 2024, 3 months ago

Problem/Motivation

Drupal 10 can have a custom access check for menu links, however, data producer "menu_links" does not consider it.

Steps to reproduce

Try to load some administrative menus using this data producer.

Proposed resolution

Add access check into data producer resolver.

API changes

Data producer "menu_links" will have for every menu link access check.

πŸ› Bug report
Status

Active

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine andriy khomych

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @andriy khomych
  • πŸ‡ΊπŸ‡¦Ukraine andriy khomych

    Prepared MR and attached patch.

  • Pipeline finished with Success
    3 months ago
    Total: 307s
    #291216
  • πŸ‡¦πŸ‡ΉAustria klausi πŸ‡¦πŸ‡Ή Vienna
  • πŸ‡¦πŸ‡ΉAustria klausi πŸ‡¦πŸ‡Ή Vienna

    Started with some unfinished test coverage, not done yet.

  • πŸ‡¦πŸ‡ΉAustria klausi πŸ‡¦πŸ‡Ή Vienna

    @andriy khomych I added cache context and 2 test cases.

    Do you need the access result neutral check? We should not allow neutral access results, right? Only menu links where the user has access should be returned.

  • πŸ‡ΊπŸ‡¦Ukraine andriy khomych

    @andriy khomych I added cache context and 2 test cases.

    Do you need the access result neutral check? We should not allow neutral access results, right? Only menu links where the user has access should be returned.

    Yup, Drupa core allows only allowed links.
    MenuLinkTree::buildItems

          // Only render accessible links.
          if ($data->access instanceof AccessResultInterface && !$data->access->isAllowed()) {
            continue;
          }
  • πŸ‡ΊπŸ‡¦Ukraine andriy khomych

    Unfortunately, I cannot add a review note to my MR, overall, it looks good.
    One more moment about cache:
    $context->addCacheableDependency($item->access);
    I think we might add a menu object as well. I'm unsure when we have a menu link removed or added so that correct information is displayed.

  • πŸ‡¦πŸ‡ΉAustria klausi πŸ‡¦πŸ‡Ή Vienna

    Thanks for the review, good point about the menu itself.

    I added the cache context for the menu as well. Not sure if this even has an effect, as I did not understand the connection between menu and menu links. But I think further testing on adding/removing menu links and caching is out of scope for this issue. I also think menus don't change that often, so should only be a minor issue.

    Let's fix the inaccessible links here and postpone any further work to a new issue if it is a problem.

  • πŸ‡¦πŸ‡ΉAustria klausi πŸ‡¦πŸ‡Ή Vienna

    And merged, should appear here soon.

  • πŸ‡¦πŸ‡ΉAustria klausi πŸ‡¦πŸ‡Ή Vienna

    Uploading patch file for composer patches.

  • πŸ‡ΊπŸ‡¦Ukraine andriy khomych

    Thanks, Klausi! Well done, it looks good to me.

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

Production build 0.71.5 2024