Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
2.9 KiB

Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
class SchemeDeactivationPeriodValidator < ActiveModel::Validator
include CollectionTimeHelper
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
def validate(record)
scheme = record.scheme
recent_deactivation = scheme.scheme_deactivation_periods.deactivations_without_reactivation.first
if recent_deactivation.present?
validate_reactivation(record, recent_deactivation, scheme)
else
validate_deactivation(record, scheme)
end
end
def validate_reactivation(record, recent_deactivation, scheme)
if record.reactivation_date.blank?
if record.reactivation_date_type.blank?
record.errors.add(:reactivation_date_type, message: I18n.t("validations.scheme.toggle_date.not_selected"))
elsif record.reactivation_date_type == "other"
record.errors.add(:reactivation_date, message: I18n.t("validations.scheme.toggle_date.invalid"))
end
elsif !record.reactivation_date.between?(scheme.available_from, Time.zone.local(2200, 1, 1))
record.errors.add(:reactivation_date, message: I18n.t("validations.scheme.toggle_date.out_of_range", date: scheme.available_from.to_formatted_s(:govuk_date)))
elsif record.reactivation_date < recent_deactivation.deactivation_date
record.errors.add(:reactivation_date, message: I18n.t("validations.scheme.reactivation.before_deactivation", date: recent_deactivation.deactivation_date.to_formatted_s(:govuk_date)))
end
end
def validate_deactivation(record, scheme)
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
if record.deactivation_date.blank?
if record.deactivation_date_type.blank?
record.errors.add(:deactivation_date_type, message: I18n.t("validations.scheme.toggle_date.not_selected"))
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
elsif record.deactivation_date_type == "other"
record.errors.add(:deactivation_date, message: I18n.t("validations.scheme.toggle_date.invalid"))
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
end
elsif scheme.scheme_deactivation_periods.any? { |period| period.reactivation_date.present? && record.deactivation_date.between?(period.deactivation_date, period.reactivation_date - 1.day) }
record.errors.add(:deactivation_date, message: I18n.t("validations.scheme.deactivation.during_deactivated_period"))
elsif record.deactivation_date.before? FormHandler.instance.start_date_of_earliest_open_collection_period
record.errors.add(:deactivation_date, message: I18n.t("validations.scheme.toggle_date.out_of_range", date: FormHandler.instance.start_date_of_earliest_open_collection_period.to_formatted_s(:govuk_date)))
elsif record.deactivation_date.before? scheme.available_from
record.errors.add(:deactivation_date, message: I18n.t("validations.scheme.toggle_date.before_creation", date: scheme.available_from.to_formatted_s(:govuk_date)))
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
end
end
end
class SchemeDeactivationPeriod < ApplicationRecord
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
validates_with SchemeDeactivationPeriodValidator
belongs_to :scheme
attr_accessor :deactivation_date_type, :reactivation_date_type
scope :deactivations_without_reactivation, -> { where(reactivation_date: nil) }
end