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
|
||||
group = Group.find(params[:group_id].to_i)
|
||||
return render_json_error group unless group && !group.automatic
|
||||
|
||||
group.remove(@user)
|
||||
GroupActionLogger.new(current_user, group).log_remove_user_from_group(@user)
|
||||
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
def primary_group
|
||||
group = Group.find(params[:primary_group_id].to_i)
|
||||
guardian.ensure_can_change_primary_group!(@user)
|
||||
if group.users.include?(@user)
|
||||
@user.primary_group_id = params[:primary_group_id]
|
||||
@user.save!
|
||||
|
||||
if params[:primary_group_id].present?
|
||||
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
|
||||
else
|
||||
@user.primary_group_id = nil
|
||||
end
|
||||
|
||||
@user.save!
|
||||
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
|
|
|
@ -228,6 +228,13 @@ describe Admin::UsersController do
|
|||
@another_user.reload
|
||||
expect(@another_user.primary_group_id).to be_nil
|
||||
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
|
||||
|
||||
context '.trust_level' do
|
||||
|
|
Loading…
Reference in New Issue