generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SC-85 Evaluator journey: Download documents (#2023)
- Loading branch information
Showing
16 changed files
with
238 additions
and
4 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions
73
app/controllers/evaluation/download_documents_controller.rb
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
module Evaluation | ||
class DownloadDocumentsController < ApplicationController | ||
before_action :set_current_case | ||
before_action :check_user_is_evaluator | ||
before_action :set_documents | ||
before_action :set_downloaded_documents | ||
before_action :set_download_document, only: %i[update] | ||
before_action { @back_url = evaluation_task_path(@current_case) } | ||
SUPPORTED_TYPES = [ | ||
"Support::EmailAttachment", | ||
"EmailAttachment", | ||
"Support::CaseAttachment", | ||
"EnergyBill", | ||
"Support::EmailTemplateAttachment", | ||
"Support::CaseUploadDocument", | ||
].freeze | ||
def show; end | ||
|
||
def update | ||
update_support_details | ||
send_data @download_document.file.download, type: @download_document.file_type, disposition: "inline", filename: @download_document.file_name | ||
end | ||
|
||
private | ||
|
||
helper_method def current_evaluator | ||
@current_evaluator ||= Support::Evaluator.find_by(support_case_id: params[:id], email: current_user.email) | ||
end | ||
def set_current_case | ||
@current_case = Support::Case.find(params[:id]) | ||
@evaluation_due_date = @current_case.evaluation_due_date? ? @current_case.evaluation_due_date.strftime("%d %B %Y") : nil | ||
end | ||
|
||
def set_downloaded_documents | ||
@downloaded_documents = Support::EvaluatorsDownloadDocument.where(support_case_id: @current_case.id, email: current_user.email) | ||
end | ||
|
||
def check_user_is_evaluator | ||
return if @current_evaluator.nil? || current_user == @current_evaluator.user | ||
|
||
redirect_to root_path, notice: I18n.t("evaluation.tasks.not_permitted") | ||
end | ||
|
||
def set_documents | ||
@documents = @current_case.upload_documents | ||
end | ||
|
||
def download_document_data | ||
[@download_document.file.download, { type: @download_document.file_type, disposition: "inline", filename: @download_document.file_name }] | ||
end | ||
|
||
def update_support_details | ||
Support::EvaluatorsDownloadDocument.upsert( | ||
{ | ||
support_case_upload_document_id: params[:document_id], | ||
support_case_id: @download_document.support_case_id, | ||
email: current_user.email, | ||
has_downloaded_documents: true, | ||
}, | ||
unique_by: %i[email support_case_id support_case_upload_document_id], | ||
) | ||
end | ||
|
||
def set_download_document | ||
@requested_file_type = CGI.unescape(params[:document_type]) | ||
if SUPPORTED_TYPES.include?(@requested_file_type) | ||
@download_document = @requested_file_type.safe_constantize.find(params[:document_id]) | ||
else | ||
head :unsupported_media_type | ||
end | ||
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
15 changes: 15 additions & 0 deletions
15
app/javascript/controllers/download_documents_controller.js
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
// Connects to data-controller="download_documents" | ||
export default class extends Controller { | ||
static targets = ["downloadLinks"] | ||
|
||
connect() { | ||
this.downloadLinksTarget.querySelectorAll('.govuk-link').forEach(link => { | ||
link.addEventListener("click", (e) => { | ||
e.target.closest('.govuk-summary-list__row').querySelector('.dowloaded-icon').classList.remove('govuk-!-display-none'); | ||
}); | ||
}); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Support | ||
class EvaluatorsDownloadDocument < ApplicationRecord | ||
belongs_to :support_case, class_name: "Support::Case" | ||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
app/views/evaluation/download_documents/_document_list.html.erb
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<%= form_with url: evaluation_download_document_path(@current_case), method: :patch do |form| %> | ||
<div class="govuk-form-group govuk-!-static-margin-bottom-8" data-controller="download_documents"> | ||
<dl class="govuk-summary-list" data-download_documents-target="downloadLinks"> | ||
<% @documents.each do |document| %> | ||
<div class="govuk-summary-list__row"> | ||
<dd class="govuk-summary-list__value"> | ||
<%= link_to document.file_name, evaluation_download_document_path(@current_case, document_type: document.class, document_id: document.id), method: :put, class: "govuk-link" %> | ||
</dd> | ||
<% hideClass = @downloaded_documents.present? && @downloaded_documents.map(&:support_case_upload_document_id).include?(document.id) ? '' : 'govuk-!-display-none' %> | ||
<dd class="govuk-summary-list__value govuk-!-padding-top-4 dowloaded-icon <%= hideClass%>"> | ||
<%= image_tag "tick.svg", alt: "Already downloaded", width: "24", height: "24" %> | ||
</dd> | ||
</div> | ||
<% end %> | ||
</dl> | ||
</div> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<%= render partial: "support/cases/components/case_header", | ||
locals: { current_case: @current_case } %> | ||
<h1 class="govuk-heading-l"><%= I18n.t("evaluation.download_documents.header") %></h1> | ||
<p class="govuk-body">Use these documents to complete your evaluation of each supplier</p> | ||
<p class="govuk-body govuk-!-static-margin-bottom-8">If you have a problem or conflict of interest, | ||
<% mail_to_address = "mailto:#{ENV.fetch('MS_GRAPH_SHARED_MAILBOX_ADDRESS')}?subject= Case #{ @current_case.ref} - query" %> | ||
<%= link_to "contact us", mail_to_address , class: "govuk-link" %> | ||
</p> | ||
<%= render "document_list"%> | ||
<div class="govuk-button-group flex-align-center"> | ||
<%= link_to I18n.t("generic.button.continue"), @back_url, class: "govuk-button" %> | ||
<%= link_to I18n.t("generic.button.cancel"), @back_url, class: "govuk-link govuk-link--no-visited-state" %> | ||
</div> |
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
12 changes: 12 additions & 0 deletions
12
db/migrate/20250110150114_add_support_evaluators_download_documents.rb
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class AddSupportEvaluatorsDownloadDocuments < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table "support_evaluators_download_documents", id: :uuid do |t| | ||
t.references "support_case", type: :uuid | ||
t.references "support_case_upload_document", type: :uuid | ||
t.string "email", null: false | ||
t.boolean "has_downloaded_documents", default: false | ||
t.timestamps | ||
t.index %w[email support_case_id support_case_upload_document_id], unique: true | ||
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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require "rails_helper" | ||
describe "Evaluator can see uploaded documents", :js do | ||
let(:support_case) { create(:support_case) } | ||
let(:user) { create(:user) } | ||
let(:file_1) { fixture_file_upload(Rails.root.join("spec/fixtures/support/text-file.txt"), "text/plain") } | ||
let(:file_2) { fixture_file_upload(Rails.root.join("spec/fixtures/support/another-text-file.txt"), "text/plain") } | ||
let(:document_uploader) { support_case.document_uploader(files: [file_1, file_2]) } | ||
|
||
specify "Evaluator can download documents" do | ||
create(:support_evaluator, support_case:, dsi_uid: user.dfe_sign_in_uid, email: user.email) | ||
|
||
Current.user = user | ||
|
||
user_exists_in_dfe_sign_in(user:) | ||
|
||
user_is_signed_in(user:) | ||
|
||
expect { document_uploader.save! }.to change { support_case.upload_documents.count }.from(0).to(2) | ||
|
||
visit evaluation_task_path(support_case) | ||
|
||
expect(page).to have_text("Evaluator task list") | ||
|
||
expect(find("#evaluator_task-1-status")).to have_text("To do") | ||
|
||
visit evaluation_download_document_path(support_case) | ||
|
||
expect(page).to have_text("Download documents") | ||
|
||
expect(page).to have_content("text-file.txt") | ||
|
||
expect(page).to have_content("another-text-file.txt") | ||
|
||
find_all(".govuk-summary-list__row a")[0].click | ||
|
||
visit evaluation_task_path(support_case) | ||
|
||
expect(find("#evaluator_task-1-status")).to have_text("In progress") | ||
|
||
visit evaluation_download_document_path(support_case) | ||
|
||
find_all(".govuk-summary-list__row a")[1].click | ||
|
||
visit evaluation_task_path(support_case) | ||
|
||
expect(find("#evaluator_task-1-status")).to have_text("Complete") | ||
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