Class: Projects::CreateFromTemplateService

Inherits:
BaseService
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/projects/create_from_template_service.rb

Instance Attribute Summary collapse

Attributes inherited from BaseService

#current_user, #params

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) ⇒ CreateFromTemplateService

Returns a new instance of CreateFromTemplateService.



9
10
11
12
13
# File 'app/services/projects/create_from_template_service.rb', line 9

def initialize(user, params)
  @current_user = user
  @params = params.to_h.dup
  @template_name = @params.delete(:template_name).presence
end

Instance Attribute Details

#template_nameObject (readonly)

Returns the value of attribute template_name.



7
8
9
# File 'app/services/projects/create_from_template_service.rb', line 7

def template_name
  @template_name
end

Instance Method Details

#executeObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/services/projects/create_from_template_service.rb', line 15

def execute
  return project unless validate_template!

  file = built_in_template&.file || sample_data_template&.file

  override_params = params.dup

  if built_in_template
    params[:file] = built_in_template.file
  elsif sample_data_template
    params[:file] = sample_data_template.file
    params[:sample_data] = true
  end

  GitlabProjectsImportService.new(current_user, params, override_params).execute
ensure
  file&.close
end