Class: Groups::CreateService

Inherits:
BaseService show all
Defined in:
app/services/groups/create_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #group, #params

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#abilities, #can?, #deny_visibility_level, #event_service, #log_info, #notification_service, #repository, #system_hook_service, #todo_service

Methods included from Gitlab::CurrentSettings

#current_application_settings, #fake_application_settings

Constructor Details

#initialize(user, params = {}) ⇒ CreateService

Returns a new instance of CreateService


3
4
5
# File 'app/services/groups/create_service.rb', line 3

def initialize(user, params = {})
  @current_user, @params = user, params.dup
end

Instance Method Details

#executeObject


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/services/groups/create_service.rb', line 7

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
  @group.save
  @group.add_owner(current_user)
  @group
end