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
|
def update
|
||||||
group_params = params[:group].dup
|
group_params = params[:group].dup
|
||||||
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.owner = User.find(owner_id)
|
||||||
|
|
|
@ -16,29 +16,25 @@ class Group < Namespace
|
||||||
has_many :users_groups, dependent: :destroy
|
has_many :users_groups, dependent: :destroy
|
||||||
has_many :users, through: :users_groups
|
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)
|
def add_users(user_ids, group_access)
|
||||||
user_ids.compact.each do |user_id|
|
user_ids.compact.each do |user_id|
|
||||||
self.users_groups.create(user_id: user_id, group_access: group_access)
|
self.users_groups.create(user_id: user_id, group_access: group_access)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_users_to_project_teams(user_ids, project_access)
|
private
|
||||||
UsersProject.add_users_into_projects(
|
|
||||||
projects.map(&:id),
|
|
||||||
user_ids,
|
|
||||||
project_access
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
def human_name
|
def add_owner
|
||||||
name
|
self.add_users([owner.id], UsersGroup::OWNER)
|
||||||
end
|
|
||||||
|
|
||||||
def truncate_teams
|
|
||||||
UsersProject.truncate_teams(project_ids)
|
|
||||||
end
|
|
||||||
|
|
||||||
def owners
|
|
||||||
@owners ||= (users_groups.owners.map(&:user) << owner)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue