FIX: wasn't able to remove a user's primary group
This commit is contained in:
parent
519b70ea46
commit
3c0de22bf0
|
@ -135,18 +135,29 @@ class Admin::UsersController < Admin::AdminController
|
||||||
def remove_group
|
def remove_group
|
||||||
group = Group.find(params[:group_id].to_i)
|
group = Group.find(params[:group_id].to_i)
|
||||||
return render_json_error group unless group && !group.automatic
|
return render_json_error group unless group && !group.automatic
|
||||||
|
|
||||||
group.remove(@user)
|
group.remove(@user)
|
||||||
GroupActionLogger.new(current_user, group).log_remove_user_from_group(@user)
|
GroupActionLogger.new(current_user, group).log_remove_user_from_group(@user)
|
||||||
|
|
||||||
render nothing: true
|
render nothing: true
|
||||||
end
|
end
|
||||||
|
|
||||||
def primary_group
|
def primary_group
|
||||||
group = Group.find(params[:primary_group_id].to_i)
|
|
||||||
guardian.ensure_can_change_primary_group!(@user)
|
guardian.ensure_can_change_primary_group!(@user)
|
||||||
if group.users.include?(@user)
|
|
||||||
@user.primary_group_id = params[:primary_group_id]
|
if params[:primary_group_id].present?
|
||||||
@user.save!
|
primary_group_id = params[:primary_group_id].to_i
|
||||||
|
if group = Group.find(primary_group_id)
|
||||||
|
if group.user_ids.include?(@user.id)
|
||||||
|
@user.primary_group_id = primary_group_id
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@user.primary_group_id = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
@user.save!
|
||||||
|
|
||||||
render nothing: true
|
render nothing: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -228,6 +228,13 @@ describe Admin::UsersController do
|
||||||
@another_user.reload
|
@another_user.reload
|
||||||
expect(@another_user.primary_group_id).to be_nil
|
expect(@another_user.primary_group_id).to be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "remove user's primary group" do
|
||||||
|
group.add(@another_user)
|
||||||
|
xhr :put, :primary_group, user_id: @another_user.id, primary_group_id: ""
|
||||||
|
@another_user.reload
|
||||||
|
expect(@another_user.primary_group_id).to be(nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context '.trust_level' do
|
context '.trust_level' do
|
||||||
|
|
Loading…
Reference in New Issue