Patch #43640
closedImprove Group Controller – Enable Adding/Removing Multiple Users from Users View
Added by Florian Walchshofer 5 months ago. Updated 16 days ago.
Description
To improve efficiency in group management,
extend the functionality to allow bulk operations for adding and removing multiple users directly from the Users view (Administration)
This enhancement should include updates to the controller logic, and users view
Patch changes:- Group Controller - rename method
remove_usertoremove_users- add new route - PATCH -
group_remove_users_path- /groups/:id/remove_users - keep the existing DELETE route, but point it to the renamed method that handles multiple user removal.
delete 'groups/:id/users/:user_id', :to => 'groups#remove_users', :id => /\d+/, :as => 'group_user' post 'groups/:id/remove_users', :to => 'groups#remove_users', :id => /\d+/, :as => 'group_remove_users'
- add new route - PATCH -
- Users View - Administration
- add multiple users to a group (the controller already existed)
- remove multiple users to a group
- Tests & Localization
Files
Related issues
Updated by Holger Just 5 months ago
Generally, I like this feature. I would significantly improve usability for admins with a lots of users.
Some random notes:
- Instead of
post 'groups/:id/remove_users', you could also usedelete 'groups/:id/users'inconfig/routes.rbto match the existing POST URL. We have proper HTTP verbs, let's use them :) - Why are you manually checking the referer in the controller? Can't you just use the
redirect_back_or_defaulthelper? - Why are you rendering an API error in
GroupsController#remove_usersif no user matched? An empty set seems entirely correct and I believe this is also valid everywhere else (including the HTML part) - The generic
confirm: l(:text_are_you_sure)Alert is rather pointless. Yes, there are a few instances of these in Redmine, but we should not add more. Better add a real confirmation which specifically confirms the action taken, including a full list of users being added / deleted. - The context menu option to delete users from a group should filter the groups the selected users are actually in instead of offering all groups. And maybe even disable the option unless there are any groups which each include all of the selected users.
- In the tests, both the existing route as well as the new route should be tested.
Updated by Florian Walchshofer 5 months ago
Thank you, Holger, for your suggestions.
I will address them in the next patch. Please let me know if I understood everything correctly:
- Switch the route from POST to `DELETE /groups/:id/users`
delete 'groups/:id/users', :to => 'groups#remove_users', :id => /\d+/, :as => 'group_remove_users' - Use `redirect_back_or_default` and show the flash notice only when returning to the Users view.
- For the API, return success even if no users matched, to keep the operation idempotent.
Should I also change something in theadd_usersmethod? I copied it from there.def remove_users @users = User.in_group(@group).where(:id => (params[:user_id] || params[:user_ids])).to_a @group.users.delete(@users) respond_to do |format| format.html do flash[:notice] = l(:notice_successful_delete) unless request.referer.presence == edit_group_path(@group, :tab => 'users') redirect_back_or_default edit_group_path(@group, tab: 'users'), referer: true end format.js format.api {render_api_ok} end end - Add a specific confirmation dialog that lists the affected users (or shows a count when there are more than 10).
i will add a new helper, i can not find any in the redmine core - Filter the “Delete from group” context-menu options to only show groups that actually include the selected users (and disable the action when none do).
- In the current test patch, which test is missing here?
Does this align with your expectations before I submit the patch?
Updated by Florian Walchshofer 5 months ago
- File v2-01-group-controller-remove_users.patch v2-01-group-controller-remove_users.patch added
- File v2-03-localization-group-controller-remove_users.patch v2-03-localization-group-controller-remove_users.patch added
- File v2-02-tests-group-controller-remove_users.patch v2-02-tests-group-controller-remove_users.patch added
- File ConfirmDialog.png ConfirmDialog.png added
[PATCH v2] Improve group user management API and context menu
- Switch the route from POST to
DELETE /groups/:id/users - Use helper `redirect_back_or_default`
- API, return success even if no users matched
- Add confirmation dialog
data are from thecontext_menu_controller.rb
Usernames are displayed in the confirmation dialog when the selected count is less than 10,
showing only the selected users, not those who are actually not in the group. - Filter delete/add group, the available fields are this, when one user from the selected is in group or not
- All tests are complete, add context_menus_controller_test, api_test/groups_test.
Update previous tests due to the new group member in the fixtures.
I would also prefer to work on adding multi-user selection and context menu support for
the admin views of groups, users/projects, and project members. (if it is welcomed)
Updated by Florian Walchshofer 3 months ago
- File 0001-group-controller-remove_users.patch 0001-group-controller-remove_users.patch added
- File 0001-localization-group-controller-remove_users.patch 0001-localization-group-controller-remove_users.patch added
- File 0001-tests-group-controller-remove_users.patch 0001-tests-group-controller-remove_users.patch added
I have updated the patches.
This version no longer changes the core fixtures, which makes it much cleaner.
Workflow Run:
https://github.com/FloWalchs/redmine/actions/runs/22871948998
Latest Commits:
https://github.com/FloWalchs/redmine/commits/groupController-multipleUsers/?author=FloWalchs
I'm looking forward to any feedback!
Updated by Marius BĂLTEANU about 1 month ago
- File 0001-Refactor-GroupsController-remove_user-to-remove_user.patch added
- File 0002-Add-or-remove-users-from-group-using-the-context-men.patch added
Florian, I rewrote your patches to better match the existing code, can you test it, please?
I will add later the third patch for confirmation message.
Updated by Florian Walchshofer about 1 month ago
I tested your patch and it works as expected
Thanks for taking the time to rework it.
There is one thing I would still prefer to do differently regarding @common_group_ids .
In the current form it performs an extra query per selected user, and it also applies an exclusive logic:
when I select user 1 and user 2 and both are members of different groups, I end up with nothing to select.
For me, it would be clearer and more consistent to handle this the same way as the Add group selection works with your patch, where all groups are always offered regardless of existing memberships. I actually think this behavior is much better and clearer from a UX point of view.
The following code would therefore be my suggestion here, as it better aligns with that behavior.
@common_group_ids = Group.givable.joins(:groups_users).where(groups_users: { user_id: @users.map(&:id) }).distinct.pluck(:id).to_set
Updated by Marius BĂLTEANU 20 days ago
- File deleted (
0001-Refactor-GroupsController-remove_user-to-remove_user.patch)
Updated by Marius BĂLTEANU 20 days ago
- File deleted (
0002-Add-or-remove-users-from-group-using-the-context-men.patch)
Updated by Marius BĂLTEANU 20 days ago
- File 0001-Refactor-GroupsController-remove_user-to-remove_user.patch 0001-Refactor-GroupsController-remove_user-to-remove_user.patch added
- File 0002-Add-or-remove-users-from-group-using-the-context-men.patch 0002-Add-or-remove-users-from-group-using-the-context-men.patch added
- File 0003-Implement-explicit-confirmation-when-removing-user-s.patch 0003-Implement-explicit-confirmation-when-removing-user-s.patch added
- Target version set to 7.0.0
Florian, thanks for testing and for your feedback. I've integrated the change in the second patch, now the "Remove from group" option show all groups of the selected users. The last patch implements the explicit confirmation message when removing a user or multiple users from a group. The old way that use the browser alert window was removed.
Updated by Florian Walchshofer 19 days ago
- File 0004-Ensure-correct-redirect-after-user-removal-conf.patch 0004-Ensure-correct-redirect-after-user-removal-conf.patch added
Added patch 0004 to improve correct redirect behavior after user removal confirmation.
- Introduces
@back = back_urlin the GroupsController#remove_users,
so the cancel button correctly returns to the originating context (users/groups) - Redirects to the appropriate page after submit by passing
@backvia ahidden_field_tagin the remove_users confirmation view - Adds a success notice (flash[:notice]) for better user feedback,
GroupsController#add_usersfor add_users only html view
thanks for the clear and well-structured sequence of patches.
Updated by Holger Just 18 days ago
Starting from the 0003 patch (and changed in the 0004 patch), I'm not sure where the initial @back_url variable comes from which is accessed from the view.
In any case, the back_url generally needs to be validated before it can be used. At least the Cancel link does not do this in the patch series and would thus allow an attacker to add an unvalidated link there (and thus a possible XSS).
Updated by Florian Walchshofer 18 days ago
- File 0004b-Validate-back-url-in-user-removal-confirmation-.patch 0004b-Validate-back-url-in-user-removal-confirmation-.patch added
In the updated patch (0004b), I removed the @back variable from GroupsController again, as it was unnecessary and not a good approach.
Validation is now handled via helper methods ( cancel_button_tag and back_url_hidden_field_tag ),
so the back_url is properly checked before being used, including for the cancel link.
Updated by Marius BĂLTEANU 17 days ago
- Status changed from New to Resolved
- Assignee set to Marius BĂLTEANU
I've committed the patches!
Holger, thanks for reviewing the code and for pointing out the XSS issues.
I will add a few more tests in the following days for better coverage, including assertions for XSS protection.
Updated by Marius BĂLTEANU 16 days ago
- Status changed from Resolved to Closed
I've added a few more test cases for this feature.
Updated by Go MAEDA 10 days ago
- Related to Patch #44115: GroupsController#remove_users tests fail randomly added
