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 Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

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
# File 'app/services/projects/create_from_template_service.rb', line 9

def initialize(user, params)
  @current_user, @params = user, 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


14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/projects/create_from_template_service.rb', line 14

def execute
  return project unless validate_template!

  file = built_in_template&.file

  override_params = params.dup
  params[:file] = file

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