summaryrefslogtreecommitdiff
path: root/app/services/groups/create_service.rb
blob: 46c2a53e1f655dff4d00f26998d182ea822bf16b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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

      @group.name = @group.path.dup unless @group.name
      @group.save
      @group.add_owner(current_user)
      @group
    end
  end
end