diff --git a/app/models/user.rb b/app/models/user.rb index f9e34a652..4e762c9a1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -24,6 +24,7 @@ class User < ApplicationRecord after_validation :send_data_protection_confirmation_reminder, if: :is_dpo_changed? validates :organisation_id, presence: true + validate :organisation_not_merged has_paper_trail ignore: %w[last_sign_in_at current_sign_in_at @@ -185,6 +186,12 @@ protected private + def organisation_not_merged + if organisation&.merge_date.present? && organisation.merge_date < Time.zone.now + errors.add :organisation_id, I18n.t("validations.organisation.merged") + end + end + def send_data_protection_confirmation_reminder return unless persisted? return unless is_dpo? diff --git a/config/locales/en.yml b/config/locales/en.yml index e3507b9e5..09abf6729 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -198,6 +198,7 @@ en: managing_agent: blank: "You must choose a managing agent" already_added: "You have already added this managing agent" + merged: "Select an organisation that has not been merged" not_answered: "You must answer %{question}" invalid_option: "Enter a valid value for %{question}" invalid_number: "Enter a number for %{question}"