Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add attachment_data_id to file attachments #9641

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
7 changes: 7 additions & 0 deletions app/models/file_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def publishing_api_details_for_format
filename:,
number_of_pages:,
preview_url:,
attachment_data_id:,
}
end

Expand All @@ -66,6 +67,12 @@ def alternative_format_contact_email
nil
end

def attachment_data_id
return unless csv? && attachable.is_a?(Edition) && attachment_data.all_asset_variants_uploaded?

attachment_data.id
end

def preview_url
return unless csv? && attachable.is_a?(Edition) && attachment_data.all_asset_variants_uploaded?

Expand Down
5 changes: 5 additions & 0 deletions test/unit/app/models/file_attachment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,9 @@ def assert_delegated(attachment, method)
attachment = create(:csv_attachment, attachable: create(:edition))
assert_equal Plek.asset_root + "/media/#{attachment.attachment_data.id}/sample.csv/preview", attachment.publishing_api_details_for_format[:preview_url]
end

test "return media attachment_data_id if all_asset_variants_uploaded?" do
attachment = create(:csv_attachment, attachable: create(:edition))
assert_equal attachment.attachment_data.id, attachment.publishing_api_details_for_format[:attachment_data_id]
end
end