Skip to content

Commit

Permalink
Merge pull request #1978 from DFE-Digital/single-upload-documents
Browse files Browse the repository at this point in the history
Handle documents with a single upload only
  • Loading branch information
thomasleese authored Feb 9, 2024
2 parents 273fd36 + b84e325 commit 5ccb7d4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 14 deletions.
2 changes: 2 additions & 0 deletions app/forms/teacher_interface/upload_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class UploadForm < BaseForm
attr_reader :timeout_error

def update_model
document.uploads.each(&:destroy!) unless document.allow_multiple_uploads?

if original_attachment.present?
document.uploads.create!(
attachment: original_attachment,
Expand Down
15 changes: 12 additions & 3 deletions app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,21 @@ class Document < ApplicationRecord
identification
medium_of_instruction
name_change
signed_consent
unsigned_consent
].freeze

UNTRANSLATABLE_SINGLE_TYPES = %w[signed_consent unsigned_consent].freeze

TRANSLATABLE_TYPES = %w[
qualification_certificate
qualification_document
qualification_transcript
written_statement
].freeze
DOCUMENT_TYPES = (UNTRANSLATABLE_TYPES + TRANSLATABLE_TYPES).freeze

DOCUMENT_TYPES =
(
UNTRANSLATABLE_TYPES + UNTRANSLATABLE_SINGLE_TYPES + TRANSLATABLE_TYPES
).freeze

enum document_type:
DOCUMENT_TYPES.each_with_object({}) { |type, memo| memo[type] = type }
Expand All @@ -58,6 +63,10 @@ def translatable?
TRANSLATABLE_TYPES.include?(document_type)
end

def allow_multiple_uploads?
!UNTRANSLATABLE_SINGLE_TYPES.include?(document_type)
end

def optional?
written_statement? && application_form.written_statement_optional
end
Expand Down
38 changes: 27 additions & 11 deletions app/views/teacher_interface/documents/edit_uploads.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,41 @@
<%= govuk_summary_list do |summary_list|
@document.uploads.order(:created_at).each_with_index do |upload, index|
summary_list.with_row do |row|
row.with_key(text: "File #{index + 1}")
if @document.allow_multiple_uploads?
row.with_key(text: "File #{index + 1}")
end

row.with_value { upload_link_to(upload) }
row.with_action(
text: "Delete",
href: delete_teacher_interface_application_form_document_upload_path(@document, upload),
visually_hidden_text: upload.attachment.filename
)

if @document.allow_multiple_uploads?
row.with_action(
text: "Delete",
href: delete_teacher_interface_application_form_document_upload_path(@document, upload),
visually_hidden_text: upload.attachment.filename
)
else
row.with_action(
text: "Change",
href: new_teacher_interface_application_form_document_upload_path(@document),
visually_hidden_text: upload.attachment.filename
)
end
end
end
end %>

<%= form_with model: @form, url: [:teacher_interface, :application_form, @document], method: :patch do |f| %>
<%= f.govuk_error_summary %>

<%= f.govuk_radio_buttons_fieldset :add_another,
legend: { text: "Do you need to upload another page?" },
hint: { text: "If your document has several pages or you’re providing an image of the other side of your identity card or driving license, you can upload them here. Otherwise, select ‘No’ and then ‘Continue’." } do %>
<%= f.govuk_radio_button :add_another, "true", label: { text: "Yes" } %>
<%= f.govuk_radio_button :add_another, "false", label: { text: "No" } %>
<% if @document.allow_multiple_uploads? %>
<%= f.govuk_radio_buttons_fieldset :add_another,
legend: { text: "Do you need to upload another page?" },
hint: { text: "If your document has several pages or you’re providing an image of the other side of your identity card or driving license, you can upload them here. Otherwise, select ‘No’ and then ‘Continue’." } do %>
<%= f.govuk_radio_button :add_another, "true", label: { text: "Yes" } %>
<%= f.govuk_radio_button :add_another, "false", label: { text: "No" } %>
<% end %>
<% else %>
<%= f.hidden_field :add_another, value: "false" %>
<% end %>

<%= render "shared/save_submit_buttons", f: %>
Expand Down
12 changes: 12 additions & 0 deletions spec/models/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,16 @@
it { is_expected.to be(true) }
end
end

describe "#allow_multiple_uploads?" do
subject(:allow_multiple_uploads?) { document.allow_multiple_uploads? }

it { is_expected.to be(true) }

context "with a single page document" do
before { document.document_type = :signed_consent }

it { is_expected.to be(false) }
end
end
end

0 comments on commit 5ccb7d4

Please sign in to comment.