From b855a2987e669f35e32c51cb9f04c2a6539729ab Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Thu, 5 Jan 2023 16:27:01 +0000 Subject: [PATCH] change housing provider -> stock owner (#1104) * change housing provider -> stock owner * feat: add case and _ replacements * refactor: rename files * refactor: - changes * housing provider * refactor: registered ... renaming --- app/components/search_component.rb | 2 +- .../organisation_relationships_controller.rb | 34 ++-- app/helpers/navigation_items_helper.rb | 12 +- .../{housing_provider.rb => stock_owner.rb} | 16 +- .../{housing_provider.rb => stock_owner.rb} | 16 +- app/models/form/lettings/subsections/setup.rb | 6 +- app/models/organisation.rb | 4 +- app/models/organisation_relationship.rb | 10 +- app/models/scheme.rb | 2 +- ...rovider_list.erb => _stock_owner_list.erb} | 8 +- ...ider.html.erb => add_stock_owner.html.erb} | 14 +- ...r.html.erb => remove_stock_owner.html.erb} | 10 +- ...oviders.html.erb => stock_owners.html.erb} | 22 +-- config/locales/en.yml | 2 +- config/routes.rb | 10 +- db/seeds.rb | 12 +- spec/features/lettings_log_spec.rb | 2 +- spec/features/schemes_spec.rb | 4 +- spec/helpers/navigation_items_helper_spec.rb | 22 +-- ...g_provider_spec.rb => stock_owner_spec.rb} | 28 ++-- ...g_provider_spec.rb => stock_owner_spec.rb} | 24 +-- .../form/lettings/subsections/setup_spec.rb | 4 +- spec/models/organisation_relationship_spec.rb | 4 +- spec/models/organisation_spec.rb | 6 +- spec/requests/form_controller_spec.rb | 22 +-- ...anisation_relationships_controller_spec.rb | 146 +++++++++--------- 26 files changed, 221 insertions(+), 221 deletions(-) rename app/models/form/lettings/pages/{housing_provider.rb => stock_owner.rb} (50%) rename app/models/form/lettings/questions/{housing_provider.rb => stock_owner.rb} (75%) rename app/views/organisation_relationships/{_housing_provider_list.erb => _stock_owner_list.erb} (67%) rename app/views/organisation_relationships/{add_housing_provider.html.erb => add_stock_owner.html.erb} (70%) rename app/views/organisation_relationships/{remove_housing_provider.html.erb => remove_stock_owner.html.erb} (66%) rename app/views/organisation_relationships/{housing_providers.html.erb => stock_owners.html.erb} (51%) rename spec/models/form/lettings/pages/{housing_provider_spec.rb => stock_owner_spec.rb} (84%) rename spec/models/form/lettings/questions/{housing_provider_spec.rb => stock_owner_spec.rb} (83%) diff --git a/app/components/search_component.rb b/app/components/search_component.rb index e9fe83a3a..d13882645 100644 --- a/app/components/search_component.rb +++ b/app/components/search_component.rb @@ -15,7 +15,7 @@ class SearchComponent < ViewComponent::Base request.path elsif request.path.include?("organisations") && request.path.include?("schemes") request.path - elsif request.path.include?("organisations") && request.path.include?("housing-providers") + elsif request.path.include?("organisations") && request.path.include?("stock-owners") request.path elsif request.path.include?("organisations") && request.path.include?("managing-agents") request.path diff --git a/app/controllers/organisation_relationships_controller.rb b/app/controllers/organisation_relationships_controller.rb index 9aa93c37c..65617baac 100644 --- a/app/controllers/organisation_relationships_controller.rb +++ b/app/controllers/organisation_relationships_controller.rb @@ -7,19 +7,19 @@ class OrganisationRelationshipsController < ApplicationController before_action :organisations before_action :target_organisation, only: %i[ - remove_housing_provider + remove_stock_owner remove_managing_agent - delete_housing_provider + delete_stock_owner delete_managing_agent ] - def housing_providers - housing_providers = organisation.housing_providers - unpaginated_filtered_housing_providers = filtered_collection(housing_providers, search_term) + def stock_owners + stock_owners = organisation.stock_owners + unpaginated_filtered_stock_owners = filtered_collection(stock_owners, search_term) - @pagy, @housing_providers = pagy(unpaginated_filtered_housing_providers) + @pagy, @stock_owners = pagy(unpaginated_filtered_stock_owners) @searched = search_term.presence - @total_count = housing_providers.size + @total_count = stock_owners.size end def managing_agents @@ -31,7 +31,7 @@ class OrganisationRelationshipsController < ApplicationController @total_count = managing_agents.size end - def add_housing_provider + def add_stock_owner @organisation_relationship = organisation.parent_organisation_relationships.new end @@ -39,14 +39,14 @@ class OrganisationRelationshipsController < ApplicationController @organisation_relationship = organisation.child_organisation_relationships.new end - def create_housing_provider + def create_stock_owner @organisation_relationship = organisation.parent_organisation_relationships.new(organisation_relationship_params) - if @organisation_relationship.save(context: :housing_provider) - flash[:notice] = "#{@organisation_relationship.parent_organisation.name} is now one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} housing providers" - redirect_to housing_providers_organisation_path + if @organisation_relationship.save(context: :stock_owner) + flash[:notice] = "#{@organisation_relationship.parent_organisation.name} is now one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} stock owners" + redirect_to stock_owners_organisation_path else @organisations = Organisation.where.not(id: organisation.id).pluck(:id, :name) - render "organisation_relationships/add_housing_provider", status: :unprocessable_entity + render "organisation_relationships/add_stock_owner", status: :unprocessable_entity end end @@ -61,15 +61,15 @@ class OrganisationRelationshipsController < ApplicationController end end - def remove_housing_provider; end + def remove_stock_owner; end - def delete_housing_provider + def delete_stock_owner OrganisationRelationship.find_by!( child_organisation: organisation, parent_organisation: target_organisation, ).destroy! - flash[:notice] = "#{target_organisation.name} is no longer one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} housing providers" - redirect_to housing_providers_organisation_path + flash[:notice] = "#{target_organisation.name} is no longer one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} stock owners" + redirect_to stock_owners_organisation_path end def remove_managing_agent; end diff --git a/app/helpers/navigation_items_helper.rb b/app/helpers/navigation_items_helper.rb index d996894ea..8db369d59 100644 --- a/app/helpers/navigation_items_helper.rb +++ b/app/helpers/navigation_items_helper.rb @@ -17,7 +17,7 @@ module NavigationItemsHelper NavigationItem.new("Schemes", "/schemes", subnav_supported_housing_schemes_path?(path)), NavigationItem.new("Users", users_organisation_path(current_user.organisation), subnav_users_path?(path)), NavigationItem.new("About your organisation", "/organisations/#{current_user.organisation.id}", subnav_details_path?(path)), - (NavigationItem.new("Housing providers", housing_providers_organisation_path(current_user.organisation), housing_providers_path?(path)) if FeatureToggle.managing_owning_enabled?), + (NavigationItem.new("Stock owners", stock_owners_organisation_path(current_user.organisation), stock_owners_path?(path)) if FeatureToggle.managing_owning_enabled?), (NavigationItem.new("Managing agents", managing_agents_organisation_path(current_user.organisation), managing_agents_path?(path)) if FeatureToggle.managing_owning_enabled?), ].compact else @@ -26,7 +26,7 @@ module NavigationItemsHelper FeatureToggle.sales_log_enabled? ? NavigationItem.new("Sales logs", sales_logs_path, sales_logs_current?(path)) : nil, NavigationItem.new("Users", users_organisation_path(current_user.organisation), subnav_users_path?(path)), NavigationItem.new("About your organisation", "/organisations/#{current_user.organisation.id}", subnav_details_path?(path)), - (NavigationItem.new("Housing providers", housing_providers_organisation_path(current_user.organisation), housing_providers_path?(path)) if FeatureToggle.managing_owning_enabled?), + (NavigationItem.new("Stock owners", stock_owners_organisation_path(current_user.organisation), stock_owners_path?(path)) if FeatureToggle.managing_owning_enabled?), (NavigationItem.new("Managing agents", managing_agents_organisation_path(current_user.organisation), managing_agents_path?(path)) if FeatureToggle.managing_owning_enabled?), ].compact end @@ -40,7 +40,7 @@ module NavigationItemsHelper NavigationItem.new("Schemes", "/organisations/#{current_organisation_id}/schemes", subnav_supported_housing_schemes_path?(path)), NavigationItem.new("Users", "/organisations/#{current_organisation_id}/users", subnav_users_path?(path)), NavigationItem.new("About this organisation", "/organisations/#{current_organisation_id}", subnav_details_path?(path)), - (NavigationItem.new("Housing providers", housing_providers_organisation_path(current_organisation_id), housing_providers_path?(path)) if FeatureToggle.managing_owning_enabled?), + (NavigationItem.new("Stock owners", stock_owners_organisation_path(current_organisation_id), stock_owners_path?(path)) if FeatureToggle.managing_owning_enabled?), (NavigationItem.new("Managing agents", managing_agents_organisation_path(current_organisation_id), managing_agents_path?(path)) if FeatureToggle.managing_owning_enabled?), ].compact else @@ -49,7 +49,7 @@ module NavigationItemsHelper FeatureToggle.sales_log_enabled? ? NavigationItem.new("Sales logs", "/organisations/#{current_organisation_id}/sales-logs", sales_logs_current?(path)) : nil, NavigationItem.new("Users", "/organisations/#{current_organisation_id}/users", subnav_users_path?(path)), NavigationItem.new("About this organisation", "/organisations/#{current_organisation_id}", subnav_details_path?(path)), - (NavigationItem.new("Housing providers", housing_providers_organisation_path(current_organisation_id), housing_providers_path?(path)) if FeatureToggle.managing_owning_enabled?), + (NavigationItem.new("Stock owners", stock_owners_organisation_path(current_organisation_id), stock_owners_path?(path)) if FeatureToggle.managing_owning_enabled?), (NavigationItem.new("Managing agents", managing_agents_organisation_path(current_organisation_id), managing_agents_path?(path)) if FeatureToggle.managing_owning_enabled?), ].compact end @@ -104,8 +104,8 @@ private path.include?("/organisations") && path.include?("/details") end - def housing_providers_path?(path) - path.include?("/housing-providers") + def stock_owners_path?(path) + path.include?("/stock-owners") end def managing_agents_path?(path) diff --git a/app/models/form/lettings/pages/housing_provider.rb b/app/models/form/lettings/pages/stock_owner.rb similarity index 50% rename from app/models/form/lettings/pages/housing_provider.rb rename to app/models/form/lettings/pages/stock_owner.rb index ea801b49c..d142214c5 100644 --- a/app/models/form/lettings/pages/housing_provider.rb +++ b/app/models/form/lettings/pages/stock_owner.rb @@ -1,7 +1,7 @@ -class Form::Lettings::Pages::HousingProvider < ::Form::Page +class Form::Lettings::Pages::StockOwner < ::Form::Page def initialize(id, hsh, subsection) super - @id = "housing_provider" + @id = "stock_owner" @header = "" @description = "" @subsection = subsection @@ -9,7 +9,7 @@ class Form::Lettings::Pages::HousingProvider < ::Form::Page def questions @questions ||= [ - Form::Lettings::Questions::HousingProvider.new(nil, nil, self), + Form::Lettings::Questions::StockOwner.new(nil, nil, self), ] end @@ -17,17 +17,17 @@ class Form::Lettings::Pages::HousingProvider < ::Form::Page return false unless current_user return true if current_user.support? - housing_providers = current_user.organisation.housing_providers + stock_owners = current_user.organisation.stock_owners if current_user.organisation.holds_own_stock? - return true if housing_providers.count >= 1 + return true if stock_owners.count >= 1 log.update!(owning_organisation: current_user.organisation) else - return false if housing_providers.count.zero? - return true if housing_providers.count > 1 + return false if stock_owners.count.zero? + return true if stock_owners.count > 1 - log.update!(owning_organisation: housing_providers.first) + log.update!(owning_organisation: stock_owners.first) end false diff --git a/app/models/form/lettings/questions/housing_provider.rb b/app/models/form/lettings/questions/stock_owner.rb similarity index 75% rename from app/models/form/lettings/questions/housing_provider.rb rename to app/models/form/lettings/questions/stock_owner.rb index f46ea1632..1f4323531 100644 --- a/app/models/form/lettings/questions/housing_provider.rb +++ b/app/models/form/lettings/questions/stock_owner.rb @@ -1,10 +1,10 @@ -class Form::Lettings::Questions::HousingProvider < ::Form::Question +class Form::Lettings::Questions::StockOwner < ::Form::Question attr_accessor :current_user, :log def initialize(id, hsh, page) super @id = "owning_organisation_id" - @check_answer_label = "Housing provider" + @check_answer_label = "Stock owner" @header = "Which organisation owns this property?" @type = "select" @page = page @@ -19,7 +19,7 @@ class Form::Lettings::Questions::HousingProvider < ::Form::Question answer_opts[current_user.organisation.id] = "#{current_user.organisation.name} (Your organisation)" end - answer_opts.merge(housing_providers_answer_options) + answer_opts.merge(stock_owners_answer_options) end def displayed_answer_options(log, user = nil) @@ -44,12 +44,12 @@ class Form::Lettings::Questions::HousingProvider < ::Form::Question return false if current_user.support? - housing_providers = current_user.organisation.housing_providers + stock_owners = current_user.organisation.stock_owners if current_user.organisation.holds_own_stock? - housing_providers.count.zero? + stock_owners.count.zero? else - housing_providers.count <= 1 + stock_owners.count <= 1 end end @@ -63,11 +63,11 @@ private true end - def housing_providers_answer_options + def stock_owners_answer_options if current_user.support? Organisation else - current_user.organisation.housing_providers + current_user.organisation.stock_owners end.pluck(:id, :name).to_h end end diff --git a/app/models/form/lettings/subsections/setup.rb b/app/models/form/lettings/subsections/setup.rb index e871406be..e2dbb7f8b 100644 --- a/app/models/form/lettings/subsections/setup.rb +++ b/app/models/form/lettings/subsections/setup.rb @@ -9,7 +9,7 @@ class Form::Lettings::Subsections::Setup < ::Form::Subsection def pages @pages ||= [ organisation_page, - housing_provider_page, + stock_owner_page, managing_organisation_page, created_by_page, Form::Lettings::Pages::NeedsType.new(nil, nil, self), @@ -35,10 +35,10 @@ private Form::Common::Pages::Organisation.new(nil, nil, self) end - def housing_provider_page + def stock_owner_page return unless FeatureToggle.managing_for_other_user_enabled? - Form::Lettings::Pages::HousingProvider.new(nil, nil, self) + Form::Lettings::Pages::StockOwner.new(nil, nil, self) end def managing_organisation_page diff --git a/app/models/organisation.rb b/app/models/organisation.rb index d0b6b8299..0bf47eb76 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -13,8 +13,8 @@ class Organisation < ApplicationRecord has_many :child_organisation_relationships, foreign_key: :parent_organisation_id, class_name: "OrganisationRelationship" has_many :child_organisations, through: :child_organisation_relationships - has_many :housing_provider_relationships, foreign_key: :child_organisation_id, class_name: "OrganisationRelationship" - has_many :housing_providers, through: :housing_provider_relationships, source: :parent_organisation + has_many :stock_owner_relationships, foreign_key: :child_organisation_id, class_name: "OrganisationRelationship" + has_many :stock_owners, through: :stock_owner_relationships, source: :parent_organisation has_many :managing_agent_relationships, foreign_key: :parent_organisation_id, class_name: "OrganisationRelationship" has_many :managing_agents, through: :managing_agent_relationships, source: :child_organisation diff --git a/app/models/organisation_relationship.rb b/app/models/organisation_relationship.rb index 7f3a85cae..5a4f86938 100644 --- a/app/models/organisation_relationship.rb +++ b/app/models/organisation_relationship.rb @@ -1,17 +1,17 @@ class OrganisationRelationship < ApplicationRecord belongs_to :child_organisation, class_name: "Organisation" belongs_to :parent_organisation, class_name: "Organisation" - validates :parent_organisation_id, presence: { message: I18n.t("validations.organisation.housing_provider.blank") } + validates :parent_organisation_id, presence: { message: I18n.t("validations.organisation.stock_owner.blank") } validates :child_organisation_id, presence: { message: I18n.t("validations.organisation.managing_agent.blank") } - validates :parent_organisation_id, uniqueness: { scope: :child_organisation_id, message: I18n.t("validations.organisation.housing_provider.already_added") } + validates :parent_organisation_id, uniqueness: { scope: :child_organisation_id, message: I18n.t("validations.organisation.stock_owner.already_added") } validates :child_organisation_id, uniqueness: { scope: :parent_organisation_id, message: I18n.t("validations.organisation.managing_agent.already_added") } - validate :validate_housing_provider_owns_stock, on: :housing_provider + validate :validate_stock_owner_owns_stock, on: :stock_owner private - def validate_housing_provider_owns_stock + def validate_stock_owner_owns_stock if parent_organisation_id.present? && !parent_organisation.holds_own_stock - errors.add :parent_organisation_id, I18n.t("validations.organisation.housing_provider.does_not_own_stock") + errors.add :parent_organisation_id, I18n.t("validations.organisation.stock_owner.does_not_own_stock") end end end diff --git a/app/models/scheme.rb b/app/models/scheme.rb index 0f90b57f6..94d2b135b 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -103,7 +103,7 @@ class Scheme < ApplicationRecord ARRANGEMENT_TYPE = { "The same organisation that owns the housing stock": "D", - "Another registered housing provider": "R", + "Another registered stock owner": "R", "A registered charity or voluntary organisation": "V", "Another organisation": "O", "Missing": "X", diff --git a/app/views/organisation_relationships/_housing_provider_list.erb b/app/views/organisation_relationships/_stock_owner_list.erb similarity index 67% rename from app/views/organisation_relationships/_housing_provider_list.erb rename to app/views/organisation_relationships/_stock_owner_list.erb index 0aa2244f6..0120c553b 100644 --- a/app/views/organisation_relationships/_housing_provider_list.erb +++ b/app/views/organisation_relationships/_stock_owner_list.erb @@ -1,18 +1,18 @@
<%= govuk_table do |table| %> <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> - <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "housing providers", path: request.path)) %> + <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "stock owners", path: request.path)) %> <% end %> - <% @housing_providers.each do |housing_provider| %> + <% @stock_owners.each do |stock_owner| %> <%= table.body do |body| %> <%= body.row do |row| %> - <% row.cell(text: housing_provider.name) %> + <% row.cell(text: stock_owner.name) %> <% if current_user.data_coordinator? || current_user.support? %> <% row.cell(html_attributes: { scope: "row", class: "govuk-!-text-align-right", }) do %> - <%= govuk_link_to("Remove", housing_providers_remove_organisation_path(target_organisation_id: housing_provider.id)) %> + <%= govuk_link_to("Remove", stock_owners_remove_organisation_path(target_organisation_id: stock_owner.id)) %> <% end %> <% end %> <% end %> diff --git a/app/views/organisation_relationships/add_housing_provider.html.erb b/app/views/organisation_relationships/add_stock_owner.html.erb similarity index 70% rename from app/views/organisation_relationships/add_housing_provider.html.erb rename to app/views/organisation_relationships/add_stock_owner.html.erb index cb95fd6ac..e78e81b8a 100644 --- a/app/views/organisation_relationships/add_housing_provider.html.erb +++ b/app/views/organisation_relationships/add_stock_owner.html.erb @@ -1,17 +1,17 @@ -<%= form_with model: @organisation_relationship, url: housing_providers_organisation_path, method: "post", local: true do |f| %> +<%= form_with model: @organisation_relationship, url: stock_owners_organisation_path, method: "post", local: true do |f| %> <% if current_user.support? %> <%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> <%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %> -

Add Housing Provider

+

Add Stock Owner

<%= govuk_back_link(href: :back) %> - <%= render partial: "organisations/headings", locals: { main: "What is the name of this organisation's housing provider?", sub: nil } %> -

Start typing to search for a housing provider

+ <%= render partial: "organisations/headings", locals: { main: "What is the name of this organisation's stock owner?", sub: nil } %> +

Start typing to search for a stock owner

<% else %> <% content_for :before_content do %> <%= govuk_back_link(href: :back) %> <% end %> - <%= render partial: "organisations/headings", locals: { main: "What is the name of your housing provider?", sub: nil } %> -

Start typing to search for your housing provider

+ <%= render partial: "organisations/headings", locals: { main: "What is the name of your stock owner?", sub: nil } %> +

Start typing to search for your stock owner

<% end %> <% answer_options = { "" => "Select an option" } %> <% @organisations.each do |organisation| %> @@ -23,7 +23,7 @@ f:, } %> <%= f.govuk_submit "Add" %> - <%= govuk_details(summary_text: "Can't find the housing provider you're looking for?") do %> + <%= govuk_details(summary_text: "Can't find the stock owner you're looking for?") do %>