Merge pull request #4507 from ming-relax/feat-delete-by-email
Remove user from a group by user email
This commit is contained in:
commit
ee9946388c
|
@ -128,6 +128,8 @@ class GroupsController < ApplicationController
|
|||
user = User.find(params[:user_id])
|
||||
elsif params[:username].present?
|
||||
user = User.find_by_username(params[:username])
|
||||
elsif params[:user_email].present?
|
||||
user = User.find_by_email(params[:user_email])
|
||||
else
|
||||
raise Discourse::InvalidParameters.new('user_id or username must be present')
|
||||
end
|
||||
|
|
|
@ -200,19 +200,22 @@ describe GroupsController do
|
|||
end
|
||||
|
||||
it "removes by id" do
|
||||
xhr :delete, :remove_member, id: group.id, user_id: user.id
|
||||
expect do
|
||||
xhr :delete, :remove_member, id: group.id, user_id: user.id
|
||||
|
||||
expect(response).to be_success
|
||||
group.reload
|
||||
expect(group.users.count).to eq(0)
|
||||
expect(response).to be_success
|
||||
group.reload
|
||||
end.to change{group.users.count}.from(1).to(0)
|
||||
end
|
||||
|
||||
it "removes by username" do
|
||||
xhr :delete, :remove_member, id: group.id, username: user.username
|
||||
expect do
|
||||
xhr :delete, :remove_member, id: group.id, username: user.username
|
||||
|
||||
expect(response).to be_success
|
||||
group.reload
|
||||
expect(group.users.count).to eq(0)
|
||||
expect(response).to be_success
|
||||
group.reload
|
||||
|
||||
end.to change{group.users.count}.from(1).to(0)
|
||||
end
|
||||
|
||||
it "removes user.primary_group_id when user is removed from group" do
|
||||
|
@ -224,6 +227,14 @@ describe GroupsController do
|
|||
user.reload
|
||||
expect(user.primary_group_id).to eq(nil)
|
||||
end
|
||||
|
||||
it "removes by user_email" do
|
||||
expect do
|
||||
xhr :delete, :remove_member, id: group.id, user_email: user.email
|
||||
expect(response).to be_success
|
||||
group.reload
|
||||
end.to change{group.users.count}.from(1).to(0)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue