Skip to content
Snippets Groups Projects

Issue #3408003 by rawdreeg: Update role exclusion logic to account for users...

1 file
+ 11
13
Compare changes
  • Side-by-side
  • Inline
+ 11
13
@@ -361,24 +361,22 @@ class InactiveUsersHandler {
*/
public function getUsers() {
$exclude_user_roles = $this->emailConfig->get('block_inactive_users_exclude_roles');
$query = $this->userStorage
->getQuery()
->accessCheck(FALSE);
$query = $this->userStorage->getQuery()->accessCheck(TRUE);
// Only return active users.
$query->condition('status', 1);
// Subquery to find users with excluded roles.
if (!empty($exclude_user_roles)) {
$or_group = $query->orConditionGroup();
// If any role excluded, update query condition accordingly.
$or_group->condition('roles', $exclude_user_roles, 'NOT IN');
// IF Roles does not exist, then we want to include all roles.
$or_group->condition('roles', NULL, 'IS NULL');
// If roles is empty, then we want to include all roles.
$query->condition($or_group);
$subquery = $this->userStorage->getQuery()
->condition('roles', $exclude_user_roles, 'IN')
->accessCheck(TRUE)
->execute();
// Assuming execute() returns an array of user IDs, adjust as necessary.
if (!empty($subquery)) {
$query->condition('uid', $subquery, 'NOT IN');
}
}
// Don't block the admin account.
Loading