Improve change group ownership logic
This commit is contained in:
parent
db03bfa868
commit
a5dbe35354
2 changed files with 12 additions and 1 deletions
|
@ -34,7 +34,7 @@ class Admin::GroupsController < Admin::ApplicationController
|
||||||
owner_id =group_params.delete(:owner_id)
|
owner_id =group_params.delete(:owner_id)
|
||||||
|
|
||||||
if owner_id
|
if owner_id
|
||||||
@group.owner = User.find(owner_id)
|
@group.change_owner(User.find(owner_id))
|
||||||
end
|
end
|
||||||
|
|
||||||
if @group.update_attributes(group_params)
|
if @group.update_attributes(group_params)
|
||||||
|
|
|
@ -32,6 +32,17 @@ class Group < Namespace
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def change_owner(user)
|
||||||
|
self.owner = user
|
||||||
|
membership = users_groups.where(user_id: user.id).first
|
||||||
|
|
||||||
|
if membership
|
||||||
|
membership.update_attributes(group_access: UsersGroup::OWNER)
|
||||||
|
else
|
||||||
|
add_owner
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def add_owner
|
def add_owner
|
||||||
|
|
Loading…
Reference in a new issue