Improve change group ownership logic

This commit is contained in:
Dmitriy Zaporozhets 2013-06-26 14:51:57 +03:00
parent db03bfa868
commit a5dbe35354
2 changed files with 12 additions and 1 deletions

View file

@ -34,7 +34,7 @@ class Admin::GroupsController < Admin::ApplicationController
owner_id =group_params.delete(:owner_id)
if owner_id
@group.owner = User.find(owner_id)
@group.change_owner(User.find(owner_id))
end
if @group.update_attributes(group_params)

View file

@ -32,6 +32,17 @@ class Group < Namespace
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
def add_owner