On a default Drupal install, users with 'administer permissions' and 'administer users' permissions can go to Administer » User management (/admin/user/user), select multiple users, and then either add or remove roles by using the "Update options" drop down and selecting a role under "Add a role to the selected users" or "Remove a role from the selected users".
However, with Role Delegation this is not possible. Instead, the individual users accounts have to be edited one at a time (on the user edit pages /user/[uid]/edit).
The RoleAssign module is able to implement this functionality, so I assume it must be possible for a module to do. Also, since Role Delegation claims to supersede RoleAssign, implementing this functionality is important in order for that claim to remain true.
I'm happy to provide more info or test patches if needed. Thanks!
Comments
Comment #1
Andrew Schulman commentedshark, I agree that this is an essential feature.
I'm attaching a patch that I believe implements this. Please review and test. After applying the patch, be sure to clear your Drupal cache before going to admin/user/user to see the new batch operations.
Note to role_delegation maintainer(s): I borrowed most of role_delegation_user_operations() from user_user_operations() in user.module.
Comment #2
Andrew Schulman commentedComment #3
Andrew Schulman commentedHm. Although this works, it causes the user module to emit a 'Detected malicious attempt to alter protected user fields' warning in the log. I'll look into this.
Comment #4
Andrew Schulman commentedOK, here's a revised patch that fixes the log warnings. I had to change the operation names from e.g. add_role to role_delegation_add_role, so that user_user_operations() wouldn't worry about the permissions. Please test.
Comment #5
Andrew Schulman commentedComment #6
shark commentedI tested the patch in #4. Works great!
Thanks Andrew.
Comment #7
Andrew Schulman commentedComment #8
Andrew Schulman commentedComment cleanups.
Comment #9
Andrew Schulman commentedThis patch is tested and ready. Can we get it incorporated into a new release? Thanks, Andrew.
Comment #10
David Lesieur commentedCommitted to the DRUPAL-6--1 branch. Thanks for not giving up! :)
This will need to be ported to Drupal 7.
Comment #11
Andrew Schulman commentedHere's a port of this feature to D7.
The approach I used here for providing the operations is a little different than in D6. In the D6 patch I submitted, role_delegation_user_operations() returns a nested array of operations, e.g.
This is actually not right. The API for hook_user_operations (not available for D7 yet, but it's the same) is clear that hook_user_operations() should only return a simple array of operations, not a nested array. However the above works, because in the form API, form_select_options() does accept nested arrays of options, which it renders as optgroups.
A better approach is to return a simple array, as the API requires, of properly labeled operations, e.g.
Then separately alter the user bulk update form to present these as nested options, as before. The user sees the same thing, but we follow the API, so the operations can also be used elsewhere (e.g. in VBO) and be properly labeled there.
This is what I did for D7. The correction could also be applied in D6, but it's probably not worth the trouble since the existing code works.
Comment #12
Andrew Schulman commentedHere's a slightly corrected patch:
Comment #13
Andrew Schulman commentedFixed committed in 7.x-1.x-dev.