create_service.rb 709 字节
Newer Older
1 2
module Groups
  class CreateService < Groups::BaseService
F
Felipe Artur 已提交
3 4
    def initialize(user, params = {})
      @current_user, @params = user, params.dup
5 6
    end

F
Felipe Artur 已提交
7
    def execute
8 9
      @group = Group.new(params)

D
Douwe Maan 已提交
10 11 12 13
      unless Gitlab::VisibilityLevel.allowed_for?(current_user, params[:visibility_level])
        deny_visibility_level(@group)
        return @group
      end
14

15 16 17
      if @group.parent && !can?(current_user, :admin_group, @group.parent)
        @group.parent = nil
        @group.errors.add(:parent_id, 'manage access required to create subgroup')
18

19
        return @group
20 21
      end

D
Douwe Maan 已提交
22
      @group.name ||= @group.path.dup
F
Felipe Artur 已提交
23
      @group.save
24
      @group.add_owner(current_user)
F
Felipe Artur 已提交
25
      @group
26 27 28
    end
  end
end