Browse Source

Fill in placeholders and persist data in table

CLDC-2322-read-and-sign-data-sharing-agreement
Jack S 2 years ago
parent
commit
3c03635393
  1. 5
      app/controllers/organisations_controller.rb
  2. 10
      app/helpers/data_sharing_agreement_helper.rb
  3. 17
      app/views/organisations/data_sharing_agreement.html.erb
  4. 5
      db/migrate/20230530094653_add_data_sharing_agreement.rb
  5. 5
      db/schema.rb
  6. 15
      spec/factories/data_sharing_agreement.rb
  7. 21
      spec/requests/organisations_controller_spec.rb
  8. 96
      spec/views/organisations/data_sharing_agreement.html.erb_spec.rb
  9. 25
      spec/views/organisations/show.html.erb_spec.rb

5
app/controllers/organisations_controller.rb

@ -170,6 +170,11 @@ class OrganisationsController < ApplicationController
organisation: current_user.organisation,
signed_at: Time.zone.now,
data_protection_officer: current_user,
organisation_name: @organisation.name,
organisation_address: @organisation.address_string,
organisation_phone_number: @organisation.phone,
dpo_email: current_user.email,
dpo_name: current_user.name,
)
if data_sharing_agreement.save

10
app/helpers/data_sharing_agreement_helper.rb

@ -31,6 +31,16 @@ module DataSharingAgreementHelper
end
end
def org_name_for_data_sharing_agreement(data_sharing_agreement, user)
if data_sharing_agreement.present?
data_sharing_agreement.organisation_name
elsif user.is_dpo?
user.organisation.name
else
"[Data provider organisation]"
end
end
private
def data_sharing_agreement_first_line(organisation:, user:)

17
app/views/organisations/data_sharing_agreement.html.erb

@ -3,7 +3,7 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<h2 id="data-provider-organisation-and-department-for-levelling-up-housing-and-communities" class="govuk-heading-l">
[Data provider organisation] and Department for Levelling Up, Housing and Communities
<%= org_name_for_data_sharing_agreement(@data_sharing_agreement, current_user) %> and Department for Levelling Up, Housing and Communities
</h2>
<p class="govuk-body-m">
<% if @data_sharing_agreement %>
@ -15,7 +15,11 @@
<% end %>
</p>
<p class="govuk-body-m"><strong>between</strong></p>
<p class="govuk-body-m">1) [core data provider organisation] of [full address] (“CORE Data Provider”)</p>
<% if @data_sharing_agreement %>
<p class="govuk-body-m">1) <%= @data_sharing_agreement.organisation_name %> of <%= @data_sharing_agreement.organisation_address %> (“CORE Data Provider”)</p>
<% else %>
<p class="govuk-body-m">1) [Data provider organisation] of [full address] (“CORE Data Provider”)</p>
<% end %>
<p class="govuk-body-m">and</p>
<p class="govuk-body-m">2) The Department for Levelling Up, Housing and Communities of 2 Marsham Street, London, SW1P 4DF (“DLUHC”)</p>
<h3 id="1-background" class="govuk-heading-m">1. Background</h3>
@ -101,8 +105,11 @@
<p class="govuk-body-m">11.2. CORE data providers and DLUHC acknowledge that any loss or unauthorised release of the Data can be treated as valid grounds for immediately terminating this agreement by DLUHC.</p>
<h3 id="12-authorised-representatives" class="govuk-heading-m">12. Authorised representatives</h3>
<p class="govuk-body-m">12.1. CORE data providers and DLUHC will each appoint an Authorised Representative to be the primary point of contact in all day-to-day matters relating to this Agreement:</p>
<p class="govuk-body-m">12.2. For [the Data Provider]: Name:
Postal Address: E-mail address: Telephone number:</p>
<% if @data_sharing_agreement %>
<p class="govuk-body-m">12.2. For <%= @data_sharing_agreement.organisation_name %>: Name: <%= @data_sharing_agreement.dpo_name %>, Postal Address: <%= @data_sharing_agreement.organisation_address %>, E-mail address: <%= @data_sharing_agreement.dpo_email %>, Telephone number: <%= @data_sharing_agreement.organisation_phone_number %></p>
<% else %>
<p class="govuk-body-m">12.2. For [Organisation name]: Name: [DPO name], Postal Address: [Organisation address], E-mail address: [DPO email], Telephone number: [Organisation telephone number]</p>
<% end %>
<p class="govuk-body-m">12.3. For DLUHC: Name: Rachel Worledge
Postal Address: South-west section, 4th Floor, Fry Building, 2 Marsham Street, London, SW1P 4DF
E-mail address: Rachel.Worledge@levellingup.gov.uk </p>
@ -118,7 +125,7 @@
<h3 id="16-statutory-compliance" class="govuk-heading-m">16. Statutory compliance</h3>
<p class="govuk-body-m">16.1. The Parties shall comply with all relevant legislation, regulations, orders, statutory instruments and any amendments or re-enactments thereof from the commencement of this agreement.</p>
<p class="govuk-body-m">As witness of which the parties have set their hands on the day and year first above written
signed for and on behalf of [job title of an officer with appropriate delegated authority] for [core data provider name], by:</p>
signed for and on behalf of [job title of an officer with appropriate delegated authority] for <%= org_name_for_data_sharing_agreement(@data_sharing_agreement, current_user) %>, by:</p>
<ul class="govuk-list govuk-list--bullet">
<li>Name: <%= name_for_data_sharing_agreement(@data_sharing_agreement, current_user) %></li>
<li>Title: Data Protection Officer</li>

5
db/migrate/20230530094653_add_data_sharing_agreement.rb

@ -5,6 +5,11 @@ class AddDataSharingAgreement < ActiveRecord::Migration[7.0]
t.belongs_to :data_protection_officer, class_name: "User"
t.datetime :signed_at, null: false
t.string :organisation_name, null: false
t.string :organisation_address, null: false
t.string :organisation_phone_number
t.string :dpo_email, null: false
t.string :dpo_name, null: false
t.timestamps
end

5
db/schema.rb

@ -60,6 +60,11 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_30_094653) do
t.bigint "organisation_id"
t.bigint "data_protection_officer_id"
t.datetime "signed_at", null: false
t.string "organisation_name", null: false
t.string "organisation_address", null: false
t.string "organisation_phone_number"
t.string "dpo_email", null: false
t.string "dpo_name", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["data_protection_officer_id"], name: "index_data_sharing_agreements_on_data_protection_officer_id"

15
spec/factories/data_sharing_agreement.rb

@ -0,0 +1,15 @@
FactoryBot.define do
factory :data_sharing_agreement do
organisation
data_protection_officer { create(:user, is_dpo: true) }
signed_at { Time.zone.now }
created_at { Time.zone.now }
updated_at { Time.zone.now }
dpo_name { data_protection_officer.name }
dpo_email { data_protection_officer.email }
organisation_address { organisation.address_string }
organisation_phone_number { organisation.phone }
organisation_name { organisation.name }
end
end

21
spec/requests/organisations_controller_spec.rb

@ -1518,13 +1518,24 @@ RSpec.describe OrganisationsController, type: :request do
expect(flash[:notification_banner_body]).to eq("Your organisation can now submit logs.")
end
it "creates a data sharing agreement" do
expect(organisation.reload.data_sharing_agreement).to be_nil
post("/organisations/#{organisation.id}/data-sharing-agreement", headers:)
data_sharing_agreement = organisation.reload.data_sharing_agreement
expect(data_sharing_agreement.organisation_address).to eq(organisation.address_string)
expect(data_sharing_agreement.organisation_name).to eq(organisation.name)
expect(data_sharing_agreement.organisation_phone_number).to eq(organisation.phone)
expect(data_sharing_agreement.data_protection_officer).to eq(user)
expect(data_sharing_agreement.dpo_name).to eq(user.name)
expect(data_sharing_agreement.dpo_email).to eq(user.email)
end
context "when the user has already accepted the agreement" do
before do
DataSharingAgreement.create!(
organisation: user.organisation,
signed_at: Time.zone.now - 1.day,
data_protection_officer: user,
)
create(:data_sharing_agreement, data_protection_officer: user, organisation: user.organisation)
end
it "returns not found" do

96
spec/views/organisations/data_sharing_agreement.html.erb_spec.rb

@ -1,6 +1,6 @@
require "rails_helper"
RSpec.describe "organisations/data_sharing_agreement.html.erb" do
RSpec.describe "organisations/data_sharing_agreement.html.erb", :aggregate_failures do
before do
Timecop.freeze(Time.zone.local(2023, 1, 10))
allow(view).to receive(:current_user).and_return(user)
@ -19,46 +19,50 @@ RSpec.describe "organisations/data_sharing_agreement.html.erb" do
context "when dpo" do
let(:user) { create(:user, is_dpo: true) }
it "shows current date" do
it "renders dynamic content" do
render
# current date
expect(fragment).to have_content("10th day of January 2023")
end
it "shows dpo name" do
render
# dpo name
expect(fragment).to have_content("Name: #{user.name}")
end
it "shows action buttons" do
render
# org details
expect(fragment).to have_content("[Data provider organisation] of [full address] (“CORE Data Provider”)")
# header
expect(fragment).to have_css("h2", text: "#{user.organisation.name} and Department for Levelling Up, Housing and Communities")
# action buttons
expect(fragment).to have_button(text: "Accept this agreement")
expect(fragment).to have_link(text: "Cancel", href: "/organisations/#{organisation.id}/details")
# Shows placeholder details in 12.2
expect(fragment).to have_content("12.2. For [Organisation name]: Name: [DPO name], Postal Address: [Organisation address], E-mail address: [DPO email], Telephone number: [Organisation telephone number]")
end
context "when accepted" do
let(:data_sharing_agreement) do
DataSharingAgreement.create!(
create(
:data_sharing_agreement,
organisation:,
signed_at: Time.zone.now - 1.day,
data_protection_officer: user,
)
end
it "does not show action buttons" do
it "renders dynamic content" do
render
# dpo name
expect(fragment).to have_content("Name: #{data_sharing_agreement.dpo_name}")
# org details
expect(fragment).to have_content("#{data_sharing_agreement.organisation_name} of #{data_sharing_agreement.organisation_address} (“CORE Data Provider”)")
# header
expect(fragment).to have_css("h2", text: "#{data_sharing_agreement.organisation_name} and Department for Levelling Up, Housing and Communities")
# does not show action buttons
expect(fragment).not_to have_button(text: "Accept this agreement")
expect(fragment).not_to have_link(text: "Cancel", href: "/organisations/#{organisation.id}/details")
end
it "sees signed_at date" do
render
# sees signed_at date
expect(fragment).to have_content("9th day of January 2023")
end
it "shows dpo name" do
render
expect(fragment).to have_content("Name: #{user.name}")
# Shows filled in details in 12.2
expect(fragment).to have_content("12.2. For #{data_sharing_agreement.organisation_name}: Name: #{data_sharing_agreement.dpo_name}, Postal Address: #{data_sharing_agreement.organisation_address}, E-mail address: #{data_sharing_agreement.dpo_email}, Telephone number: #{data_sharing_agreement.organisation_phone_number}")
end
end
end
@ -66,45 +70,47 @@ RSpec.describe "organisations/data_sharing_agreement.html.erb" do
context "when not dpo" do
let(:user) { create(:user) }
it "shows DPO placeholder" do
render
expect(fragment).to have_content("Name: [DPO name]")
end
it "shows placeholder date" do
it "renders dynamic content" do
render
# placeholder date
expect(fragment).to have_content("This agreement is made the [XX] day of [XX] 20[XX]")
end
it "does not show action buttons" do
render
# dpo name placedholder
expect(fragment).to have_content("Name: [DPO name]")
# org details
expect(fragment).to have_content("[Data provider organisation] of [full address] (“CORE Data Provider”)")
# header
expect(fragment).to have_css("h2", text: "[Data provider organisation] and Department for Levelling Up, Housing and Communities")
# does not show action buttons
expect(fragment).not_to have_button(text: "Accept this agreement")
expect(fragment).not_to have_link(text: "Cancel", href: "/organisations/#{organisation.id}/details")
# Shows placeholder details in 12.2
expect(fragment).to have_content("12.2. For [Organisation name]: Name: [DPO name], Postal Address: [Organisation address], E-mail address: [DPO email], Telephone number: [Organisation telephone number]")
end
context "when accepted" do
let(:data_sharing_agreement) do
DataSharingAgreement.create!(
create(
:data_sharing_agreement,
organisation:,
signed_at: Time.zone.now - 1.day,
data_protection_officer: user,
)
end
it "does not show action buttons" do
it "renders dynamic content" do
render
# sees signed_at date
expect(fragment).to have_content("9th day of January 2023")
# dpo name placedholder
expect(fragment).to have_content("Name: #{data_sharing_agreement.dpo_name}")
# org details
expect(fragment).to have_content("#{data_sharing_agreement.organisation_name} of #{data_sharing_agreement.organisation_address} (“CORE Data Provider”)")
# header
expect(fragment).to have_css("h2", text: "#{data_sharing_agreement.organisation_name} and Department for Levelling Up, Housing and Communities")
# does not show action buttons
expect(fragment).not_to have_button(text: "Accept this agreement")
expect(fragment).not_to have_link(text: "Cancel", href: "/organisations/#{organisation.id}/details")
end
it "sees signed_at date" do
render
expect(fragment).to have_content("9th day of January 2023")
end
it "shows dpo name" do
render
expect(fragment).to have_content("Name: #{user.name}")
# Shows filled in details in 12.2
expect(fragment).to have_content("12.2. For #{data_sharing_agreement.organisation_name}: Name: #{data_sharing_agreement.dpo_name}, Postal Address: #{data_sharing_agreement.organisation_address}, E-mail address: #{data_sharing_agreement.dpo_email}, Telephone number: #{data_sharing_agreement.organisation_phone_number}")
end
end
end

25
spec/views/organisations/show.html.erb_spec.rb

@ -52,13 +52,7 @@ RSpec.describe "organisations/show.html.erb" do
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
let(:data_sharing_agreement) { create(:data_sharing_agreement, organisation:, signed_at: Time.zone.now - 1.day) }
it "includes data sharing agreement row" do
render
@ -108,14 +102,7 @@ RSpec.describe "organisations/show.html.erb" do
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
let(:data_sharing_agreement) { create(:data_sharing_agreement, organisation:, signed_at: Time.zone.now - 1.day) }
it "includes data sharing agreement row" do
render
@ -132,7 +119,7 @@ RSpec.describe "organisations/show.html.erb" do
it "shows show name of who signed the agreement" do
render
expect(fragment).to have_content(dpo.name)
expect(fragment).to have_content(data_sharing_agreement.dpo_name)
end
it "shows link to view data sharing agreement" do
@ -169,11 +156,7 @@ RSpec.describe "organisations/show.html.erb" do
context "when accepted" do
let(:data_sharing_agreement) do
DataSharingAgreement.create!(
organisation:,
signed_at: Time.zone.now - 1.day,
data_protection_officer: user,
)
create(:data_sharing_agreement, organisation:, signed_at: Time.zone.now - 1.day)
end
it "includes data sharing agreement row" do

Loading…
Cancel
Save