Skip to content

Commit

Permalink
Fix: Add check for audit certificate deadline for controller actions
Browse files Browse the repository at this point in the history
- Add before_action to check if it's before the financial statement deadline
- Add before_action to check if the audit certificate can be viewed
- Update show view to display appropriate links based on the deadline

Signed-off-by: Louis Kirkham <[email protected]>
  • Loading branch information
TheDancingClown committed Nov 19, 2024
1 parent ceceba6 commit 0871ff7
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 6 deletions.
18 changes: 18 additions & 0 deletions app/controllers/users/audit_certificates_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class Users::AuditCertificatesController < Users::BaseController
before_action :check_if_vocf_is_required!
before_action :check_if_audit_certificate_already_exist!, only: [:create]
before_action :check_if_before_financial_statement_deadline!, only: [:create, :destroy]
before_action :check_if_can_view_audit_certificate!, only: [:show]

expose(:form_answer) do
current_user.account
Expand Down Expand Up @@ -125,4 +127,20 @@ def check_if_vocf_is_required!
def editing_external_accountants_report_guide
File.open(Rails.root.join("lib/assets/Guide-to-Editing-External-Accountant's-Report-Using-Adobe-PDF-Editor.pdf"))
end

def check_if_before_financial_statement_deadline!
if form_answer.after_current_audit_certificates_deadline?
redirect_to dashboard_url,
alert: "You cannot amend the Verification of Commercial Figures after the deadline."
nil
end
end

def check_if_can_view_audit_certificate!
if form_answer.audit_certificate.blank? && form_answer.after_current_audit_certificates_deadline?
redirect_to dashboard_url,
alert: "You cannot upload the Verification of Commercial Figures after the deadline."
nil
end
end
end
11 changes: 11 additions & 0 deletions app/models/form_answer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,21 @@ def submission_end_date
.try(:trigger_at)
end

def financial_statements_due_date
award_year.settings
.deadlines
.audit_certificates_deadline
.try(:trigger_at)
end

def submission_ended?
submission_end_date.present? && (Time.zone.now > submission_end_date)
end

def after_current_audit_certificates_deadline?
financial_statements_due_date && Time.zone.now >= financial_statements_due_date
end

def version_before_deadline
paper_trail.version_at(submission_end_date - 1.minute)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
- if award.audit_certificate.present?
li
= link_to "View verification of commercial figures", users_form_answer_audit_certificate_url(award), class: 'govuk-link', "aria-label" => "View verification of commercial figures for #{award.id} #{award.award_type_full_name + 'Award'}"
- else
- elsif !award.after_current_audit_certificates_deadline?
li
= link_to "Download the External Accountant's Report", users_form_answer_audit_certificate_url(award, format: :pdf), "aria-label" => "Download the external accountant’s report form for #{award.id} for #{award.award_type_full_name + 'Award'}", class: 'govuk-link'
li
Expand Down
10 changes: 5 additions & 5 deletions app/views/users/audit_certificates/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ header.page-header.group class=('page-header-wider govuk-!-margin-bottom-0')
p.govuk-body Please continue with the following steps:
p
ol.govuk-list.govuk-list--number
li
| Download the
= link_to("External Accountant's Report ", users_form_answer_audit_certificate_url(form_answer, format: :pdf))
| and the
li
| Download the
= link_to("External Accountant's Report ", users_form_answer_audit_certificate_url(form_answer, format: :pdf))
| and the
= link_to("Guide to Editing the External Accountant's Report Using Adobe Acrobat PDF Editor", guide_users_form_answer_audit_certificate_url(form_answer, format: :pdf), target: '_blank')
li We recommend that you send the report and the guide to the accountant immediately so that you can agree on the timelines. Let them know if you will be providing revisions to the figures.
li In the External Accountant's Report, provide actual figures if they are different from the estimates submitted at the time of the application or if you made any other changes to the figures. If you make any revisions, you must sign the Applicant's Management's Statement section in the report.
li Once you make the revisions (if any), the accountant may perform their own relevant procedures and will return the completed External Accountant's Report to you.
li Log back in to this online portal and click the "Provide verification of commercial figures" button next to your Shortlisted entries.
li Log back in to this online portal and click the "Provide verification of commercial figures" button next to your Shortlisted entries.
br
p.govuk-body = "Please upload the External Accountant's Report provided by the accountant by <strong>#{Settings.current_audit_certificates_deadline.decorate.formatted_trigger_time}</strong>.".html_safe

Expand Down
59 changes: 59 additions & 0 deletions spec/controllers/users/audit_certificates_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require "rails_helper"

describe Users::AuditCertificatesController, type: :controller do
let!(:user) { create :user, :completed_profile, role: "account_admin" }
let!(:award_year) { AwardYear.current }
let!(:form_answer) { create(:form_answer, :innovation, user: user, award_year: award_year) }

before do
sign_in user
end

describe "GET show" do
describe "before the financial statement deadline" do
let!(:settings) { create(:settings) }

it "should render the template" do
get :show, params: { form_answer_id: form_answer.id }

expect(response).to render_template(:show)
end
end

describe "after the financial statement deadline" do
let!(:settings) { create(:settings, :expired_audit_submission_deadline) }

describe "without an audit certificate" do
it "should redirect to the dashboard" do
get :show, params: { form_answer_id: form_answer.id }

expect(response).to redirect_to dashboard_url
expect(flash[:alert]).to eq("You cannot upload the Verification of Commercial Figures after the deadline.")
end
end

describe "with an audit certificate" do
let!(:audit_certificate) { create(:audit_certificate, form_answer: form_answer) }
it "should render the template" do
get :show, params: { form_answer_id: form_answer.id }

expect(response).to render_template(:show)
end
end
end
end

describe "DELETE destroy" do
describe "after the financial statement deadline" do
let!(:settings) { create(:settings, :expired_audit_submission_deadline) }
let!(:audit_certificate) { create(:audit_certificate, form_answer: form_answer) }

it "should redirect to the dashboard" do
delete :destroy, params: { form_answer_id: form_answer.id }

expect(response).to redirect_to dashboard_url
expect(flash[:alert]).to eq("You cannot amend the Verification of Commercial Figures after the deadline.")
end
end
end
end

0 comments on commit 0871ff7

Please sign in to comment.