DEV: Show failed to remove members from bulk groups api

Before this commit if you were bulk removing group members and passed in
a user who wasn't currently a member of that group the whole request
would fail. This change will return a 200 response now listing the users
that were removed and those that were skipped.
This commit is contained in:
Blake Erickson
2020-07-22 14:27:43 -06:00
parent 1100b3d185
commit 395d17e2ac
2 changed files with 23 additions and 5 deletions

View File

@ -412,16 +412,25 @@ class GroupsController < ApplicationController
end
end
removed_users = []
skipped_users = []
users.each do |user|
if group.remove(user)
removed_users << user.username
GroupActionLogger.new(current_user, group).log_remove_user_from_group(user)
else
raise Discourse::InvalidParameters
if group.users.exclude? user
skipped_users << user.username
else
raise Discourse::InvalidParameters
end
end
end
render json: success_json.merge!(
usernames: users.map(&:username)
usernames: removed_users,
skipped_usernames: skipped_users
)
end