diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb
index 58fffd2e0..29cca7d9e 100644
--- a/app/helpers/locations_helper.rb
+++ b/app/helpers/locations_helper.rb
@@ -69,7 +69,7 @@ module LocationsHelper
end
def toggle_location_link(location)
- return govuk_button_link_to "Deactivate this location", scheme_location_new_deactivation_path(location.scheme, location), warning: true if location.active?
+ return govuk_button_link_to "Deactivate this location", scheme_location_new_deactivation_path(location.scheme, location), warning: true if location.active? || location.deactivates_in_more_than_6_months?
return govuk_button_link_to "Reactivate this location", scheme_location_new_reactivation_path(location.scheme, location) if location.deactivated?
end
diff --git a/app/helpers/schemes_helper.rb b/app/helpers/schemes_helper.rb
index 50bd4efb2..f28a18211 100644
--- a/app/helpers/schemes_helper.rb
+++ b/app/helpers/schemes_helper.rb
@@ -40,7 +40,7 @@ module SchemesHelper
end
def toggle_scheme_link(scheme)
- return govuk_button_link_to "Deactivate this scheme", scheme_new_deactivation_path(scheme), warning: true if scheme.active?
+ return govuk_button_link_to "Deactivate this scheme", scheme_new_deactivation_path(scheme), warning: true if scheme.active? || scheme.deactivates_in_more_than_6_months?
return govuk_button_link_to "Reactivate this scheme", scheme_new_reactivation_path(scheme) if scheme.deactivated?
end
diff --git a/app/helpers/tag_helper.rb b/app/helpers/tag_helper.rb
index f8b19dd83..6fc6927e5 100644
--- a/app/helpers/tag_helper.rb
+++ b/app/helpers/tag_helper.rb
@@ -27,11 +27,13 @@ module TagHelper
deactivated: "grey",
}.freeze
- def status_tag(status, classes = [])
+ def status_tag(resource, classes = [])
+ display_status = resource.status
+ display_status = :active if resource.deactivates_in_more_than_6_months?
govuk_tag(
classes:,
- colour: COLOUR[status.to_sym],
- text: TEXT[status.to_sym],
+ colour: COLOUR[display_status.to_sym],
+ text: TEXT[display_status.to_sym],
)
end
end
diff --git a/app/models/location.rb b/app/models/location.rb
index 57393d9fb..dab4a2cf5 100644
--- a/app/models/location.rb
+++ b/app/models/location.rb
@@ -108,6 +108,10 @@ class Location < ApplicationRecord
status == :reactivating_soon
end
+ def deactivates_in_more_than_6_months?
+ status == :deactivating_soon && open_deactivation.present? && open_deactivation.deactivation_date > 6.months.from_now
+ end
+
def validate_postcode
if !postcode&.match(POSTCODE_REGEXP)
error_message = I18n.t("validations.postcode")
diff --git a/app/models/scheme.rb b/app/models/scheme.rb
index 75b37dec6..c43d06a17 100644
--- a/app/models/scheme.rb
+++ b/app/models/scheme.rb
@@ -242,4 +242,8 @@ class Scheme < ApplicationRecord
def deactivated?
status == :deactivated
end
+
+ def deactivates_in_more_than_6_months?
+ status == :deactivating_soon && open_deactivation.present? && open_deactivation.deactivation_date > 6.months.from_now
+ end
end
diff --git a/app/views/locations/index.html.erb b/app/views/locations/index.html.erb
index e974d7dfb..5d0f429b2 100644
--- a/app/views/locations/index.html.erb
+++ b/app/views/locations/index.html.erb
@@ -54,7 +54,7 @@
end), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: location.name) %>
<% row.cell(text: location.id) %>
- <% row.cell(text: status_tag(location.status)) %>
+ <% row.cell(text: status_tag(location)) %>
<% end %>
<% end %>
<% end %>
diff --git a/app/views/locations/show.html.erb b/app/views/locations/show.html.erb
index dd819b2fb..a865364e6 100644
--- a/app/views/locations/show.html.erb
+++ b/app/views/locations/show.html.erb
@@ -15,7 +15,7 @@
<% display_location_attributes(@location).each do |attr| %>
<%= summary_list.row do |row| %>
<% row.key { attr[:name] } %>
- <% row.value { attr[:attribute].eql?("status") ? status_tag(attr[:value]) : details_html(attr) } %>
+ <% row.value { attr[:attribute].eql?("status") ? status_tag(@location) : details_html(attr) } %>
<% if LocationPolicy.new(current_user, @location).update? %>
<% row.action(text: "Change", href: scheme_location_name_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "name" %>
<% end %>
diff --git a/app/views/schemes/_scheme_list.html.erb b/app/views/schemes/_scheme_list.html.erb
index 4f3b06454..a3fb82013 100644
--- a/app/views/schemes/_scheme_list.html.erb
+++ b/app/views/schemes/_scheme_list.html.erb
@@ -17,7 +17,7 @@
<% row.cell(text: simple_format(scheme_cell(scheme), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: scheme.id_to_display) %>
<% row.cell(text: scheme.locations&.count) %>
- <% row.cell(text: status_tag(scheme.status)) %>
+ <% row.cell(text: status_tag(scheme)) %>
<% end %>
<% end %>
<% end %>
diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb
index 88d73901c..f63dd3cfb 100644
--- a/spec/requests/locations_controller_spec.rb
+++ b/spec/requests/locations_controller_spec.rb
@@ -1673,6 +1673,19 @@ RSpec.describe LocationsController, type: :request do
expect(response).to have_http_status(:ok)
expect(page).not_to have_link("Reactivate this location")
expect(page).not_to have_link("Deactivate this location")
+ expect(page).to have_content("Deactivating soon")
+ end
+ end
+
+ context "with location that's deactivating in more than 6 months" do
+ let(:location_deactivation_period) { create(:location_deactivation_period, deactivation_date: Time.zone.local(2023, 6, 12), location:) }
+
+ it "does render toggle location link" do
+ expect(response).to have_http_status(:ok)
+ expect(page).not_to have_link("Reactivate this location")
+ expect(page).to have_link("Deactivate this location")
+ expect(response.body).not_to include("Deactivating soon")
+ expect(response.body).to include("Active")
end
end
diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb
index 4c7bad55a..fdd6d64e4 100644
--- a/spec/requests/schemes_controller_spec.rb
+++ b/spec/requests/schemes_controller_spec.rb
@@ -330,6 +330,18 @@ RSpec.describe SchemesController, type: :request do
expect(page).not_to have_link("Deactivate this scheme")
end
end
+
+ context "with scheme that's deactivating in more than 6 months" do
+ let(:scheme_deactivation_period) { create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2023, 5, 12), scheme:) }
+
+ it "does not render toggle scheme link" do
+ expect(response).to have_http_status(:ok)
+ expect(page).not_to have_link("Reactivate this scheme")
+ expect(page).to have_link("Deactivate this scheme")
+ expect(response.body).not_to include("Deactivating soon")
+ expect(response.body).to include("Active")
+ end
+ end
end
context "when coordinator attempts to see scheme belonging to a parent organisation" do