From 0a00d801bcea8d156a3df4962c942e1666fcec03 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Thu, 14 Mar 2024 18:14:57 +0100 Subject: [PATCH] fix(data): update procedures with invalid mon avis --- .../disable_remaining_invalid_mon_avis_task.rb | 15 +++++++++++++++ app/validators/mon_avis_embed_validator.rb | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 app/tasks/maintenance/disable_remaining_invalid_mon_avis_task.rb diff --git a/app/tasks/maintenance/disable_remaining_invalid_mon_avis_task.rb b/app/tasks/maintenance/disable_remaining_invalid_mon_avis_task.rb new file mode 100644 index 000000000..71a78696d --- /dev/null +++ b/app/tasks/maintenance/disable_remaining_invalid_mon_avis_task.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Maintenance + class DisableRemainingInvalidMonAvisTask < MaintenanceTasks::Task + def collection + # rubocop:disable DS/Unscoped + Procedure.unscoped.where.not(monavis_embed: nil) + # rubocop:enable DS/Unscoped + end + + def process(procedure) + procedure.update_column(:monavis_embed, '') if !procedure.valid? && procedure.errors.key?(:monavis_embed) + end + end +end diff --git a/app/validators/mon_avis_embed_validator.rb b/app/validators/mon_avis_embed_validator.rb index 3fb87b456..276552163 100644 --- a/app/validators/mon_avis_embed_validator.rb +++ b/app/validators/mon_avis_embed_validator.rb @@ -13,9 +13,9 @@ class MonAvisEmbedValidator < ActiveModel::Validator check_img(embed.css('img')) end rescue MonAvisEmbedError => e - record.errors.add :base, :invalid, message: "Le code fourni ne correspond pas au format des codes MonAvis reconnus par la plateforme. #{e.message}" + record.errors.add :monavis_embed, :invalid, message: "Le code fourni ne correspond pas au format des codes MonAvis reconnus par la plateforme. #{e.message}" rescue # nokogiri - record.errors.add :base, :invalid, message: "Le code fourni ne correspond pas au format des codes MonAvis reconnus par la plateforme." + record.errors.add :monavis_embed, :invalid, message: "Le code fourni ne correspond pas au format des codes MonAvis reconnus par la plateforme." end def check_link(links)