Browse Source

CLDC-1291 Permitted user can edit scheme name (#717)

* feature to test editing a scheme

* adding editing buttons

* adding scheme_edit_name route

* controller tests for editing name

* edit-name template missing

* edit-name controller action

* edit-name controller action - leftovers

* padding for checkbox fieldset

* added Which organisation owns the housing stock for this scheme? to the check

* testing editing name via controller

* last test

* lint

* wrong button name

* legend is gone

* Save changes
pull/718/head
J G 3 years ago committed by GitHub
parent
commit
8c6dc56f5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/controllers/schemes_controller.rb
  2. 6
      app/models/scheme.rb
  3. 5
      app/views/schemes/details.html.erb
  4. 47
      app/views/schemes/edit_name.html.erb
  5. 7
      app/views/schemes/new.html.erb
  6. 2
      app/views/schemes/show.html.erb
  7. 1
      config/routes.rb
  8. 59
      spec/features/schemes_spec.rb
  9. 110
      spec/requests/schemes_controller_spec.rb

8
app/controllers/schemes_controller.rb

@ -79,6 +79,10 @@ class SchemesController < ApplicationController
render "schemes/check_answers"
end
def edit_name
render "schemes/edit_name"
end
private
def confirm_secondary_page?(page)
@ -97,6 +101,8 @@ private
new_location_path
when "details"
scheme_primary_client_group_path(@scheme)
when "edit-name"
scheme_path(@scheme)
end
end
@ -132,7 +138,7 @@ private
def authenticate_scope!
head :unauthorized and return unless current_user.data_coordinator? || current_user.support?
if %w[show locations primary_client_group confirm_secondary_client_group secondary_client_group support details check_answers].include?(action_name) && !((current_user.organisation == @scheme.owning_organisation) || current_user.support?)
if %w[show locations primary_client_group confirm_secondary_client_group secondary_client_group support details check_answers edit_name].include?(action_name) && !((current_user.organisation == @scheme.owning_organisation) || current_user.support?)
render_not_found and return
end
end

6
app/models/scheme.rb

@ -130,9 +130,9 @@ class Scheme < ApplicationRecord
def display_attributes
[
{ name: "Service code", value: id_to_display },
{ name: "Name", value: service_name },
{ name: "Confidential information", value: sensitive },
{ name: "Housing stock owned by", value: owning_organisation.name },
{ name: "Name", value: service_name, edit: true },
{ name: "Confidential information", value: sensitive, edit: true },
{ name: "Housing stock owned by", value: owning_organisation.name, edit: true },
{ name: "Managed by", value: managing_organisation&.name },
{ name: "Type of scheme", value: scheme_type },
{ name: "Registered under Care Standards Act 2000", value: registered_under_care_act },

5
app/views/schemes/details.html.erb

@ -18,12 +18,15 @@
label: { text: "Scheme name", size: "m" },
hint: { text: "This is how you’ll refer to this supported housing scheme within your organisation. For example, the name could relate to the address or location. You’ll be able to see the client group when selecting it." } %>
<%= f.govuk_check_boxes_fieldset :sensitive,
legend: nil do %>
<%= f.govuk_check_box :sensitive,
1,
0,
checked: @scheme.sensitive?,
multiple: false,
checked: @scheme.sensitive == "Yes",
label: { text: "This scheme contains confidential information" } %>
<% end %>
<% null_option = [OpenStruct.new(id: "", name: "Select an option")] %>
<% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %>

47
app/views/schemes/edit_name.html.erb

@ -0,0 +1,47 @@
<% content_for :title, "Scheme details" %>
<% content_for :before_content do %>
<%= govuk_back_link(
text: "Back",
href: :back,
) %>
<% end %>
<%= render partial: "organisations/headings", locals: { main: "Scheme details", sub: @scheme.service_name } %>
<%= form_for(@scheme, method: :patch) do |f| %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %>
<%= f.govuk_text_field :service_name,
label: { text: "Scheme name", size: "m" },
hint: { text: "This is how you’ll refer to this supported housing scheme within your organisation. For example, the name could relate to the address or location. You’ll be able to see the client group when selecting it." } %>
<%= f.govuk_check_boxes_fieldset :sensitive,
legend: nil do %>
<%= f.govuk_check_box :sensitive,
1,
0,
multiple: false,
checked: @scheme.sensitive == "Yes",
label: { text: "This scheme contains confidential information" } %>
<% end %>
<% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %>
<% if current_user.support? %>
<%= f.govuk_collection_select :owning_organisation_id,
organisations,
:id,
:name,
label: { text: "Which organisation owns the housing stock for this scheme?", size: "m" },
"data-controller": %w[accessible-autocomplete conditional-filter] %>
<% end %>
<%= f.hidden_field :page, value: "edit-name" %>
<%= f.govuk_submit "Save changes" %>
</div>
</div>
<% end %>

7
app/views/schemes/new.html.erb

@ -20,11 +20,14 @@
label: { text: "Scheme name", size: "m" },
hint: { text: "This is how you refer to this supported housing scheme within your organisation. For example, the name could relate to the address or location. You’ll be able to see the client group when selecting it." } %>
<%= f.govuk_check_boxes_fieldset :sensitive,
legend: nil do %>
<%= f.govuk_check_box :sensitive,
"Yes",
checked: @scheme.sensitive?,
1,
0,
multiple: false,
label: { text: "This scheme contains confidential information" } %>
<% end %>
<% null_option = [OpenStruct.new(id: "", name: "Select an option")] %>
<% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %>

2
app/views/schemes/show.html.erb

@ -16,9 +16,11 @@
<div class="govuk-grid-column-two-thirds">
<%= govuk_summary_list do |summary_list| %>
<% @scheme.display_attributes.each do |attr| %>
<% next if current_user.data_coordinator? && attr[:name] == ("Housing stock owned by") %>
<%= summary_list.row do |row| %>
<% row.key { attr[:name].eql?("Registered under Care Standards Act 2000") ? "Registered under Care Standards Act 2000" : attr[:name].to_s.humanize } %>
<% row.value { details_html(attr) } %>
<% row.action(text: "Change", href: scheme_edit_name_path(scheme_id: @scheme.id)) if attr[:edit] %>
<% end %>
<% end %>
<% end %>

1
config/routes.rb

@ -42,6 +42,7 @@ Rails.application.routes.draw do
get "support", to: "schemes#support"
get "details", to: "schemes#details"
get "check-answers", to: "schemes#check_answers"
get "edit-name", to: "schemes#edit_name"
member do
resources :locations

59
spec/features/schemes_spec.rb

@ -665,5 +665,64 @@ RSpec.describe "Schemes scheme Features" do
end
end
end
context "when editing a scheme" do
context "when I visit schemes page" do
before do
visit("schemes")
end
it "shows list of links to schemes" do
schemes.each do |scheme|
expect(page).to have_link(scheme.service_name)
expect(page).to have_content(scheme.primary_client_group)
end
end
context "when I click to see individual scheme" do
let(:scheme) { schemes.first }
before do
click_link(scheme.service_name)
end
it "shows me details about the selected scheme" do
expect(page).to have_content(schemes.first.id_to_display)
expect(page).to have_content(schemes.first.service_name)
expect(page).to have_content(schemes.first.sensitive)
expect(page).to have_content(schemes.first.scheme_type)
expect(page).to have_content(schemes.first.registered_under_care_act)
expect(page).to have_content(schemes.first.primary_client_group)
expect(page).to have_content(schemes.first.secondary_client_group)
expect(page).to have_content(schemes.first.support_type)
expect(page).to have_content(schemes.first.intended_stay)
end
context "when I click to change scheme name" do
before do
click_link("Change", href: "/schemes/#{scheme.id}/edit-name", match: :first)
end
it "shows available fields to edit" do
expect(page).to have_current_path("/schemes/#{scheme.id}/edit-name")
expect(page).to have_content "Scheme details"
end
context "when I edit details" do
before do
fill_in "Scheme name", with: "FooBar"
check "This scheme contains confidential information"
click_button "Save changes"
end
it "lets me see amended details on the show page" do
expect(page).to have_content "FooBar"
expect(page).to have_current_path("/schemes/#{scheme.id}")
end
end
end
end
end
end
end
end

110
spec/requests/schemes_controller_spec.rb

@ -213,7 +213,6 @@ RSpec.describe SchemesController, type: :request do
get "/schemes/#{specific_scheme.id}"
expect(page).to have_content(specific_scheme.id_to_display)
expect(page).to have_content(specific_scheme.service_name)
expect(page).to have_content(specific_scheme.owning_organisation.name)
expect(page).to have_content(specific_scheme.sensitive)
expect(page).to have_content(specific_scheme.id_to_display)
expect(page).to have_content(specific_scheme.service_name)
@ -615,6 +614,22 @@ RSpec.describe SchemesController, type: :request do
end
end
end
context "when editing scheme name details" do
let(:params) { { scheme: { service_name: "testy", sensitive: "1", page: "edit-name" } } }
it "renders scheme show page after successful update" do
follow_redirect!
expect(response).to have_http_status(:ok)
expect(page).to have_content(scheme_to_update.reload.service_name)
end
it "updates a scheme with valid params" do
follow_redirect!
expect(scheme_to_update.reload.service_name).to eq("testy")
expect(scheme_to_update.reload.sensitive).to eq("Yes")
end
end
end
context "when signed in as a support" do
@ -810,6 +825,29 @@ RSpec.describe SchemesController, type: :request do
end
end
end
context "when editing scheme name details" do
let(:another_organisation) { FactoryBot.create(:organisation) }
let(:params) do
{ scheme: { service_name: "testy",
sensitive: "1",
page: "edit-name",
owning_organisation_id: another_organisation.id } }
end
it "renders scheme show page after successful update" do
follow_redirect!
expect(response).to have_http_status(:ok)
expect(page).to have_content(scheme_to_update.reload.service_name)
expect(scheme_to_update.reload.owning_organisation_id).to eq(another_organisation.id)
end
it "updates a scheme with valid params" do
follow_redirect!
expect(scheme_to_update.reload.service_name).to eq("testy")
expect(scheme_to_update.reload.sensitive).to eq("Yes")
end
end
end
end
@ -1208,4 +1246,74 @@ RSpec.describe SchemesController, type: :request do
end
end
end
describe "#edit_name" do
context "when not signed in" do
it "redirects to the sign in page" do
get "/schemes/1/edit-name"
expect(response).to redirect_to("/account/sign-in")
end
end
context "when signed in as a data provider" do
let(:user) { FactoryBot.create(:user) }
before do
sign_in user
get "/schemes/1/edit-name"
end
it "returns 401 unauthorized" do
request
expect(response).to have_http_status(:unauthorized)
end
end
context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) }
let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let!(:another_scheme) { FactoryBot.create(:scheme) }
before do
sign_in user
get "/schemes/#{scheme.id}/edit-name"
end
it "returns a template for a edit-name" do
expect(response).to have_http_status(:ok)
expect(page).to have_content("Scheme details")
expect(page).to have_content("This scheme contains confidential information")
expect(page).not_to have_content("Which organisation owns the housing stock for this scheme?")
end
context "when attempting to access secondary-client-group scheme page for another organisation" do
before do
get "/schemes/#{another_scheme.id}/edit-name"
end
it "returns 404 not_found" do
request
expect(response).to have_http_status(:not_found)
end
end
end
context "when signed in as a support user" do
let(:user) { FactoryBot.create(:user, :support) }
let!(:scheme) { FactoryBot.create(:scheme) }
before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user
get "/schemes/#{scheme.id}/edit-name"
end
it "returns a template for a secondary-client-group" do
expect(response).to have_http_status(:ok)
expect(page).to have_content("Scheme details")
expect(page).to have_content("This scheme contains confidential information")
expect(page).to have_content("Which organisation owns the housing stock for this scheme?")
end
end
end
end

Loading…
Cancel
Save