Problem/Motivation
When logging out all users except Admin, I get the "illegal choice" error. The logs don't tell me much: "Illegal choice 1 in This setting will force logout all users except admin element."
Using Drupal 8.9. Current dev version of the module produces the same error.
Error Screenshot

Steps to reproduce

  1. Install the module
  2. Go to the Role Based User Logout (All Other Users) Configuration /admin/config/force-users-logout/otheruserslogout
  3. Select the "This setting will force logout all users except admin" checkbox
  4. Click on Force Logout
  5. You will notice the error "An illegal choice has been detected. Please contact the site administrator."

Comments

ex DJ created an issue. See original summary.

ex dj’s picture

Issue summary: View changes
cadila’s picture

StatusFileSize
new1.43 KB

Got the same issue, easy fix required

cadila’s picture

Status: Active » Needs review
joshua1234511’s picture

Updated the Issue summary with steps to replicate.

Reviewed the Patch provided in #3
Thanks @ cadila
- The patch applies clean.
- The proposed logic works as intended.
Fixed Working

Rerolled the patch with the changes.

Removed the unused/ additional probably duplicated from Role based from

$roles = Role::loadMultiple();
    $optionarray[] = '';
    foreach ($roles as $rolekey => $roleval) {
      if ($rolekey != 'administrator' && $rolekey != 'authenticated' && $rolekey != 'anonymous') {
        $optionsarray[$rolekey] = $roleval->label();
      }
    }

Not specific with this issue, part of PHPCS
+ /** @var \Drupal\user\UserInterface $user */
Added a new issue to track the PHPCS fixes. So that all the PHPCS issues can be tracked together.

Fix phpcs --standard=Drupal and phpcs --standard=DrupalPractice for the Force Users Logout module

larisse’s picture

Status: Needs review » Needs work

I have a user with only Authenticated user role and I notice that this user is not logout, even after applied this patch. I think this need be fixed, but I'm not sure if this is a another bug and a different issue need to be open. I'll put this in "Needs Work", but feel free to change.

cadila’s picture

larisse’s picture

Hello @Cadila. I'm not able to logout the user with only "Authenticated user" role, even after applied the patch from the issue mentioned in comment #7.

kreynen’s picture

I ran into this in #3287657: Automated Drupal 10 compatibility fixes and was able to reproduce the issue with users that are only Authenticated users that @larisse pointed out after applying the patches. The problem with Authenticated users is that this is an assumed state so the user really isn't in a role at all.

When we're logging out everyone, why start from the user and check to see if they have the roles are logged in? Why not check the uid > 0 of the users with sessions and log out anyone that isn't in the administrator role?

arunkumark’s picture

kreynen’s picture

Status: Needs work » Needs review
kreynen’s picture

Status: Needs review » Needs work

I think this fixes the issue in that users with only the authenticated user role do not generate an error... but they aren't logged out either.

Testing this is simple. With the patched module installed, create a user with no additional roles called test-user. Log into Drupal with test-user.

In another browser, log in as an admin user with permission to admin/config/force-users-logout/otheruserslogout. Check the checkbox next to `This setting will force logout all users except admin` and submit the form by clicking the Force Logout button.

Go back to the browser where you are logged in with the authenticated test-user. You will still be logged in.

Now add test-user to a role. As the admin user, run admin/config/force-users-logout/otheruserslogout again.

The test-user is now logged out.

The underlying issue remains. Users with just the authenticated user role really have no role. They are simply authenticated.

This module is using roles to get the list of users to log out instead of logging out everyone except the current user.

eloivaque’s picture

StatusFileSize
new1.03 KB

Reroll patch with 2.0.1 version.