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 included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

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

Returns a new instance of CreateService.


5
6
7
8
# File 'app/services/groups/create_service.rb', line 5

def initialize(user, params = {})
  @current_user, @params = user, params.dup
  @chat_team = @params.delete(:create_chat_team)
end

Instance Method Details

#executeObject


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/services/groups/create_service.rb', line 10

def execute
  remove_unallowed_params
  set_visibility_level

  @group = Group.new(params)

  after_build_hook(@group, params)

  inherit_group_shared_runners_settings

  unless can_use_visibility_level? && can_create_group?
    return @group
  end

  @group.name ||= @group.path.dup

  if create_chat_team?
    response = Mattermost::CreateTeamService.new(@group, current_user).execute
    return @group if @group.errors.any?

    @group.build_chat_team(name: response['name'], team_id: response['id'])
  end

  Group.transaction do
    if @group.save
      @group.add_owner(current_user)
      @group.create_namespace_settings
      Service.create_from_active_default_integrations(@group, :group_id) if Feature.enabled?(:group_level_integrations, default_enabled: true)
    end
  end

  @group
end