Browse Source

CLDC-2498 Prevent non-support from editing org name (#1788)

* CLDC-2498 Prevent non-support from editing org name

* Update specs
pull/1798/head
Jack 1 year ago committed by GitHub
parent
commit
9f73e0f3c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      app/helpers/organisation_helper.rb
  2. 1
      app/models/organisation.rb
  3. 5
      app/views/organisations/edit.html.erb
  4. 1
      app/views/organisations/show.html.erb
  5. 5
      spec/models/organisation_spec.rb
  6. 8
      spec/requests/organisations_controller_spec.rb

16
app/helpers/organisation_helper.rb

@ -8,4 +8,20 @@ module OrganisationHelper
current_organisation.name current_organisation.name
end end
end end
def organisation_name_row(user:, organisation:, summary_list:)
summary_list.row do |row|
row.key { "Name" }
row.value { organisation.name }
if user.support?
row.action(
visually_hidden_text: organisation.name.humanize.downcase,
href: edit_organisation_path(organisation),
html_attributes: { "data-qa": "change-#{organisation.name.downcase}" },
)
else
row.action
end
end
end
end end

1
app/models/organisation.rb

@ -104,7 +104,6 @@ class Organisation < ApplicationRecord
def display_organisation_attributes def display_organisation_attributes
[ [
{ name: "Name", value: name, editable: true },
{ name: "Organisation ID", value: "ORG#{id}", editable: false }, { name: "Organisation ID", value: "ORG#{id}", editable: false },
{ name: "Address", value: address_string, editable: true }, { name: "Address", value: address_string, editable: true },
{ name: "Telephone number", value: phone, editable: true }, { name: "Telephone number", value: phone, editable: true },

5
app/views/organisations/edit.html.erb

@ -11,8 +11,9 @@
<%= content_for(:title) %> <%= content_for(:title) %>
</h1> </h1>
<%= f.govuk_text_field :name, <% if current_user.support? %>
autocomplete: "name" %> <%= f.govuk_text_field :name, autocomplete: "name" %>
<% end %>
<%= f.govuk_text_field :address_line1, <%= f.govuk_text_field :address_line1,
label: { text: "Address line 1" }, label: { text: "Address line 1" },

1
app/views/organisations/show.html.erb

@ -14,6 +14,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">
<%= govuk_summary_list do |summary_list| %> <%= govuk_summary_list do |summary_list| %>
<%= organisation_name_row(user: current_user, organisation: @organisation, summary_list:) %>
<% @organisation.display_organisation_attributes.each do |attr| %> <% @organisation.display_organisation_attributes.each do |attr| %>
<% if can_edit_org?(current_user) && attr[:editable] %> <% if can_edit_org?(current_user) && attr[:editable] %>
<%= summary_list.row do |row| %> <%= summary_list.row do |row| %>

5
spec/models/organisation_spec.rb

@ -236,7 +236,7 @@ RSpec.describe Organisation, type: :model do
it "does not include data protection agreement" do it "does not include data protection agreement" do
expect(organisation.display_organisation_attributes).to eq( expect(organisation.display_organisation_attributes).to eq(
[{ editable: true, name: "Name", value: "DLUHC" }, [
{ editable: false, name: "Organisation ID", value: "ORG#{organisation.id}" }, { editable: false, name: "Organisation ID", value: "ORG#{organisation.id}" },
{ editable: true, { editable: true,
name: "Address", name: "Address",
@ -245,7 +245,8 @@ RSpec.describe Organisation, type: :model do
{ editable: false, name: "Type of provider", value: "Local authority" }, { editable: false, name: "Type of provider", value: "Local authority" },
{ editable: false, name: "Registration number", value: "1234" }, { editable: false, name: "Registration number", value: "1234" },
{ editable: false, format: :bullet, name: "Rent periods", value: %w[All] }, { editable: false, format: :bullet, name: "Rent periods", value: %w[All] },
{ editable: false, name: "Owns housing stock", value: "Yes" }], { editable: false, name: "Owns housing stock", value: "Yes" },
],
) )
end end
end end

8
spec/requests/organisations_controller_spec.rb

@ -262,9 +262,9 @@ RSpec.describe OrganisationsController, type: :request do
expect(response.body).to include(organisation.name) expect(response.body).to include(organisation.name)
end end
it "has a change details link" do it "does not include a change details link" do
expected_html = "data-qa=\"change-name\" href=\"/organisations/#{organisation.id}/edit\"" expected_html = "data-qa=\"change-name\" href=\"/organisations/#{organisation.id}/edit\""
expect(response.body).to include(expected_html) expect(response.body).not_to include(expected_html)
end end
it "displays a link to merge organisations" do it "displays a link to merge organisations" do
@ -345,9 +345,9 @@ RSpec.describe OrganisationsController, type: :request do
get "/organisations/#{organisation.id}/edit", headers:, params: {} get "/organisations/#{organisation.id}/edit", headers:, params: {}
end end
it "shows an edit form" do it "shows an edit form without name field" do
expect(response.body).to include("Change #{organisation.name}’s details") expect(response.body).to include("Change #{organisation.name}’s details")
expect(page).to have_field("organisation-name-field") expect(page).not_to have_field("organisation-name-field")
expect(page).to have_field("organisation-phone-field") expect(page).to have_field("organisation-phone-field")
end end
end end

Loading…
Cancel
Save