Commit a5dbe353 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Improve change group ownership logic

parent db03bfa8
...@@ -34,7 +34,7 @@ class Admin::GroupsController < Admin::ApplicationController ...@@ -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 ...@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment