From d564b5fc4a001c46205a39f8270087d5a6a8e04a Mon Sep 17 00:00:00 2001 From: Carolyn Date: Thu, 13 Mar 2025 22:11:01 +0000 Subject: [PATCH] handle no open period to reactivate --- app/controllers/locations_controller.rb | 14 ++++++++++++-- app/controllers/schemes_controller.rb | 13 +++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index b80d969a0..fa2c88a3f 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -210,12 +210,22 @@ class LocationsController < ApplicationController end def new_reactivation - @location_deactivation_period = @location.location_deactivation_periods.deactivations_without_reactivation.first + open_deactivations = @location.location_deactivation_periods.deactivations_without_reactivation + if open_deactivations.blank? + render_not_found and return + end + + @location_deactivation_period = open_deactivations.first render "toggle_active", locals: { action: "reactivate" } end def reactivate - @location_deactivation_period = @location.location_deactivation_periods.deactivations_without_reactivation.first + open_deactivations = @location.location_deactivation_periods.deactivations_without_reactivation + if open_deactivations.blank? + render_not_found and return + end + + @location_deactivation_period = open_deactivations.first @location_deactivation_period.reactivation_date = toggle_date("reactivation_date") @location_deactivation_period.reactivation_date_type = params[:location_deactivation_period][:reactivation_date_type] diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 27504e9de..4b018ee34 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -88,13 +88,22 @@ class SchemesController < ApplicationController end def new_reactivation - @scheme_deactivation_period = @scheme.scheme_deactivation_periods.deactivations_without_reactivation.first + open_deactivations = @scheme.scheme_deactivation_periods&.deactivations_without_reactivation + if open_deactivations.blank? + render_not_found and return + end + + @scheme_deactivation_period = open_deactivations.first render "toggle_active", locals: { action: "reactivate" } end def reactivate - @scheme_deactivation_period = @scheme.scheme_deactivation_periods.deactivations_without_reactivation.first + open_deactivations = @scheme.scheme_deactivation_periods&.deactivations_without_reactivation + if open_deactivations.blank? + render_not_found and return + end + @scheme_deactivation_period = open_deactivations.first @scheme_deactivation_period.reactivation_date = toggle_date("reactivation_date") @scheme_deactivation_period.reactivation_date_type = params[:scheme_deactivation_period][:reactivation_date_type]