-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Attachment code in Publications, Consultations, and calls for evidence was recently updated to render locally rather than using the pre-rendered HTML from whitehall - We move some of the duplicated code into the Content Item::Attachment concern, and delete the existing code there (which wasn't being used), and provide a utility method to simplify some of the unavoidably repeated code. - Coverage slightly improved (presumable due to the deleted unused method).
- Loading branch information
Showing
4 changed files
with
25 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
module ContentItem | ||
module Attachments | ||
def attachment_details(attachment_id) | ||
content_item.dig("details", "attachments")&.find do |attachment| | ||
attachment["id"] == attachment_id | ||
def attachments | ||
return [] unless content_item["details"]["attachments"] | ||
|
||
docs = content_item["details"]["attachments"].select { |a| !a.key?("locale") || a["locale"] == locale } | ||
docs.each do |doc| | ||
doc["type"] = "html" unless doc["content_type"] | ||
doc["type"] = "external" if doc["attachment_type"] == "external" | ||
doc["preview_url"] = "#{doc['url']}/preview" if doc["preview_url"] | ||
doc["alternative_format_contact_email"] = nil if doc["accessible"] == true | ||
end | ||
end | ||
|
||
def attachments_from(attachment_id_list) | ||
attachments.select { |doc| (attachment_id_list || []).include? doc["id"] } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters