From 871adde398e9c3cc6ffc0d1f4ef8c5a86635b301 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Tue, 29 Mar 2022 14:18:01 +0100 Subject: [PATCH] Add field to views --- app/controllers/users_controller.rb | 4 ++-- app/views/users/edit.html.erb | 8 ++++++++ app/views/users/new.html.erb | 8 ++++++++ app/views/users/show.html.erb | 6 ++++++ spec/features/user_spec.rb | 21 ++++++++++++++++----- spec/requests/users_controller_spec.rb | 15 +++++++++------ 6 files changed, 49 insertions(+), 13 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c4062f6d5..1633c879e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -76,9 +76,9 @@ private def user_params if @user == current_user - params.require(:user).permit(:email, :name, :password, :password_confirmation, :role, :is_dpo) + params.require(:user).permit(:email, :name, :password, :password_confirmation, :role, :is_dpo, :is_key_contact) else - params.require(:user).permit(:email, :name, :role, :is_dpo) + params.require(:user).permit(:email, :name, :role, :is_dpo, :is_key_contact) end end diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 649d4f614..2da85f28b 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -34,6 +34,14 @@ legend: { text: "Are #{current_user == @user ? "you" : "they"} a data protection officer?", size: "m" } %> + <%= f.govuk_collection_radio_buttons :is_key_contact, + [OpenStruct.new(id: false, name: "No"), OpenStruct.new(id: true, name: "Yes")], + :id, + :name, + inline: true, + legend: { text: "Are #{current_user == @user ? "you" : "they"} a key contact?", size: "m" } + %> + <%= f.govuk_submit "Save changes" %> diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 8b89d0c47..fe9cdb3b9 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -39,6 +39,14 @@ legend: { text: "Are #{current_user == @user ? "you" : "they"} a data protection officer?", size: "m" } %> + <%= f.govuk_collection_radio_buttons :is_key_contact, + [OpenStruct.new(id: false, name: "No"), OpenStruct.new(id: true, name: "Yes")], + :id, + :name, + inline: true, + legend: { text: "Are #{current_user == @user ? "you" : "they"} a key contact?", size: "m" } + %> + <%= f.govuk_submit "Continue" %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 66c0a9145..bd38dc611 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -50,6 +50,12 @@ row.value { @user.is_data_protection_officer? ? "Yes" : "No" } row.action(visually_hidden_text: "are #{current_user == @user ? "you" : "they"} a data protection officer?", href: edit_user_path, html_attributes: { "data-qa": "change-are-#{current_user == @user ? "you" : "they"}-a-data-protection-officer" }) end %> + + <%= summary_list.row do |row| + row.key { 'Key contact' } + row.value { @user.is_key_contact? ? "Yes" : "No" } + row.action(visually_hidden_text: "are #{current_user == @user ? "you" : "they"} a key contact?", href: edit_user_path, html_attributes: { "data-qa": "change-are-#{current_user == @user ? "you" : "they"}-a-key-contact" }) + end %> <% end %> diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index b30f8a855..1e7c7deb3 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -237,16 +237,21 @@ RSpec.describe "User Features" do expect(page).to have_title("Error") end - it "sets name, email, role and is_dpo" do + it "sets name, email, role, is_dpo and is_key_contact fields" do visit("users/new") fill_in("user[name]", with: "New User") fill_in("user[email]", with: "newuser@example.com") choose("user-role-data-provider-field") choose("user-is-dpo-true-field") + choose("user-is-key-contact-true-field") click_button("Continue") - expect( - User.find_by(name: "New User", email: "newuser@example.com", role: "data_provider", is_dpo: true), - ).to be_a(User) + expect(User.find_by( + name: "New User", + email: "newuser@example.com", + role: "data_provider", + is_dpo: true, + is_key_contact: true, + )).to be_a(User) end it "defaults to is_dpo false" do @@ -274,10 +279,16 @@ RSpec.describe "User Features" do first(:link, "Change").click expect(page).to have_field("user[is_dpo]", with: true) choose("user-is-dpo-field") + choose("user-is-key-contact-true-field") fill_in("user[name]", with: "Updated new name") click_button("Save changes") expect(page).to have_title("Updated new name’s account") - expect(User.find_by(name: "Updated new name", role: "data_provider", is_dpo: false)).to be_a(User) + expect(User.find_by( + name: "Updated new name", + role: "data_provider", + is_dpo: false, + is_key_contact: true, + )).to be_a(User) end end end diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index c71eaf0f8..4e64c9714 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -210,13 +210,14 @@ RSpec.describe UsersController, type: :request do expect(whodunnit_actor.id).to eq(user.id) end - context "when user changes email and dpo" do - let(:params) { { id: user.id, user: { name: new_name, email: new_email, is_dpo: "true" } } } + context "when user changes email, dpo, key_contact" do + let(:params) { { id: user.id, user: { name: new_name, email: new_email, is_dpo: "true", is_key_contact: "true" } } } it "allows changing email and dpo" do user.reload expect(user.email).to eq(new_email) expect(user.is_data_protection_officer?).to be true + expect(user.is_key_contact?).to be true end end end @@ -399,12 +400,13 @@ RSpec.describe UsersController, type: :request do end context "when user changes email and dpo" do - let(:params) { { id: user.id, user: { name: new_name, email: new_email, is_dpo: "true" } } } + let(:params) { { id: user.id, user: { name: new_name, email: new_email, is_dpo: "true", is_key_contact: "true" } } } it "allows changing email and dpo" do user.reload expect(user.email).to eq(new_email) expect(user.is_data_protection_officer?).to be true + expect(user.is_key_contact?).to be true end end @@ -443,14 +445,15 @@ RSpec.describe UsersController, type: :request do .to change { other_user.reload.versions.last.actor&.id }.from(nil).to(user.id) end - context "when user changes email and dpo" do - let(:params) { { id: other_user.id, user: { name: new_name, email: new_email, is_dpo: "true" } } } + context "when user changes email, dpo, key_contact" do + let(:params) { { id: other_user.id, user: { name: new_name, email: new_email, is_dpo: "true", is_key_contact: "true" } } } - it "allows changing email and dpo" do + it "allows changing email, dpo, key_contact" do patch "/users/#{other_user.id}", headers: headers, params: params other_user.reload expect(other_user.email).to eq(new_email) expect(other_user.is_data_protection_officer?).to be true + expect(other_user.is_key_contact?).to be true end end