Update role exclusion logic to account for users with more than one role assigned

Created on 11 December 2023, 12 months ago
Updated 13 April 2024, 7 months ago

Problem/Motivation

Drupal users can be assigned multiple roles. The query condition currently in place does not correctly handle the case where multiple roles are assigned to a user. As the module functions currently, the user's roles must exactly match the configuration for excluded roles in block_inactive_users to be ignored by the blocking logic.

Steps to reproduce

  • As Admin, create a user with at least two roles
  • From administration/config form /admin/config/people/block_inactive_users
  • Set "Time period (in months)" to 0 to be able to test immediately
  • Check "include users who have never logged in"
  • Select only one of the two roles user was set up with
  • Click "Disable Inactive Users"
  • Confirm user was blocked

Proposed resolution

The root cause of this is the roles joined into the query to determine which users to block have separate rows per role.

Example user__roles table:
bundle | deleted | entity_id | revision_id | langcode | delta | roles_target_id |
+--------+---------+-----------+-------------+----------+-------+-----------------+
| user | 0 | 1 | 1 | en | 0 | administrator |
| user | 0 | 2 | 2 | en | 0 | content_editor |
| user | 0 | 2 | 2 | en | 1 | administrator

When these row are joined into the query the user may have multiple joined rows from the user__roles table;

Conditionally excluding one of the rows does not remove all of the user's rows from the query results. Therefore, a false positive is given when only one of the roles is selected from exclusion.

Option 1: The documentation of the "Exclude users with role(s)" functionality can be updated to specify complete match
Option 2: In order to work as logically expected the query or surrounding logic should be updated to allow one role exclusion to exclude the user.

Remaining tasks

Implement fix to query(ies) or surrounding logic

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States justachris

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024