-
Notifications
You must be signed in to change notification settings - Fork 21
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
Moj multi upload #7448
base: main
Are you sure you want to change the base?
Moj multi upload #7448
Changes from all commits
19ef5fd
d4dd2f8
fe29381
43569b6
74592d1
e8d3564
5692741
c9f9ae8
ee7a1f2
7157d9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-c origin/main |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
class Publishers::JobListing::DocumentsForm < Publishers::JobListing::VacancyForm | ||
validates :supporting_documents, form_file: DOCUMENT_VALIDATION_OPTIONS | ||
validate :document_presence | ||
validates :supporting_documents, presence: true, if: -> { vacancy.include_additional_documents } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||
|
||
attr_accessor :supporting_documents | ||
|
||
|
@@ -11,13 +10,4 @@ def self.fields | |
def params_to_save | ||
{ completed_steps: params[:completed_steps] } | ||
end | ||
|
||
private | ||
|
||
def document_presence | ||
return unless vacancy.include_additional_documents | ||
return if supporting_documents.present? | ||
|
||
errors.add(:supporting_documents, :blank) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# TODO: - this could be deleted when we move over to Azure storage, which will do the virus check for us | ||
class VirusFreeValidator < ActiveModel::EachValidator | ||
def validate_each(record, attribute, _value) | ||
changes = record.attachment_changes[attribute.to_s] | ||
if changes | ||
changes.attachables.select { |d| d.instance_of?(ActionDispatch::Http::UploadedFile) }.each do |upload_file| | ||
# :nocov: | ||
unless Publishers::DocumentVirusCheck.new(upload_file.tempfile).safe? | ||
Rails.logger.warn("Attempted to upload '#{upload_file.original_filename}' but Google Drive virus check failed") | ||
record.errors.add(attribute, :contains_a_virus) | ||
end | ||
# :nocov: | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
json.file do | ||
json.filename document.original_filename | ||
json.orginalname document.original_filename | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.success true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
- content_for :page_title_prefix, page_title_prefix(step_process, documents_form) | ||
- content_for :page_title_prefix, page_title_prefix(step_process, @documents_form) | ||
|
||
.govuk-grid-row | ||
.govuk-grid-column-two-thirds data-controller="upload-documents" | ||
= form_for documents_form, url: organisation_job_documents_path(vacancy.id) do |f| | ||
div | ||
div data-controller="upload-documents" | ||
= form_for @documents_form, url: organisation_job_documents_path(vacancy.id) do |f| | ||
= f.govuk_error_summary | ||
|
||
- if params["back_to_#{action_name}"] | ||
= f.hidden_field "back_to_#{action_name}", value: "true" | ||
|
||
= f.govuk_file_field :supporting_documents, | ||
label: { text: vacancy_form_page_heading(vacancy, step_process, back_path: back_path), tag: "h1", size: "l" }, | ||
hint: { text: t("helpers.hint.publishers_job_listing_documents_form.documents") }, | ||
accept: ".doc, .docx, .pdf", | ||
multiple: true, | ||
include_hidden: false, | ||
enctype: "multipart/form-data" | ||
= tag.div(class: "moj-multi-file-upload", data: { upload: upload_organisation_job_documents_path(vacancy.id), delete: remove_organisation_job_documents_path(vacancy.id) }) do | ||
.moj-multi-file__uploaded-files | ||
h2 class="govuk-heading-m" = "Files added" | ||
.govuk-summary-list class="moj-multi-file-upload__list" | ||
|
||
.moj-multi-file-upload__upload | ||
= f.govuk_file_field :supporting_documents, | ||
label: { text: vacancy_form_page_heading(vacancy, step_process, back_path: back_path), tag: "h1", size: "l" }, | ||
class: "moj-multi-file-upload__input", | ||
accept: ".doc, .docx, .pdf" | ||
|
||
= render "publishers/vacancies/vacancy_form_partials/submit", f: f |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
json.error do | ||
json.message "#{@document.original_filename} #{vacancy.errors[:supporting_documents].first}" | ||
end | ||
json.partial! "file", document: @document |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
json.success do | ||
json.messageHtml t("jobs.file_upload_success_message", filename: @document.original_filename) | ||
json.messageText t("jobs.file_upload_success_message", filename: @document.original_filename) | ||
end | ||
json.partial! "file", document: @document |
Unchanged files with check annotations Beta
# configuring it using the ENV variables we provide in storage.yml. However, at this point, these ENV vars have not been loaded, | ||
# causing the error. Below we define two throaway ENV vars to prevent the error from being thrown. These are then later overwritten, | ||
# when all of the ENV vars are loaded. | ||
ARG RAILS_MASTER_KEY | ||
Check warning on line 35 in Dockerfile
|
||
ENV DOCUMENTS_S3_BUCKET=throwaway_value | ||
ENV SCHOOLS_IMAGES_LOGOS_S3_BUCKET=throwaway_value | ||
ENV RAILS_MASTER_KEY=$RAILS_MASTER_KEY | ||
Check warning on line 39 in Dockerfile
|
||
RUN RAILS_ENV=production SECRET_KEY_BASE=required-to-run-but-not-used RAILS_SERVE_STATIC_FILES=1 bundle exec rake assets:precompile | ||
ENV COMMIT_SHA=$COMMIT_SHA | ||
EXPOSE 3000 | ||
CMD bundle exec rails db:migrate:ignore_concurrent_migration_exceptions && bundle exec rails s | ||
Check warning on line 72 in Dockerfile
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure this is the right place?
Could we add a
multifile_upload.js
or add it toutils.js
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure - it ought to be in the MoJ library init...