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, organisation: current_user.organisation,
signed_at: Time.zone.now, signed_at: Time.zone.now,
data_protection_officer: current_user, 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 if data_sharing_agreement.save

10
app/helpers/data_sharing_agreement_helper.rb

@ -31,6 +31,16 @@ module DataSharingAgreementHelper
end end
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 private
def data_sharing_agreement_first_line(organisation:, user:) 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-row">
<div class="govuk-grid-column-two-thirds-from-desktop"> <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"> <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> </h2>
<p class="govuk-body-m"> <p class="govuk-body-m">
<% if @data_sharing_agreement %> <% if @data_sharing_agreement %>
@ -15,7 +15,11 @@
<% end %> <% end %>
</p> </p>
<p class="govuk-body-m"><strong>between</strong></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">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> <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> <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> <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> <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.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: <% if @data_sharing_agreement %>
Postal Address: E-mail address: Telephone number:</p> <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 <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 Postal Address: South-west section, 4th Floor, Fry Building, 2 Marsham Street, London, SW1P 4DF
E-mail address: Rachel.Worledge@levellingup.gov.uk </p> 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> <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">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 <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"> <ul class="govuk-list govuk-list--bullet">
<li>Name: <%= name_for_data_sharing_agreement(@data_sharing_agreement, current_user) %></li> <li>Name: <%= name_for_data_sharing_agreement(@data_sharing_agreement, current_user) %></li>
<li>Title: Data Protection Officer</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.belongs_to :data_protection_officer, class_name: "User"
t.datetime :signed_at, null: false 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 t.timestamps
end 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 "organisation_id"
t.bigint "data_protection_officer_id" t.bigint "data_protection_officer_id"
t.datetime "signed_at", null: false 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 "created_at", null: false
t.datetime "updated_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" 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.") expect(flash[:notification_banner_body]).to eq("Your organisation can now submit logs.")
end 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 context "when the user has already accepted the agreement" do
before do before do
DataSharingAgreement.create!( create(:data_sharing_agreement, data_protection_officer: user, organisation: user.organisation)
organisation: user.organisation,
signed_at: Time.zone.now - 1.day,
data_protection_officer: user,
)
end end
it "returns not found" do it "returns not found" do

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

@ -1,6 +1,6 @@
require "rails_helper" 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 before do
Timecop.freeze(Time.zone.local(2023, 1, 10)) Timecop.freeze(Time.zone.local(2023, 1, 10))
allow(view).to receive(:current_user).and_return(user) 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 context "when dpo" do
let(:user) { create(:user, is_dpo: true) } let(:user) { create(:user, is_dpo: true) }
it "shows current date" do it "renders dynamic content" do
render render
# current date
expect(fragment).to have_content("10th day of January 2023") expect(fragment).to have_content("10th day of January 2023")
end # dpo name
it "shows dpo name" do
render
expect(fragment).to have_content("Name: #{user.name}") expect(fragment).to have_content("Name: #{user.name}")
end # org details
expect(fragment).to have_content("[Data provider organisation] of [full address] (“CORE Data Provider”)")
it "shows action buttons" do # header
render 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_button(text: "Accept this agreement")
expect(fragment).to have_link(text: "Cancel", href: "/organisations/#{organisation.id}/details") 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 end
context "when accepted" do context "when accepted" do
let(:data_sharing_agreement) do let(:data_sharing_agreement) do
DataSharingAgreement.create!( create(
:data_sharing_agreement,
organisation:, organisation:,
signed_at: Time.zone.now - 1.day, signed_at: Time.zone.now - 1.day,
data_protection_officer: user,
) )
end end
it "does not show action buttons" do it "renders dynamic content" do
render 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_button(text: "Accept this agreement")
expect(fragment).not_to have_link(text: "Cancel", href: "/organisations/#{organisation.id}/details") expect(fragment).not_to have_link(text: "Cancel", href: "/organisations/#{organisation.id}/details")
end # sees signed_at date
it "sees signed_at date" do
render
expect(fragment).to have_content("9th day of January 2023") expect(fragment).to have_content("9th day of January 2023")
end # 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}")
it "shows dpo name" do
render
expect(fragment).to have_content("Name: #{user.name}")
end end
end end
end end
@ -66,45 +70,47 @@ RSpec.describe "organisations/data_sharing_agreement.html.erb" do
context "when not dpo" do context "when not dpo" do
let(:user) { create(:user) } let(:user) { create(:user) }
it "shows DPO placeholder" do it "renders dynamic content" do
render
expect(fragment).to have_content("Name: [DPO name]")
end
it "shows placeholder date" do
render render
# placeholder date
expect(fragment).to have_content("This agreement is made the [XX] day of [XX] 20[XX]") expect(fragment).to have_content("This agreement is made the [XX] day of [XX] 20[XX]")
end # dpo name placedholder
expect(fragment).to have_content("Name: [DPO name]")
it "does not show action buttons" do # org details
render 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_button(text: "Accept this agreement")
expect(fragment).not_to have_link(text: "Cancel", href: "/organisations/#{organisation.id}/details") 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 end
context "when accepted" do context "when accepted" do
let(:data_sharing_agreement) do let(:data_sharing_agreement) do
DataSharingAgreement.create!( create(
:data_sharing_agreement,
organisation:, organisation:,
signed_at: Time.zone.now - 1.day, signed_at: Time.zone.now - 1.day,
data_protection_officer: user,
) )
end end
it "does not show action buttons" do it "renders dynamic content" do
render 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_button(text: "Accept this agreement")
expect(fragment).not_to have_link(text: "Cancel", href: "/organisations/#{organisation.id}/details") expect(fragment).not_to have_link(text: "Cancel", href: "/organisations/#{organisation.id}/details")
end # 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}")
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}")
end end
end end
end end

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

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

Loading…
Cancel
Save