diff --git a/app/models/application_type_overrides.rb b/app/models/application_type_overrides.rb new file mode 100644 index 0000000000..2a1f359901 --- /dev/null +++ b/app/models/application_type_overrides.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class ApplicationTypeOverrides + include StoreModel::Model + + attribute :code, :string + attribute :determination_period_days, :integer + + validates :determination_period_days, presence: true + validates :determination_period_days, numericality: {only_integer: true} + validates :determination_period_days, numericality: {greater_than_or_equal_to: 1} + validates :determination_period_days, numericality: {less_than_or_equal_to: 99} +end diff --git a/app/models/local_authority.rb b/app/models/local_authority.rb index b89136630e..4c9a1e5766 100644 --- a/app/models/local_authority.rb +++ b/app/models/local_authority.rb @@ -1,6 +1,14 @@ # frozen_string_literal: true class LocalAuthority < ApplicationRecord + include StoreModel::NestedAttributes + + attribute :application_type_overrides, ApplicationTypeOverrides.to_array_type + + validates :application_type_overrides, store_model: {merge_errors: true} + + accepts_nested_attributes_for :application_type_overrides + with_options dependent: :destroy do has_many :users has_many :planning_applications, -> { kept } diff --git a/app/models/planning_application.rb b/app/models/planning_application.rb index 150d8026e7..d6b55d1e28 100644 --- a/app/models/planning_application.rb +++ b/app/models/planning_application.rb @@ -1029,7 +1029,13 @@ def set_key_dates end def application_type_determination_period - application_type.determination_period_days || DAYS_TO_EXPIRE + determination_period_days_for_pre_app || + application_type.determination_period_days || + DAYS_TO_EXPIRE + end + + def determination_period_days_for_pre_app + local_authority.application_type_overrides.find { |ato| ato.code == "preApp" }&.determination_period_days if pre_application? end def set_change_access_id diff --git a/db/seeds/local_authorities.yml b/db/seeds/local_authorities.yml index 644e75346b..9cacfc05f4 100644 --- a/db/seeds/local_authorities.yml +++ b/db/seeds/local_authorities.yml @@ -10,6 +10,9 @@ email_address: "planning@lambeth.gov.uk" feedback_email: "digitalplanning@lambeth.gov.uk" press_notice_email: "digitalplanning@lambeth.gov.uk" + application_type_overrides: + - code: "preApp" + determination_period_days: 30 - subdomain: "southwark" council_code: "SWK" @@ -22,6 +25,9 @@ email_address: "planning@southwark.gov.uk" feedback_email: "digital.projects@southwark.gov.uk" press_notice_email: "digital.projects@southwark.gov.uk" + application_type_overrides: + - code: "preApp" + determination_period_days: 30 - subdomain: "buckinghamshire" council_code: "BUC" @@ -34,3 +40,6 @@ email_address: "planning@buckinghamshire.gov.uk" feedback_email: "planning.digital@buckinghamshire.gov.uk" press_notice_email: "planning.digital@buckinghamshire.gov.uk" + application_type_overrides: + - code: "preApp" + determination_period_days: 30 diff --git a/engines/bops_admin/app/controllers/bops_admin/determination_periods_controller.rb b/engines/bops_admin/app/controllers/bops_admin/determination_periods_controller.rb new file mode 100644 index 0000000000..91b9eba840 --- /dev/null +++ b/engines/bops_admin/app/controllers/bops_admin/determination_periods_controller.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module BopsAdmin + class DeterminationPeriodsController < ApplicationController + def edit + respond_to do |format| + format.html + end + end + + def update + respond_to do |format| + if current_local_authority.update(application_type_overrides_params, :application_type_overrides) + format.html do + redirect_to setting_path, notice: t(".success") + end + else + format.html { render :edit } + end + end + end + + private + + def application_type_overrides_params + params.require(:local_authority).permit(application_type_overrides_attributes:) + end + + def application_type_overrides_attributes + [ + :determination_period_days, + code: :preApp + ] + end + end +end diff --git a/engines/bops_admin/app/controllers/bops_admin/settings_controller.rb b/engines/bops_admin/app/controllers/bops_admin/settings_controller.rb new file mode 100644 index 0000000000..6732f8560d --- /dev/null +++ b/engines/bops_admin/app/controllers/bops_admin/settings_controller.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module BopsAdmin + class SettingsController < ApplicationController + before_action :set_application_type_overrides + + def show + respond_to do |format| + format.html + end + end + + private + + def set_application_type_overrides + @application_type_overrides = current_local_authority.application_type_overrides + end + end +end diff --git a/engines/bops_admin/app/helpers/bops_admin/application_helper.rb b/engines/bops_admin/app/helpers/bops_admin/application_helper.rb index da0d51c77a..6f3654d6d0 100644 --- a/engines/bops_admin/app/helpers/bops_admin/application_helper.rb +++ b/engines/bops_admin/app/helpers/bops_admin/application_helper.rb @@ -23,6 +23,8 @@ def active_page_key case controller_name when "dashboard" "dashboard" + when "settings", "determination_periods" + "setting" when "tokens" "tokens" when "users" @@ -43,6 +45,7 @@ def active_page_key def nav_items [ {link: {text: "Dashboard", href: root_path}, current: active_page_key?("dashboard")}, + {link: {text: "Application settings", href: setting_path}, current: active_page_key?("setting")}, {link: {text: "Consultees", href: consultees_path}, current: active_page_key?("consultees")}, {link: {text: "Informatives", href: informatives_path}, current: active_page_key?("informatives")}, {link: {text: "Policy", href: policy_root_path}, current: active_page_key?("policy")}, diff --git a/engines/bops_admin/app/views/bops_admin/determination_periods/edit.html.erb b/engines/bops_admin/app/views/bops_admin/determination_periods/edit.html.erb new file mode 100644 index 0000000000..710fc456bc --- /dev/null +++ b/engines/bops_admin/app/views/bops_admin/determination_periods/edit.html.erb @@ -0,0 +1,26 @@ +<% content_for :page_title do %> + <%= t(".determination_period") %> - <%= t("page_title") %> +<% end %> + +<% add_parent_breadcrumb_link "Home", root_path %> + +<% content_for :title, t(".determination_period") %> + +
+
+ <%= form_with model: current_local_authority, url: [:setting, :determination_period] do |form| %> + <%= form.govuk_error_summary %> + + <%= form.fields_for :application_type_overrides do |ff| %> + <%= ff.govuk_text_field :determination_period_days, width: 5, + label: {text: t(".set_determination_period"), size: "l"}, + hint: {text: t(".hint")}, + suffix_text: t(".days"), + value: current_local_authority&.application_type_overrides&.map(&:determination_period_days) %> + <% end %> + + <%= form.govuk_submit(t(".save")) %> + <%= govuk_button_link_to t("back"), setting_path, secondary: true %> + <% end %> +
+
diff --git a/engines/bops_admin/app/views/bops_admin/settings/show.html.erb b/engines/bops_admin/app/views/bops_admin/settings/show.html.erb new file mode 100644 index 0000000000..2a05e5eefe --- /dev/null +++ b/engines/bops_admin/app/views/bops_admin/settings/show.html.erb @@ -0,0 +1,18 @@ +<% content_for :page_title do %> + <%= t(".application_settings") %> - <%= t("page_title") %> +<% end %> + +
+
+

<%= t(".application_settings") %>

+ +

<%= t(".determination_period") %>

+ <%= govuk_summary_list do |summary_list| + summary_list.with_row do |row| + row.with_key { t(".pre_app_determination_period") } + row.with_value { t(".determination_period_including_bank_holidays", count: @application_type_overrides.map(&:determination_period_days).join(" ")) if @application_type_overrides.map(&:determination_period_days).join(" ") } + row.with_action(text: t(".change"), href: url_for([:edit, :setting, :determination_period]), visually_hidden_text: t(".determination_period")) + end + end %> +
+
diff --git a/engines/bops_admin/config/locales/en.yml b/engines/bops_admin/config/locales/en.yml index 227b2d834f..5f08f847a0 100644 --- a/engines/bops_admin/config/locales/en.yml +++ b/engines/bops_admin/config/locales/en.yml @@ -49,6 +49,15 @@ en: show: administrator_dashboard: Administrator dashboard welcome_message: Welcome %{name} + determination_periods: + edit: + days: days + determination_period: Determination period + hint: Choose the length of the determination period for the pre-application type. + save: Save + set_determination_period: Set determination period + update: + success: Determination period successfully updated informatives: create: informative_successfully_created: Informative successfully created @@ -258,6 +267,15 @@ en: telephone_number_hint: This is the number that applicants or neighbours can call if they need information in alternative formats. update: profile_successfully_updated: Council information successfully updated + settings: + show: + application_settings: Application settings + change: Change + determination_period: Determination period + determination_period_including_bank_holidays: + one: 1 day - bank holidays included + other: "%{count} days - bank holidays included" + pre_app_determination_period: Pre-application determination period tokens: create: success: API token successfully created diff --git a/engines/bops_admin/config/routes.rb b/engines/bops_admin/config/routes.rb index 6d15d41f26..6b4b591cee 100644 --- a/engines/bops_admin/config/routes.rb +++ b/engines/bops_admin/config/routes.rb @@ -8,6 +8,10 @@ resources :consultees, except: %i[show] + resource :setting, only: %i[show] do + resource :determination_period, only: %i[edit update] + end + resources :informatives, except: %i[show] scope "/policy" do diff --git a/engines/bops_admin/spec/system/application_settings_spec.rb b/engines/bops_admin/spec/system/application_settings_spec.rb new file mode 100644 index 0000000000..4671b2f29d --- /dev/null +++ b/engines/bops_admin/spec/system/application_settings_spec.rb @@ -0,0 +1,76 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe "Profile", type: :system do + let(:local_authority) { create(:local_authority, :default, :with_api_user) } + let(:user) { create(:user, :administrator, local_authority:) } + + before do + sign_in(user) + end + + it "shows the council as active on the dashboard" do + visit "/admin/dashboard" + expect(page).to have_content("Active") + end + + it "allows the administrator to view the determination period days" do + visit "/admin/setting" + expect(page).to have_selector("h1", text: "Application settings") + expect(page).to have_selector("h2", text: "Determination period") + + within "dl div:nth-child(1)" do + expect(page).to have_selector("dt", text: "Pre-application determination period") + expect(page).to have_selector("dd", text: "30 days - bank holidays included") + expect(page).to have_selector("dd > a", text: "Change") + + expect(page).to have_link( + "Change", + href: "/admin/setting/determination_period/edit" + ) + end + end + + it "allows the administrator to edit determination" do + visit "/admin/setting" + + within "dl div:nth-child(1)" do + expect(page).to have_selector("dt", text: "Pre-application determination period") + expect(page).to have_selector("dd", text: "30 days - bank holidays included") + click_link "Change" + end + + # Set determination period + expect(page).to have_selector(".govuk-label", text: "Set determination period") + expect(page).to have_selector("div.govuk-hint", text: "Choose the length of the determination period for the pre-application type.") + + fill_in "Set determination period", with: "" + click_button "Save" + + expect(page).to have_content("can't be blank") + + fill_in "Set determination period", with: "not an integer" + click_button "Save" + + expect(page).to have_content("is not a number") + + fill_in "Set determination period", with: "1.1" + click_button "Save" + + expect(page).to have_content("must be an integer") + + fill_in "Set determination period", with: "0" + click_button "Save" + expect(page).to have_content("must be greater than or equal to 1") + + fill_in "Set determination period", with: "100" + click_button "Save" + expect(page).to have_content("must be less than or equal to 99") + + fill_in "Set determination period", with: "25" + click_button "Save" + + expect(page).to have_content("Determination period successfully updated") + end +end diff --git a/spec/factories/local_authorities.rb b/spec/factories/local_authorities.rb index bf47567da9..56b3329404 100644 --- a/spec/factories/local_authorities.rb +++ b/spec/factories/local_authorities.rb @@ -14,6 +14,14 @@ feedback_email { "feedback_email@buckinghamshire.gov.uk" } email_reply_to_id { "4896bb50-4f4c-4b4d-ad67-2caddddde125" } active { true } + application_type_overrides do + [ + { + code: :preApp, + determination_period_days: 30 + } + ] + end trait :default do council_code { "PlanX" }