Add owner to group members after group create

This commit is contained in:
Dmitriy Zaporozhets 2013-06-18 16:56:31 +03:00
parent ed9cff9a3c
commit 32ef2f37f6
2 changed files with 14 additions and 18 deletions

View file

@ -72,7 +72,7 @@ class GroupsController < ApplicationController
def update
group_params = params[:group].dup
owner_id =group_params.delete(:owner_id)
owner_id = group_params.delete(:owner_id)
if owner_id
@group.owner = User.find(owner_id)

View file

@ -16,29 +16,25 @@ class Group < Namespace
has_many :users_groups, dependent: :destroy
has_many :users, through: :users_groups
after_create :add_owner
def human_name
name
end
def owners
@owners ||= (users_groups.owners.map(&:user) << owner)
end
def add_users(user_ids, group_access)
user_ids.compact.each do |user_id|
self.users_groups.create(user_id: user_id, group_access: group_access)
end
end
def add_users_to_project_teams(user_ids, project_access)
UsersProject.add_users_into_projects(
projects.map(&:id),
user_ids,
project_access
)
end
private
def human_name
name
end
def truncate_teams
UsersProject.truncate_teams(project_ids)
end
def owners
@owners ||= (users_groups.owners.map(&:user) << owner)
def add_owner
self.add_users([owner.id], UsersGroup::OWNER)
end
end