gitlab-org--gitlab-foss/app/services/groups/create_service.rb
Dmitriy Zaporozhets 9410f215ea
Add nested groups support to the Groups::CreateService
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2016-12-26 11:56:19 +02:00

34 lines
808 B
Ruby

module Groups
class CreateService < Groups::BaseService
def initialize(user, params = {})
@current_user, @params = user, params.dup
end
def execute
@group = Group.new(params)
unless Gitlab::VisibilityLevel.allowed_for?(current_user, params[:visibility_level])
deny_visibility_level(@group)
return @group
end
parent_id = params[:parent_id]
if parent_id
parent = Group.find(parent_id)
unless can?(current_user, :admin_group, parent)
@group.parent_id = nil
@group.errors.add(:parent_id, 'manage access required to create subgroup')
return @group
end
end
@group.name ||= @group.path.dup
@group.save
@group.add_owner(current_user)
@group
end
end
end