Class: Wikis::CreateAttachmentService

Inherits:
Files::CreateService show all
Defined in:
app/services/wikis/create_attachment_service.rb

Constant Summary collapse

ATTACHMENT_PATH =
'uploads'
MAX_FILENAME_LENGTH =
255

Constants inherited from Files::BaseService

Files::BaseService::FileChangedError

Constants inherited from Commits::CreateService

Commits::CreateService::ValidationError

Instance Attribute Summary collapse

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from Files::BaseService

#file_has_changed?

Methods inherited from Commits::CreateService

#execute

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(container:, current_user: nil, params: {}) ⇒ CreateAttachmentService

Returns a new instance of CreateAttachmentService.



13
14
15
16
17
18
19
20
21
# File 'app/services/wikis/create_attachment_service.rb', line 13

def initialize(container:, current_user: nil, params: {})
  super(nil, current_user, params)

  @container = container
  @file_name = clean_file_name(params[:file_name])
  @file_path = File.join(ATTACHMENT_PATH, SecureRandom.hex, @file_name) if @file_name
  @commit_message ||= "Upload attachment #{@file_name}"
  @branch_name ||= wiki.default_branch
end

Instance Attribute Details

#containerObject (readonly)

Returns the value of attribute container.



8
9
10
# File 'app/services/wikis/create_attachment_service.rb', line 8

def container
  @container
end

Instance Method Details

#create_commit!Object



23
24
25
26
27
28
29
# File 'app/services/wikis/create_attachment_service.rb', line 23

def create_commit!
  wiki.create_wiki_repository

  commit_result(create_transformed_commit(@file_content))
rescue Wiki::CouldNotCreateWikiError
  raise_error("Error creating the wiki repository")
end