FIX: display warning only if all users already added to the group (#10500)

If at least one user can be added to the group, proceed with that action
This commit is contained in:
Krzysztof Kotlarek
2020-08-21 13:38:09 +10:00
committed by GitHub
parent daddad7fd6
commit 7833853cf1
2 changed files with 21 additions and 7 deletions

View File

@ -329,12 +329,12 @@ class GroupsController < ApplicationController
'usernames or emails must be present'
)
end
if (usernames = group.users.where(id: users.map(&:id)).pluck(:username)).present?
usernames_already_in_group = group.users.where(id: users.map(&:id)).pluck(:username)
if usernames_already_in_group.present? && usernames_already_in_group.length == users.length
render_json_error(I18n.t(
"groups.errors.member_already_exist",
username: usernames.sort.join(", "),
count: usernames.size
username: usernames_already_in_group.sort.join(", "),
count: usernames_already_in_group.size
))
else
uniq_users = users.uniq