Commit 32ef2f37 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add owner to group members after group create

parent ed9cff9a
...@@ -72,7 +72,7 @@ class GroupsController < ApplicationController ...@@ -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 ...@@ -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
def add_users(user_ids, group_access) after_create :add_owner
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
def human_name def human_name
name name
end end
def truncate_teams
UsersProject.truncate_teams(project_ids)
end
def owners def owners
@owners ||= (users_groups.owners.map(&:user) << owner) @owners ||= (users_groups.owners.map(&:user) << owner)
end 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
private
def add_owner
self.add_users([owner.id], UsersGroup::OWNER)
end
end end
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