Add dblog-specific permissions to control access to dblog routes

Created on 12 December 2024, 8 months ago

Problem/Motivation

While creating reports for some of the users on one of the sites I'm currently working on, I realized that they should be reachable from the Reports menu, not the Content menu, which is where we've been putting our custom reports up to this point.

When I masqueraded as one of the users (a non-admin user) who would access these reports, I found that some dblog reports were still visible in the menu. This led me to find that the dblog reports' permissions are based on the 'access site reports' permission, which is the same permission used to grant access to the Reports menu item (specifically the system.admin_reports route in web/core/modules/system/system.routing.yml).

There should be a permission specific to the dblog module that grants access to dblog-related reports to prevent users who shouldn't see these reports from being able to see them.

Proposed resolution

I propose the following changes:

  • Add an 'access dblog reports' permission
  • Change the permission requirement on all dblog routes from 'access site reports' to 'access dblog reports'

Remaining tasks

  • Write tests to ensure the 'access dblog reports' permission works as intended.

User interface changes

Users with the 'access site reports' permission but without the 'access dblog reports' permission will no longer be able to access dblog reports. Users who should be able to access these reports will need the 'access dblog reports' permission added to at least one of their assigned roles.

Introduced terminology

None.

API changes

None.

Data model changes

None.

Release notes snippet

  • Added the 'access dblog reports' permission to control access to dblog routes.
  • Updated dblog routes to use the 'access dblog reports' permission.
✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component

dblog.module

Created by

πŸ‡ΊπŸ‡ΈUnited States jsutta United States

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

Merge Requests

Comments & Activities

  • Issue created by @jsutta
  • Pipeline finished with Failed
    8 months ago
    Total: 556s
    #366742
  • Pipeline finished with Failed
    8 months ago
    Total: 140s
    #366983
  • Pipeline finished with Failed
    8 months ago
    Total: 460s
    #366991
  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States

    Adding a patch for 10.3.x (that's our current branch) in case anyone else can use it.

  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States
  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States
  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States
  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States

    Updated the patch as I missed a couple uses of the 'access site reports' permission.

  • Pipeline finished with Failed
    8 months ago
    Total: 467s
    #367723
  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States

    One more new version of the patch. I forgot to add dblog.permissions.yml to the previous versions.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    So I wonder if we will need an upgrade hook for the view change, maybe not though since we aren't removing a permission.

    The update hook will need test coverage though.

    Probably need to expand on the existing tests too that if I have 'access site reports' then I can't access the logs
    And other side if I have 'access dblogs reports' then I can still get to the "Reports" tab but it only contains the one link

    Appears to have test failures also.

  • Pipeline finished with Failed
    6 months ago
    Total: 146s
    #417153
  • Pipeline finished with Failed
    5 months ago
    Total: 122s
    #450650
  • Pipeline finished with Failed
    5 months ago
    Total: 129s
    #450680
  • Pipeline finished with Failed
    5 months ago
    Total: 140s
    #450699
  • Issue was unassigned.
  • Status changed to Needs work 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States

    @smustgrave Thank you for the suggestions and I apologize it took me so long to circle back to this.

    Here's a summary of the latest changes:

    • Added an update hook to update the Watchdog view if it uses the default permissions (I assume we want to leave it alone if the site owner has customized it).
    • Added test coverage for the update hook (the test coverage checks the permission on the Watchdog view before and after the update).
    • Added test coverage to check if a user with the 'access site reports' permission can see the Reports menu item in the admin toolbar.
    • Added test coverage to check if a user with the 'access dblog reports' permission can access the Recent log messages page.

    This is the first time I've written these types of tests, so please double-check them and let me know if anything is missing or incorrect.

    Also, I haven't addressed the test failures yet. I hope to do so within the next couple days.

  • Pipeline finished with Failed
    5 months ago
    #450712
  • Pipeline finished with Failed
    5 months ago
    Total: 604s
    #451190
  • Pipeline finished with Failed
    5 months ago
    Total: 531s
    #451208
  • Pipeline finished with Failed
    5 months ago
    Total: 174s
    #451324
  • Pipeline finished with Failed
    5 months ago
    Total: 134s
    #451335
  • Pipeline finished with Failed
    5 months ago
    Total: 159s
    #451334
  • Pipeline finished with Failed
    5 months ago
    Total: 406s
    #451354
  • Pipeline finished with Failed
    5 months ago
    Total: 612s
    #454614
  • Pipeline finished with Failed
    5 months ago
    Total: 206s
    #454686
  • Pipeline finished with Failed
    5 months ago
    #454689
  • Pipeline finished with Failed
    5 months ago
    Total: 636s
    #454695
  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States

    @smustgrave I finally got the tests completed and all are now passing. Would you take another look at it and let me know if any other changes need to be made?

  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States
  • πŸ‡¦πŸ‡·Argentina dagmar Argentina

    @jsutta Thanks for the patch!

    There are a few files that are outside dblog but will need an upgrade as well:

    Here are a bunch of patters to check:

    rg 'dblog' | rg 'access site reports'

    modules/update/update.report.inc:  if (\Drupal::moduleHandler()->moduleExists('dblog') && \Drupal::currentUser()->hasPermission('access site reports')) {
    modules/system/system.theme.inc:  if (\Drupal::moduleHandler()->moduleExists('dblog') && \Drupal::currentUser()->hasPermission('access site reports')) {
    modules/ckeditor5/src/SmartDefaultSettings.php:      $can_access_dblog = ($this->currentUser->hasPermission('access site reports') && $this->moduleHandler->moduleExists('dblog'));
    modules/locale/locale.batch.inc:      if (\Drupal::moduleHandler()->moduleExists('dblog') && \Drupal::currentUser()->hasPermission('access site reports')) {
    modules/locale/locale.bulk.inc:        if (\Drupal::moduleHandler()->moduleExists('dblog') && \Drupal::currentUser()->hasPermission('access site reports')) {
    

    And the following files reference the dblog routing as well, so it may be worth to check the permissions there:

    lib/Drupal/Core/Routing/routing.api.php:1
    modules/system/tests/src/Functional/Menu/BreadcrumbTest.php:1
    modules/system/tests/src/Functional/File/FileSaveHtaccessLoggingTest.php:1
    modules/system/tests/src/Functional/Pager/PagerTest.php:4
    modules/migrate_drupal/tests/fixtures/drupal7.php:4
    modules/search/tests/src/Functional/SearchNumberMatchingTest.php:1
    modules/search/tests/src/Functional/SearchNumbersTest.php:1
    modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php:2
    modules/user/tests/src/Functional/UserPermissionsTest.php:1
    modules/filter/tests/src/Functional/FilterAdminTest.php:2
    modules/contact/tests/src/Functional/ContactPersonalTest.php:1
    modules/contact/tests/src/Functional/ContactSitewideTest.php:1
    tests/fixtures/config_install/multilingual/views.view.watchdog.yml:2
    modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeExecuteTestBase.php:1
    modules/file/tests/src/Functional/SaveUploadTest.php:1
    modules/file/tests/src/Functional/SaveUploadFormTest.php:1
    tests/Drupal/FunctionalTests/Theme/ClaroTest.php:1
    
  • Pipeline finished with Failed
    5 months ago
    Total: 591s
    #461006
  • Pipeline finished with Failed
    5 months ago
    Total: 491s
    #461021
  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States

    @dagmar Thank you for the catches! I've added the access dblog reports permission in the other locations where the access site reports was already being used, with one exception:

    In modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeExecuteTestBase.php: The user in this test is the root user (uid 1), so should implicitly have all permissions. With that in mind there's no need to set the specific permission.

  • Pipeline finished with Failed
    5 months ago
    Total: 862s
    #461045
  • πŸ‡¦πŸ‡·Argentina dagmar Argentina

    Thanks @jsutta Please take a look to the rest of the failing tests in https://git.drupalcode.org/issue/drupal-3493583/-/pipelines/461051

  • Pipeline finished with Failed
    4 months ago
    Total: 570s
    #471691
  • Pipeline finished with Failed
    4 months ago
    Total: 570s
    #471731
  • Pipeline finished with Failed
    4 months ago
    Total: 526s
    #471738
  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States

    @dagmar Thank you for pointing these out. I believe I've fixed all of the failed tests at this point, but please review the results and let me know if I missed anything.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Upgrade path tests seem to be added so removing that tag

    Still appears to need a CR so moving to NW for that.

    Will let @dagmar do the final review before RTBC as he seems to have more knowledge with this code already.

  • πŸ‡¦πŸ‡·Argentina dagmar Argentina

    It seems there is a missing change to do to fix the Nighwatch related tests.

  • Pipeline finished with Failed
    18 days ago
    Total: 168s
    #558983
  • Pipeline finished with Failed
    18 days ago
    Total: 410s
    #558996
  • Pipeline finished with Failed
    12 days ago
    Total: 140s
    #563749
  • Pipeline finished with Failed
    12 days ago
    Total: 138s
    #563752
  • Pipeline finished with Failed
    12 days ago
    Total: 479s
    #563756
  • Pipeline finished with Failed
    12 days ago
    Total: 1027s
    #563768
  • Pipeline finished with Failed
    12 days ago
    Total: 546s
    #563778
  • Pipeline finished with Failed
    12 days ago
    Total: 586s
    #563805
  • Pipeline finished with Failed
    12 days ago
    Total: 183s
    #563856
  • Pipeline finished with Failed
    12 days ago
    Total: 511s
    #563860
  • Pipeline finished with Failed
    12 days ago
    Total: 528s
    #563861
  • Pipeline finished with Failed
    3 days ago
    #571566
  • Pipeline finished with Failed
    1 day ago
    Total: 483s
    #572555
  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States

    Been picking away at this and I'm at the point where I need some help with the tests.

    The only remaining PHPUnit test issues are related to the issue below. I checked the default config for the Watchdog table in views.view.watchdog.yml and found that there's no default class provided. At this point I think fixing this is outside the scope of this issue, but I'm more than happy to fix it if anyone feels it should be included.

    The update to add a default table CSS class for view "watchdog" is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Profile, module and theme provided configuration should be updated. See <a href="https://www.drupal.org/node/3499943">https://www.drupal.org/node/3499943</a>.

    The PHPUnit Functional JavaScript errors are also unrelated:

    Behat\Mink\Exception\ExpectationException: The string "Added text format ckeditor5." was not found anywhere in the HTML response of the current page.

    As for Nightwatch, the error is below. I don't believe it's related to the changes in this issue:

    An error occurred while running .click() command on <input[name="i5byg6bay[administer modules]"]>: element click intercepted: Element <input class="rid-i5byg6bay js-rid-i5byg6bay form-checkbox" data-drupal-selector="edit-i5byg6bay-administer-modules" type="checkbox" id="edit-i5byg6bay-administer-modules" name="i5byg6bay[administer modules]" value="1"> is not clickable at point (674, 52). Other element would receive the click: <th class="checkbox">...</th>

    I'm happy to continue digging into the test results, but at this point I don't feel like there's much more I can do.

  • πŸ‡¦πŸ‡·Argentina dagmar Argentina

    @jsutta I think the problem here is the way we are updating the Watchdog table. Potentially any other view could be be using the access dblog reports permission and we want to make sure those views are updated as well.

    The way this is done is via the ViewsConfigUpdater. See for example this function

    Converting the code from dblog_update_112002 into the ViewsConfigUpdater should point you in the right direction.

Production build 0.71.5 2024