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])
|
user = User.find(params[:user_id])
|
||||||
elsif params[:username].present?
|
elsif params[:username].present?
|
||||||
user = User.find_by_username(params[:username])
|
user = User.find_by_username(params[:username])
|
||||||
|
elsif params[:user_email].present?
|
||||||
|
user = User.find_by_email(params[:user_email])
|
||||||
else
|
else
|
||||||
raise Discourse::InvalidParameters.new('user_id or username must be present')
|
raise Discourse::InvalidParameters.new('user_id or username must be present')
|
||||||
end
|
end
|
||||||
|
|
|
@ -200,19 +200,22 @@ describe GroupsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "removes by id" do
|
it "removes by id" do
|
||||||
|
expect do
|
||||||
xhr :delete, :remove_member, id: group.id, user_id: user.id
|
xhr :delete, :remove_member, id: group.id, user_id: user.id
|
||||||
|
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
group.reload
|
group.reload
|
||||||
expect(group.users.count).to eq(0)
|
end.to change{group.users.count}.from(1).to(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "removes by username" do
|
it "removes by username" do
|
||||||
|
expect do
|
||||||
xhr :delete, :remove_member, id: group.id, username: user.username
|
xhr :delete, :remove_member, id: group.id, username: user.username
|
||||||
|
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
group.reload
|
group.reload
|
||||||
expect(group.users.count).to eq(0)
|
|
||||||
|
end.to change{group.users.count}.from(1).to(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "removes user.primary_group_id when user is removed from group" do
|
it "removes user.primary_group_id when user is removed from group" do
|
||||||
|
@ -224,6 +227,14 @@ describe GroupsController do
|
||||||
user.reload
|
user.reload
|
||||||
expect(user.primary_group_id).to eq(nil)
|
expect(user.primary_group_id).to eq(nil)
|
||||||
end
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue