Just reporting this to be helpful, we're actually going to work around this a different way on the project we're using it on.

With Core 8.7.x and VBO 2.x this module could successfully add roles to users in bulk based upon a view result. After upgrading to 8.9.x the are no new errors, notices etc, but the array of available roles retuned by the listRoles function is empty, so no job can be run. This is when the VBO is run as an admin will all permissions.

Comments

thomasmurphy created an issue. See original summary.

thomasmurphy’s picture

Title: No roles available for add role VBO action » listRoles returns empty array incorrectly in VBO
adamps’s picture

Status: Active » Postponed (maintainer needs more info)

You say that listRoles() returns empty. You say that you are running as admin with all permissions. Well this is expected, see the comment in preAccess():

Full admins already have permissions so we are wasting our time to continue.

I don't understand how listRoles() is called when you hit the bug. It is called form administerusersbyrole_query_administerusersbyrole_edit_access_alter() so maybe you added the tag administerusersbyrole_edit_access to a view???

The description for this tag is this:

Modifies the user listing results to exclude user accounts that the logged in user does not have permission to modify.

If you are running as admin, then it has no effect because the admin can modify all users.

morvaim’s picture

In the case of administrator listRoles() is not called from administerusersbyrole_query_administerusersbyrole_edit_access_alter(), because in the first condition it says the code should only run if the current user DOES NOT have administer users permission.
\Drupal\views_bulk_operations\src\Form\ConfigureAction calls $action->buildConfigurationForm($form, $form_state) and buildConfigurationForm() calls listRoles() and listRoles() gives back an empty list for admin users in case of preAccess() returns FALSE and preAccess() returns FALSE, because the user has the administer users permission.
So I don't know what could be a solution for this problem, but I think, the problem exists. Just try to change bulk form to views bulk operations form on the user listing view and check with an administrator user can add or remove roles on the user listing page.

adamps’s picture

Priority: Minor » Normal
Status: Postponed (maintainer needs more info) » Active

Thanks the problem is now clear.

adamps’s picture

Title: listRoles returns empty array incorrectly in VBO » Admin user cannot bulk add/remove roles when using VBO
Status: Active » Needs review
StatusFileSize
new989 bytes

I think this might fix it. I would be grateful for any review/testing.

Status: Needs review » Needs work

The last submitted patch, 6: administerusersbyrole.role_action.3172576-6.patch, failed testing. View results

adamps’s picture

Status: Needs work » Needs review
bsuttis’s picture

Confirming I ran into the same issue using a views action to add/remove roles as an Administrator (uid 1), patch provided fixes it.

  • AdamPS committed 464c1e0 on 8.x-3.x
    Issue #3172576 by AdamPS, thomasmurphy, morvaim, bsuttis: Admin user...
adamps’s picture

Status: Needs review » Fixed

Thanks for the confirmation

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.