Attached display link is shown even if validation criteria in the contextual filters fails

Created on 7 May 2024, about 2 months ago
Updated 13 May 2024, about 1 month ago

Problem/Motivation

An attached display link should not be shown when the user has no access to that attached display.
This is true when the access is restricted in the view display's access settings.
However, when the access is restricted via a validation criteria in a contextual filter, the attached display link is still shown. When clicking on the link, the user will see a 404 page.

Steps to reproduce

I did the following in a fresh standard install of Drupal 11.

  1. Edit the frontpage view (https://d11.ddev.site/admin/structure/views/view/frontpage/edit);
  2. Change the path to be: /node/%type and add a contextual filter for content type (all displays);
  3. Remove the filter "Promoted to the front page" (all displays);
  4. Create some basic pages;
  5. Add this to your theme (for this test I'm editing "core/themes/olivero/templates/views/views-view--frontpage.html.twig"), for example above the footer section:
      {% if feed_icons %}
        <div class="feed-icons">
          {{ feed_icons }}
        </div>
      {% endif %}
      
  6. Now, as an authenticated user, when going to https://d11.ddev.site/node/page the RSS feed link should be visible.
  7. When clicking the RSS feed link a file should be ready to be downloaded;
  8. Edit the frontpage view (https://d11.ddev.site/admin/structure/views/view/frontpage/edit);
  9. Now as admin edit the frontpage view, the Feed display (https://d11.ddev.site/admin/structure/views/view/frontpage/edit/feed_1);
  10. Click in the Contextual filter: content type and then:
  11. - check the box for "Specify validation criteria";
  12. - select the validator "Content type";
  13. - check the box " Validate user has access to the Content type";
  14. - for the Access operation to check, choose "Edit";
  15. - on the top of the modal, choose to apply only to this feed display (override)
  16. - and apply the changes.
  17. Save the view.
  18. Now, as an authenticated user, when going to https://d11.ddev.site/node/page the RSS feed link should be visible.
  19. When clicking the RSS feed link a page 404 is shown!

The link to an inaccessible page should not be shown.

Proposed resolution

In "\Drupal\views\ViewExecutable::attachDisplays()" there is a check if the display can be accessed:
if ($display_handler->isEnabled() && $display_handler->access()) {...}

Either $display_handler->access() should return false or we need to add another check.

Remaining tasks

Investigate and fix.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

Issue description.

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated about 5 hours ago

Created by

πŸ‡΅πŸ‡ΉPortugal dxvargas

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

Comments & Activities

Production build 0.69.0 2024