Merge pull request #3378 from techAPJ/patch-1
FIX: show error message if user already exist in group
This commit is contained in:
commit
acf9334ea5
|
@ -52,6 +52,12 @@ const Group = Discourse.Model.extend({
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
// reload member list
|
// reload member list
|
||||||
self.findMembers();
|
self.findMembers();
|
||||||
|
}).catch(function(error) {
|
||||||
|
if (error && error.responseText) {
|
||||||
|
bootbox.alert($.parseJSON(error.responseText).errors[0]);
|
||||||
|
} else {
|
||||||
|
bootbox.alert(I18n.t('generic_error'));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,11 @@ class Admin::GroupsController < Admin::AdminController
|
||||||
end
|
end
|
||||||
|
|
||||||
users.each do |user|
|
users.each do |user|
|
||||||
|
if !group.users.include?(user)
|
||||||
group.add(user)
|
group.add(user)
|
||||||
|
else
|
||||||
|
return render_json_error I18n.t('groups.errors.member_already_exist', username: user.username)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if group.save
|
if group.save
|
||||||
|
|
|
@ -180,6 +180,7 @@ en:
|
||||||
groups:
|
groups:
|
||||||
errors:
|
errors:
|
||||||
can_not_modify_automatic: "You can not modify an automatic group"
|
can_not_modify_automatic: "You can not modify an automatic group"
|
||||||
|
member_already_exist: "'%{username}' is already a member of this group."
|
||||||
default_names:
|
default_names:
|
||||||
everyone: "everyone"
|
everyone: "everyone"
|
||||||
admins: "admins"
|
admins: "admins"
|
||||||
|
|
|
@ -136,6 +136,16 @@ describe Admin::GroupsController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns 422 if member already exists" do
|
||||||
|
group = Fabricate(:group)
|
||||||
|
existing_member = Fabricate(:user)
|
||||||
|
group.add(existing_member)
|
||||||
|
group.save
|
||||||
|
|
||||||
|
xhr :put, :add_members, id: group.id, usernames: existing_member.username
|
||||||
|
expect(response.status).to eq(422)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context ".remove_member" do
|
context ".remove_member" do
|
||||||
|
|
Loading…
Reference in New Issue