Add owner to group members after group create
This commit is contained in:
parent
ed9cff9a3c
commit
32ef2f37f6
2 changed files with 14 additions and 18 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue