From c51a48aa548bd4534c8e4fa1ac4493878860dc87 Mon Sep 17 00:00:00 2001
From: Benjamin Eskola <ben.eskola@unboxedconsulting.com>
Date: Mon, 20 Jan 2025 17:12:21 +0000
Subject: [PATCH 1/3] Sort application type features

---
 app/models/application_type.rb         | 6 +++---
 app/models/application_type_feature.rb | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/app/models/application_type.rb b/app/models/application_type.rb
index af4f444837..3127d74acc 100644
--- a/app/models/application_type.rb
+++ b/app/models/application_type.rb
@@ -88,15 +88,15 @@ class ApplicationType < ApplicationRecord
     delegate :assess_against_policies?
     delegate :cil?
     delegate :considerations?
+    delegate :consultation_steps
+    delegate :consultations_skip_bank_holidays?
     delegate :eia?
     delegate :informatives?
     delegate :legislative_requirements?
     delegate :ownership_details?
-    delegate :planning_conditions?
     delegate :permitted_development_rights?
+    delegate :planning_conditions?
     delegate :site_visits?
-    delegate :consultations_skip_bank_holidays?
-    delegate :consultation_steps
   end
 
   with_options to: :legislation, prefix: true, allow_nil: true do
diff --git a/app/models/application_type_feature.rb b/app/models/application_type_feature.rb
index b2bc37b9df..f0b73b7ab3 100644
--- a/app/models/application_type_feature.rb
+++ b/app/models/application_type_feature.rb
@@ -7,15 +7,15 @@ class ApplicationTypeFeature
   attribute :assess_against_policies, :boolean, default: false
   attribute :cil, :boolean, default: true
   attribute :considerations, :boolean, default: false
+  attribute :consultation_steps, :list, default: -> { [] }
+  attribute :consultations_skip_bank_holidays, :boolean, default: false
   attribute :eia, :boolean, default: true
   attribute :informatives, :boolean, default: false
   attribute :legislative_requirements, :boolean, default: true
   attribute :ownership_details, :boolean, default: true
-  attribute :planning_conditions, :boolean, default: false
   attribute :permitted_development_rights, :boolean, default: true
+  attribute :planning_conditions, :boolean, default: false
   attribute :site_visits, :boolean, default: true
-  attribute :consultations_skip_bank_holidays, :boolean, default: false
-  attribute :consultation_steps, :list, default: -> { [] }
 
   validate :consultation_steps_are_valid
 

From e692b4370507389fbc6da7d1f6ba6350950419da Mon Sep 17 00:00:00 2001
From: Benjamin Eskola <ben.eskola@unboxedconsulting.com>
Date: Mon, 20 Jan 2025 17:37:02 +0000
Subject: [PATCH 2/3] Add application type feature for optional description
 change validation requests

---
 app/models/application_type.rb                                   | 1 +
 app/models/application_type_feature.rb                           | 1 +
 .../app/helpers/bops_config/application_type_helper.rb           | 1 +
 engines/bops_config/config/locales/application_type_features.yml | 1 +
 4 files changed, 4 insertions(+)

diff --git a/app/models/application_type.rb b/app/models/application_type.rb
index 3127d74acc..c03161b9ef 100644
--- a/app/models/application_type.rb
+++ b/app/models/application_type.rb
@@ -90,6 +90,7 @@ class ApplicationType < ApplicationRecord
     delegate :considerations?
     delegate :consultation_steps
     delegate :consultations_skip_bank_holidays?
+    delegate :description_change_requires_validation?
     delegate :eia?
     delegate :informatives?
     delegate :legislative_requirements?
diff --git a/app/models/application_type_feature.rb b/app/models/application_type_feature.rb
index f0b73b7ab3..ad4b977d6f 100644
--- a/app/models/application_type_feature.rb
+++ b/app/models/application_type_feature.rb
@@ -9,6 +9,7 @@ class ApplicationTypeFeature
   attribute :considerations, :boolean, default: false
   attribute :consultation_steps, :list, default: -> { [] }
   attribute :consultations_skip_bank_holidays, :boolean, default: false
+  attribute :description_change_requires_validation, :boolean, default: true
   attribute :eia, :boolean, default: true
   attribute :informatives, :boolean, default: false
   attribute :legislative_requirements, :boolean, default: true
diff --git a/engines/bops_config/app/helpers/bops_config/application_type_helper.rb b/engines/bops_config/app/helpers/bops_config/application_type_helper.rb
index 923ccb7961..8d173d9493 100644
--- a/engines/bops_config/app/helpers/bops_config/application_type_helper.rb
+++ b/engines/bops_config/app/helpers/bops_config/application_type_helper.rb
@@ -24,6 +24,7 @@ def application_details_features
         eia
         ownership_details
         site_visits
+        description_change_requires_validation
       ]
     end
   end
diff --git a/engines/bops_config/config/locales/application_type_features.yml b/engines/bops_config/config/locales/application_type_features.yml
index 0dea110909..d83c61eedb 100644
--- a/engines/bops_config/config/locales/application_type_features.yml
+++ b/engines/bops_config/config/locales/application_type_features.yml
@@ -6,6 +6,7 @@ en:
       cil: "Community Infrastructure Levy"
       considerations: "Assess policies and guidance (considerations)"
       consultations_skip_bank_holidays: "Extend consultation periods that contain bank holidays"
+      description_change_requires_validation: "Require applicants to approve changes to descriptions"
       eia: "Environmental Impact Assessment"
       informatives: "Add informatives"
       legislative_requirements: "Check legislative requirments"

From 1749ca01823b0f107247c25ad08d5fb21e492d16 Mon Sep 17 00:00:00 2001
From: Benjamin Eskola <ben.eskola@unboxedconsulting.com>
Date: Tue, 21 Jan 2025 11:36:24 +0000
Subject: [PATCH 3/3] Automatically close/accept DCVRs on application types
 that don't require approval

---
 .../description_change_validation_request.rb  |  8 ++-
 .../_new.html.erb                             |  9 ++--
 spec/factories/application_type.rb            |  1 +
 .../description_changes_validation_spec.rb    | 53 +++++++++++++++++++
 4 files changed, 67 insertions(+), 4 deletions(-)

diff --git a/app/models/description_change_validation_request.rb b/app/models/description_change_validation_request.rb
index 47535da441..f5bb3a48a9 100644
--- a/app/models/description_change_validation_request.rb
+++ b/app/models/description_change_validation_request.rb
@@ -9,6 +9,7 @@ class DescriptionChangeValidationRequest < ValidationRequest
   validate :rejected_reason_is_present?
 
   before_create :set_previous_application_description
+  after_save :preapplication_auto_close, if: -> { open? && !planning_application.application_type.description_change_requires_validation? }
 
   def response_due
     RESPONSE_TIME_IN_DAYS.business_days.after(created_at).to_date
@@ -25,7 +26,7 @@ def create_audit!
   end
 
   def email_and_timestamp
-    send_description_request_email
+    send_description_request_email if planning_application.application_type.description_change_requires_validation?
 
     mark_as_sent!
   end
@@ -75,4 +76,9 @@ def audit_api_comment
   def update_planning_application_for_auto_closed_request!
     planning_application.update!(description: proposed_description)
   end
+
+  def preapplication_auto_close
+    auto_close_request!
+    planning_application.update!(valid_description: true)
+  end
 end
diff --git a/app/views/planning_applications/validation/description_change_validation_requests/_new.html.erb b/app/views/planning_applications/validation/description_change_validation_requests/_new.html.erb
index c46d4d8339..3162c71d5d 100644
--- a/app/views/planning_applications/validation/description_change_validation_requests/_new.html.erb
+++ b/app/views/planning_applications/validation/description_change_validation_requests/_new.html.erb
@@ -19,9 +19,12 @@
     <h2 class="govuk-heading-m govuk-!-margin-top-3">
       Suggest a new description to the applicant
     </h2>
-    <p class="govuk-body">
-      This will be sent to the applicant immediately. If the applicant does not respond within 5 days, the amended description will be automatically accepted.
-    </p>
+
+    <% if @planning_application.application_type.description_change_requires_validation? %>
+      <p class="govuk-body">
+        This will be sent to the applicant immediately. If the applicant does not respond within 5 days, the amended description will be automatically accepted.
+      </p>
+    <% end %>
 
     <div class="govuk-inset-text">
       <h3 class="govuk-heading-s">
diff --git a/spec/factories/application_type.rb b/spec/factories/application_type.rb
index 9763b62a91..20aeb8e547 100644
--- a/spec/factories/application_type.rb
+++ b/spec/factories/application_type.rb
@@ -562,6 +562,7 @@
       features {
         {
           "cil" => false,
+          "description_change_requires_validation" => false,
           "eia" => false,
           "legislative_requirements" => false
         }
diff --git a/spec/system/planning_applications/validating/description_changes_validation_spec.rb b/spec/system/planning_applications/validating/description_changes_validation_spec.rb
index f9eb26939a..4e97d97c66 100644
--- a/spec/system/planning_applications/validating/description_changes_validation_spec.rb
+++ b/spec/system/planning_applications/validating/description_changes_validation_spec.rb
@@ -187,4 +187,57 @@
       end
     end
   end
+
+  context "when the application is a pre-application" do
+    let(:planning_application) do
+      create(
+        :planning_application, :not_started, :pre_application, local_authority: default_local_authority
+      )
+    end
+
+    it "I can request a change and it will be automatically accepted immediately" do
+      visit "/planning_applications/#{planning_application.reference}/validation/tasks"
+      click_link "Check description"
+
+      within(".govuk-fieldset") do
+        within(".govuk-radios") { choose "No" }
+      end
+
+      click_button "Save and mark as complete"
+
+      expect(page).to have_current_path(
+        "/planning_applications/#{planning_application.reference}/validation/validation_requests/new?type=description_change"
+      )
+      expect(page).to have_content("Description change")
+      expect(page).to have_content("Application number: #{planning_application.reference}")
+
+      fill_in(
+        "Enter an amended description to send to the applicant",
+        with: "My better description"
+      )
+
+      click_button "Send request"
+
+      expect(page).to have_content("Description change request successfully sent.")
+
+      within("#check-description-task") do
+        expect(page).to have_content("Completed")
+      end
+
+      expect(planning_application.reload.valid_description).to be true
+      expect(DescriptionChangeValidationRequest.all.length).to eq(1)
+      expect(DescriptionChangeValidationRequest.closed.length).to eq(1)
+
+      click_link "Check description"
+
+      expect(page).to have_current_path(
+        "/planning_applications/#{planning_application.reference}/validation/description_changes"
+      )
+
+      expect(page).to have_content("My better description")
+
+      click_link "Back"
+      expect(page).to have_current_path("/planning_applications/#{planning_application.reference}/validation/tasks")
+    end
+  end
 end