diff --git a/app/helpers/data_sharing_agreement_helper.rb b/app/helpers/data_sharing_agreement_helper.rb index 4279766db..3ab0abc1c 100644 --- a/app/helpers/data_sharing_agreement_helper.rb +++ b/app/helpers/data_sharing_agreement_helper.rb @@ -2,11 +2,22 @@ module DataSharingAgreementHelper def data_sharing_agreement_row(user:, organisation:, summary_list:) summary_list.row do |row| row.key { "Data Sharing Agreement" } - row.value { organisation.data_sharing_agreement.present? ? "Accepted" : "Not accepted" } row.action( href: data_sharing_agreement_organisation_path(organisation), text: "View agreement", ) + + row.value do + simple_format( + data_sharing_agreement_first_line(organisation:, user:), + wrapper_tag: "span", + class: "govuk-!-margin-right-4", + ) + simple_format( + data_sharing_agreement_second_line(organisation:, user:), + wrapper_tag: "span", + class: "govuk-!-font-weight-regular app-!-colour-muted", + ) + end end end @@ -19,4 +30,24 @@ module DataSharingAgreementHelper "[DPO name]" end end + +private + + def data_sharing_agreement_first_line(organisation:, user:) + return "Not accepted" if organisation.data_sharing_agreement.blank? + + if user.support? + "Accepted #{organisation.data_sharing_agreement.signed_at.strftime('%d/%m/%Y')}" + else + "Accepted" + end + end + + def data_sharing_agreement_second_line(organisation:, user:) + if organisation.data_sharing_agreement.present? + organisation.data_sharing_agreement.data_protection_officer.name if user.support? + else + "Data protection officer must sign" unless user.is_dpo? + end + end end diff --git a/app/views/organisations/show.html.erb b/app/views/organisations/show.html.erb index e2dbb9862..6b87fbdfd 100644 --- a/app/views/organisations/show.html.erb +++ b/app/views/organisations/show.html.erb @@ -21,7 +21,7 @@ <% row.value { details_html(attr) } %> <% row.action( visually_hidden_text: attr[:name].to_s.humanize.downcase, - href: edit_organisation_path, + href: edit_organisation_path(@organisation), html_attributes: { "data-qa": "change-#{attr[:name].downcase}" }, ) %> <% end %> @@ -32,11 +32,13 @@ <% row.action %> <% end %> <% end %> - + <% end %> + <% if FeatureToggle.new_data_sharing_agreement? %> + <%= data_sharing_agreement_row(organisation: @organisation, user: current_user, summary_list: summary_list) %> <% end %> <% end %> <% if FeatureToggle.merge_organisations_enabled? %> -

Is your organisation merging with another? <%= govuk_link_to "Let us know using this form", merge_request_organisation_path %>

+

Is your organisation merging with another? <%= govuk_link_to "Let us know using this form", merge_request_organisation_path(@organisation) %>

<% end %> diff --git a/spec/views/organisations/show.html.erb_spec.rb b/spec/views/organisations/show.html.erb_spec.rb new file mode 100644 index 000000000..762b7786a --- /dev/null +++ b/spec/views/organisations/show.html.erb_spec.rb @@ -0,0 +1,196 @@ +require "rails_helper" + +RSpec.describe "organisations/show.html.erb" do + before do + Timecop.freeze(Time.zone.local(2023, 1, 10)) + allow(view).to receive(:current_user).and_return(user) + assign(:organisation, organisation) + organisation.update!(data_sharing_agreement:) + end + + after do + Timecop.return + end + + let(:fragment) { Capybara::Node::Simple.new(rendered) } + let(:organisation) { user.organisation } + let(:data_sharing_agreement) { nil } + + context "when flag disabled" do + let(:user) { create(:user) } + + before do + allow(FeatureToggle).to receive(:new_data_sharing_agreement?).and_return(false) + end + + it "does not include data sharing agreement row" do + render + + expect(fragment).not_to have_content("Data Sharing Agreement") + end + end + + context "when dpo" do + let(:user) { create(:user, is_dpo: true) } + + it "includes data sharing agreement row" do + render + + expect(fragment).to have_content("Data Sharing Agreement") + end + + it "shows data sharing agreement not accepted" do + render + + expect(fragment).to have_content("Not accepted") + end + + it "shows link to view data sharing agreement" do + render + + expect(fragment).to have_link(text: "View agreement", href: "/organisations/#{organisation.id}/data-sharing-agreement") + end + + context "when accepted" do + let(:data_sharing_agreement) do + DataSharingAgreement.create!( + organisation:, + signed_at: Time.zone.now - 1.day, + data_protection_officer: user, + ) + end + + it "includes data sharing agreement row" do + render + + expect(fragment).to have_content("Data Sharing Agreement") + end + + it "shows data sharing agreement accepted" do + render + + expect(fragment).to have_content("Accepted") + end + + it "shows link to view data sharing agreement" do + render + + expect(fragment).to have_link(text: "View agreement", href: "/organisations/#{organisation.id}/data-sharing-agreement") + end + end + end + + context "when support user" do + let(:user) { create(:user, :support) } + + it "includes data sharing agreement row" do + render + + expect(fragment).to have_content("Data Sharing Agreement") + end + + it "shows data sharing agreement not accepted" do + render + + expect(fragment).to have_content("Not accepted") + end + + it "tells DPO must sign" do + render + + expect(fragment).to have_content("Data protection officer must sign") + end + + it "shows link to view data sharing agreement" do + render + + expect(fragment).to have_link(text: "View agreement", href: "/organisations/#{organisation.id}/data-sharing-agreement") + end + + context "when accepted" do + let(:dpo) { create(:user, is_dpo: true) } + let(:data_sharing_agreement) do + DataSharingAgreement.create!( + organisation:, + signed_at: Time.zone.now - 1.day, + data_protection_officer: dpo, + ) + end + + it "includes data sharing agreement row" do + render + + expect(fragment).to have_content("Data Sharing Agreement") + end + + it "shows data sharing agreement accepted with date" do + render + + expect(fragment).to have_content("Accepted 09/01/2023") + end + + it "shows show name of who signed the agreement" do + render + + expect(fragment).to have_content(dpo.name) + end + + it "shows link to view data sharing agreement" do + render + + expect(fragment).to have_link(text: "View agreement", href: "/organisations/#{organisation.id}/data-sharing-agreement") + end + end + end + + context "when not dpo" do + let(:user) { create(:user) } + + it "includes data sharing agreement row" do + render + + expect(fragment).to have_content("Data Sharing Agreement") + end + + it "shows data sharing agreement not accepted" do + render + expect(fragment).to have_content("Not accepted") + end + + it "tells DPO must sign" do + render + expect(fragment).to have_content("Data protection officer must sign") + end + + it "shows link to view data sharing agreement" do + render + expect(fragment).to have_link(text: "View agreement", href: "/organisations/#{organisation.id}/data-sharing-agreement") + end + + context "when accepted" do + let(:data_sharing_agreement) do + DataSharingAgreement.create!( + organisation:, + signed_at: Time.zone.now - 1.day, + data_protection_officer: user, + ) + end + + it "includes data sharing agreement row" do + render + + expect(fragment).to have_content("Data Sharing Agreement") + end + + it "shows data sharing agreement accepted" do + render + expect(fragment).to have_content("Accepted") + end + + it "shows link to view data sharing agreement" do + render + expect(fragment).to have_link(text: "View agreement", href: "/organisations/#{organisation.id}/data-sharing-agreement") + end + end + end +end