Skip to content

Commit

Permalink
Allow local admin to set determination period day for pre app
Browse files Browse the repository at this point in the history
  • Loading branch information
EGiataganas committed Dec 18, 2024
1 parent f133f46 commit d3e7d8d
Show file tree
Hide file tree
Showing 13 changed files with 245 additions and 1 deletion.
13 changes: 13 additions & 0 deletions app/models/application_type_overrides.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions app/models/local_authority.rb
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down
8 changes: 7 additions & 1 deletion app/models/planning_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions db/seeds/local_authorities.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
email_address: "[email protected]"
feedback_email: "[email protected]"
press_notice_email: "[email protected]"
application_type_overrides:
- code: "preApp"
determination_period_days: 30

- subdomain: "southwark"
council_code: "SWK"
Expand All @@ -22,6 +25,9 @@
email_address: "[email protected]"
feedback_email: "[email protected]"
press_notice_email: "[email protected]"
application_type_overrides:
- code: "preApp"
determination_period_days: 30

- subdomain: "buckinghamshire"
council_code: "BUC"
Expand All @@ -34,3 +40,6 @@
email_address: "[email protected]"
feedback_email: "[email protected]"
press_notice_email: "[email protected]"
application_type_overrides:
- code: "preApp"
determination_period_days: 30
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def active_page_key
case controller_name
when "dashboard"
"dashboard"
when "settings", "determination_periods"
"setting"
when "tokens"
"tokens"
when "users"
Expand All @@ -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")},
Expand Down
Original file line number Diff line number Diff line change
@@ -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") %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<%= 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 %>
</div>
</div>
18 changes: 18 additions & 0 deletions engines/bops_admin/app/views/bops_admin/settings/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<% content_for :page_title do %>
<%= t(".application_settings") %> - <%= t("page_title") %>
<% end %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<h1 class="govuk-heading-l"><%= t(".application_settings") %></h1>

<h2 class="govuk-heading-m"><%= t(".determination_period") %></h2>
<%= 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 %>
</div>
</div>
18 changes: 18 additions & 0 deletions engines/bops_admin/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions engines/bops_admin/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 76 additions & 0 deletions engines/bops_admin/spec/system/application_settings_spec.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions spec/factories/local_authorities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
feedback_email { "[email protected]" }
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" }
Expand Down

0 comments on commit d3e7d8d

Please sign in to comment.