diff --git a/app/dashboards/procedure_dashboard.rb b/app/dashboards/procedure_dashboard.rb index bba85da5b..8f60beb3b 100644 --- a/app/dashboards/procedure_dashboard.rb +++ b/app/dashboards/procedure_dashboard.rb @@ -36,7 +36,9 @@ class ProcedureDashboard < Administrate::BaseDashboard refused_mail_template: MailTemplateField, without_continuation_mail_template: MailTemplateField, attestation_template: AttestationTemplateField, - procedure_expires_when_termine_enabled: Field::Boolean + procedure_expires_when_termine_enabled: Field::Boolean, + duree_conservation_dossiers_dans_ds: Field::Number, + duree_conservation_etendue_par_ds: Field::Boolean }.freeze # COLLECTION_ATTRIBUTES @@ -84,14 +86,18 @@ class ProcedureDashboard < Administrate::BaseDashboard :refused_mail_template, :without_continuation_mail_template, :attestation_template, - :procedure_expires_when_termine_enabled + :procedure_expires_when_termine_enabled, + :duree_conservation_dossiers_dans_ds, + :duree_conservation_etendue_par_ds ].freeze # FORM_ATTRIBUTES # an array of attributes that will be displayed # on the model's form (`new` and `edit`) pages. FORM_ATTRIBUTES = [ - :procedure_expires_when_termine_enabled + :procedure_expires_when_termine_enabled, + :duree_conservation_dossiers_dans_ds, + :duree_conservation_etendue_par_ds ].freeze # Overwrite this method to customize how procedures are displayed diff --git a/app/models/procedure.rb b/app/models/procedure.rb index e4aefcadd..b729c8c1a 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -18,6 +18,7 @@ # description :string # direction :string # duree_conservation_dossiers_dans_ds :integer +# duree_conservation_etendue_par_ds :boolean default(FALSE) # durees_conservation_required :boolean default(TRUE) # encrypted_api_particulier_token :string # euro_flag :boolean default(FALSE) @@ -63,8 +64,8 @@ class Procedure < ApplicationRecord self.discard_column = :hidden_at default_scope -> { kept } - MAX_DUREE_CONSERVATION = 36 - MAX_DUREE_CONSERVATION_EXPORT = 3.hours + OLD_MAX_DUREE_CONSERVATION = 36 + NEW_MAX_DUREE_CONSERVATION = 12 MIN_WEIGHT = 350000 @@ -270,7 +271,22 @@ class Procedure < ApplicationRecord if: :validate_for_publication? validate :check_juridique validates :path, presence: true, format: { with: /\A[a-z0-9_\-]{3,200}\z/ }, uniqueness: { scope: [:path, :closed_at, :hidden_at, :unpublished_at], case_sensitive: false } - validates :duree_conservation_dossiers_dans_ds, allow_nil: false, numericality: { only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: MAX_DUREE_CONSERVATION } + validates :duree_conservation_dossiers_dans_ds, allow_nil: false, + numericality: { + only_integer: true, + greater_than_or_equal_to: 1, + less_than_or_equal_to: OLD_MAX_DUREE_CONSERVATION + }, + if: :duree_conservation_etendue_par_ds + + validates :duree_conservation_dossiers_dans_ds, allow_nil: false, + numericality: { + only_integer: true, + greater_than_or_equal_to: 1, + less_than_or_equal_to: NEW_MAX_DUREE_CONSERVATION + }, + unless: :duree_conservation_etendue_par_ds + validates :lien_dpo, email_or_link: true, allow_nil: true validates_with MonAvisEmbedValidator diff --git a/app/views/administrateurs/procedures/_informations.html.haml b/app/views/administrateurs/procedures/_informations.html.haml index d3cbd0d8d..aa107152a 100644 --- a/app/views/administrateurs/procedures/_informations.html.haml +++ b/app/views/administrateurs/procedures/_informations.html.haml @@ -27,8 +27,8 @@ Sur #{APPLICATION_NAME} %span.mandatory * -%p.notice (durée en mois après le début de l’instruction) -= f.number_field :duree_conservation_dossiers_dans_ds, class: 'form-control', placeholder: '6', required: true +%p.notice Durée en mois après le début de l’instruction. Pour les démarches classiques, cette durée ne peut exceder 12 mois. Si vous avez besoin d'une durée supérieur à 12 mois, merci d'en faire la demande à notre support += f.number_field :duree_conservation_dossiers_dans_ds, {class: 'form-control', placeholder: '6', required: true}.merge(f.object.duree_conservation_etendue_par_ds ? {} : {max: 12}) - if @procedure.created_at.present? = f.label :lien_site_web do diff --git a/config/locales/models/procedure/fr.yml b/config/locales/models/procedure/fr.yml index 1c3f1b9e1..e0385936d 100644 --- a/config/locales/models/procedure/fr.yml +++ b/config/locales/models/procedure/fr.yml @@ -9,7 +9,6 @@ fr: path: Lien public organisation: Organisme duree_conservation_dossiers_dans_ds: Durée de conservation des dossiers sur demarches-simplifiees.fr - duree_conservation_dossiers_hors_ds: Durée de conservation des dossiers hors demarches-simplifiees.fr aasm_state/brouillon: Brouillon aasm_state/publiee: Publiée aasm_state/close: Close diff --git a/db/migrate/20220708151654_drop_duree_conservation_dossiers_hors_ds.rb b/db/migrate/20220708151654_drop_duree_conservation_dossiers_hors_ds.rb new file mode 100644 index 000000000..80dca3d7c --- /dev/null +++ b/db/migrate/20220708151654_drop_duree_conservation_dossiers_hors_ds.rb @@ -0,0 +1,5 @@ +class DropDureeConservationDossiersHorsDs < ActiveRecord::Migration[6.1] + def change + safety_assured { remove_column :procedures, :duree_conservation_dossiers_hors_ds } + end +end diff --git a/db/migrate/20220708151802_add_column_duree_conservation_entendue_par_ds.rb b/db/migrate/20220708151802_add_column_duree_conservation_entendue_par_ds.rb new file mode 100644 index 000000000..b84292ed8 --- /dev/null +++ b/db/migrate/20220708151802_add_column_duree_conservation_entendue_par_ds.rb @@ -0,0 +1,5 @@ +class AddColumnDureeConservationEntendueParDs < ActiveRecord::Migration[6.1] + def change + add_column :procedures, :duree_conservation_etendue_par_ds, :boolean + end +end diff --git a/db/migrate/20220708151917_backfill_duree_conservation_entendue_par_ds.rb b/db/migrate/20220708151917_backfill_duree_conservation_entendue_par_ds.rb new file mode 100644 index 000000000..eb77de0af --- /dev/null +++ b/db/migrate/20220708151917_backfill_duree_conservation_entendue_par_ds.rb @@ -0,0 +1,8 @@ +class BackfillDureeConservationEntendueParDs < ActiveRecord::Migration[6.1] + def change + Procedure.in_batches do |relation| + relation.update_all duree_conservation_etendue_par_ds: true + sleep(0.01) + end + end +end diff --git a/db/migrate/20220708152039_new_default_duree_conservation_entendue_par_ds.rb b/db/migrate/20220708152039_new_default_duree_conservation_entendue_par_ds.rb new file mode 100644 index 000000000..e6cc770e3 --- /dev/null +++ b/db/migrate/20220708152039_new_default_duree_conservation_entendue_par_ds.rb @@ -0,0 +1,5 @@ +class NewDefaultDureeConservationEntendueParDs < ActiveRecord::Migration[6.1] + def change + change_column_default :procedures, :duree_conservation_etendue_par_ds, false + end +end diff --git a/db/schema.rb b/db/schema.rb index 01ceabc9d..eeca800f2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_06_22_183305) do +ActiveRecord::Schema.define(version: 2022_07_08_152039) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -636,7 +636,7 @@ ActiveRecord::Schema.define(version: 2022_06_22_183305) do t.string "direction" t.bigint "draft_revision_id" t.integer "duree_conservation_dossiers_dans_ds" - t.integer "duree_conservation_dossiers_hors_ds" + t.boolean "duree_conservation_etendue_par_ds", default: false t.boolean "durees_conservation_required", default: true t.string "encrypted_api_particulier_token" t.boolean "euro_flag", default: false diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index a939e101f..6316080ec 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -281,19 +281,26 @@ describe Procedure do end end - shared_examples 'duree de conservation' do - context 'duree_conservation_required it true, the field gets validated' do + describe 'duree de conservation dans ds' do + let(:field_name) { :duree_conservation_dossiers_dans_ds } + + context 'for old procedures, duree_conservation_required it true, the field gets validated' do + subject { create(:procedure, duree_conservation_etendue_par_ds: true) } it { is_expected.not_to allow_value(nil).for(field_name) } it { is_expected.not_to allow_value('').for(field_name) } it { is_expected.not_to allow_value('trois').for(field_name) } it { is_expected.to allow_value(3).for(field_name) } + it { is_expected.to allow_value(36).for(field_name) } + it { is_expected.to validate_numericality_of(field_name).is_less_than_or_equal_to(Procedure::OLD_MAX_DUREE_CONSERVATION) } end - end - describe 'duree de conservation dans ds' do - let(:field_name) { :duree_conservation_dossiers_dans_ds } - - it_behaves_like 'duree de conservation' + context 'for new procedures, duree_conservation_required it true, the field gets validated' do + subject { create(:procedure, duree_conservation_etendue_par_ds: false) } + it { is_expected.not_to allow_value(nil).for(field_name) } + it { is_expected.not_to allow_value('').for(field_name) } + it { is_expected.not_to allow_value('trois').for(field_name) } + it { is_expected.to validate_numericality_of(field_name).is_less_than_or_equal_to(Procedure::NEW_MAX_DUREE_CONSERVATION) } + end end describe 'draft_types_de_champ validations' do