Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions app/models/attachment_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ class AttachmentData < ApplicationRecord

OPENDOCUMENT_EXTENSIONS = %w[ODT ODP ODS].freeze

def filename
file&.file&.filename
end

def filename_without_extension
filename && filename.sub(/.[^.]*$/, "")
end
Expand All @@ -38,21 +34,12 @@ def pdf?
content_type == AttachmentUploader::PDF_CONTENT_TYPE
end

def txt?
file_extension == "txt"
end

def csv?
return file_extension.casecmp("csv").zero? if file_extension

false
end

# Is in OpenDocument format? (see https://en.wikipedia.org/wiki/OpenDocument)
def opendocument?
OPENDOCUMENT_EXTENSIONS.include? file_extension.upcase
end

def indexable?
AttachmentUploader::INDEXABLE_TYPES.include?(file_extension)
end
Expand All @@ -77,12 +64,6 @@ def auth_bypass_ids
attachable && attachable.respond_to?(:auth_bypass_id) ? [attachable.auth_bypass_id].compact : []
end

def redirect_url
return nil unless unpublished?

unpublished_attachable.unpublishing.document_url
end

def keep_existing_file?
to_replace_id.present? && keep_or_replace != "replace"
end
Expand Down
15 changes: 1 addition & 14 deletions app/models/call_for_evidence_response_form_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,7 @@ class CallForEvidenceResponseFormData < ApplicationRecord
validates :file, presence: true

def all_asset_variants_uploaded?
asset_variants = assets.map(&:variant).map(&:to_sym)
required_variants = [Asset.variants[:original].to_sym]

return false if (required_variants - asset_variants).any?

assets_match_updated_image_filename
end

def filename
file.present? && file.file.filename
end

def assets_match_updated_image_filename
assets.all? { |asset| asset.filename.include?(filename) } if filename
super && assets_match_updated_image_filename
end

def attachable
Expand Down
21 changes: 20 additions & 1 deletion app/models/concerns/asset_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ module AssetData

delegate :unpublished?, to: :unpublished_attachable

delegate :auth_bypass_id, to: :attachable
delegate :auth_bypass_id, to: :attachable, allow_nil: true

delegate :url, :path, :content_type, to: :file, allow_nil: true

def attachable
Attachable::Null.new
Expand All @@ -25,6 +27,8 @@ def auth_bypass_ids
return [] if auth_bypass_id.blank?

[auth_bypass_id]
rescue NoMethodError
[]
end

def access_limitation_organisation_ids
Expand Down Expand Up @@ -107,6 +111,21 @@ def attachable_url
end
end

def filename
file&.file&.filename
end

def all_asset_variants_uploaded?
asset_variants = assets.map(&:variant).map(&:to_sym)
required_variants = file.active_version_names + [:original]

(required_variants - asset_variants).empty?
end

def assets_match_updated_image_filename
assets.all? { |asset| asset.filename.include?(filename) } if filename
end

private

def filtered_attachments(include_deleted_attachables: false)
Expand Down
15 changes: 1 addition & 14 deletions app/models/consultation_response_form_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,7 @@ class ConsultationResponseFormData < ApplicationRecord
validates :file, presence: true

def all_asset_variants_uploaded?
asset_variants = assets.map(&:variant).map(&:to_sym)
required_variants = [Asset.variants[:original].to_sym]

return false if (required_variants - asset_variants).any?

assets_match_updated_image_filename
end

def filename
file.present? && file.file.filename
end

def assets_match_updated_image_filename
assets.all? { |asset| asset.filename.include?(filename) } if filename
super && assets_match_updated_image_filename
end

def attachable
Expand Down
5 changes: 0 additions & 5 deletions app/models/external_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ def should_generate_new_friendly_id?
false
end

# Is in OpenDocument format? (see https://en.wikipedia.org/wiki/OpenDocument)
def opendocument?
false
end

def file_extension
""
end
Expand Down
1 change: 0 additions & 1 deletion app/models/file_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class FileAttachment < Attachment
:content_type,
:pdf?,
:csv?,
:opendocument?,
:file_extension,
:file_size,
:number_of_pages,
Expand Down
5 changes: 0 additions & 5 deletions app/models/html_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ def csv?
false
end

# Is in OpenDocument format? (see https://en.wikipedia.org/wiki/OpenDocument)
def opendocument?
false
end

def content_type
"text/html"
end
Expand Down
4 changes: 0 additions & 4 deletions app/models/image_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ def attachments
images
end

def filename
file&.file&.filename
end

def auth_bypass_ids
images
.filter { |image| Edition::PRE_PUBLICATION_STATES.include? image.edition.state }
Expand Down
6 changes: 0 additions & 6 deletions app/uploaders/image_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ def image_cache
end
end

def active_version_names
# active_versions is protected, so it can only be called by subclasses
# it returns an array of [key, value] pairs, and we want the keys
active_versions.map(&:first)
end

def height_range
return unless bitmap?(file)

Expand Down
6 changes: 6 additions & 0 deletions app/uploaders/whitehall_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ def asset_params
assetable_type: model.class.to_s,
}.deep_stringify_keys
end

def active_version_names
# active_versions is protected, so it can only be called by subclasses
# it returns an array of [key, value] pairs, and we want the keys
active_versions.map(&:first)
end
end