Module: RecordsUploads::Concern

Extended by:
ActiveSupport::Concern
Included in:
AttachmentUploader, AvatarUploader, DesignManagement::DesignV432x230Uploader, FileUploader, MetricImageUploader
Defined in:
app/uploaders/records_uploads.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#uploadObject

Returns the value of attribute upload.



7
8
9
# File 'app/uploaders/records_uploads.rb', line 7

def upload
  @upload
end

Instance Method Details

#filenameObject



45
46
47
# File 'app/uploaders/records_uploads.rb', line 45

def filename
  upload&.path ? File.basename(upload.path) : super
end

#readd_uploadObject



29
30
31
32
33
34
35
36
37
38
# File 'app/uploaders/records_uploads.rb', line 29

def readd_upload
  Gitlab::Database::QueryAnalyzers::PreventCrossDatabaseModification.temporary_ignore_tables_in_transaction(
    %w[uploads], url: "https://gitlab.com/gitlab-org/gitlab/-/issues/398199"
  ) do
    uploads.where(model: model, path: upload_path).delete_all
    upload.delete if upload

    self.upload = build_upload.tap(&:save!)
  end
end

#record_upload(_tempfile = nil) ⇒ Object

After storing an attachment, create a corresponding Upload record

NOTE: We’re ignoring the argument passed to this callback because we want the ‘SanitizedFile` object from `CarrierWave::Uploader::Base#file`, not the `Tempfile` object the callback gets.

Called ‘after :store` rubocop: disable CodeReuse/ActiveRecord



22
23
24
25
26
27
# File 'app/uploaders/records_uploads.rb', line 22

def record_upload(_tempfile = nil)
  return unless model
  return unless file && file.exists?

  Upload.transaction { readd_upload }
end

#upload_pathObject

rubocop: enable CodeReuse/ActiveRecord



41
42
43
# File 'app/uploaders/records_uploads.rb', line 41

def upload_path
  File.join(store_dir, filename.to_s)
end