Merge pull request #7860 from mfo/US/procedure-duree-up-to-manager

feat(procedure.max_duree_conservation_dossiers_dans_ds): make it more flexible
This commit is contained in:
mfo 2022-10-06 11:36:50 +02:00 committed by GitHub
commit 8a3550cda4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 26 deletions

View file

@ -38,7 +38,7 @@ class ProcedureDashboard < Administrate::BaseDashboard
attestation_template: AttestationTemplateField,
procedure_expires_when_termine_enabled: Field::Boolean,
duree_conservation_dossiers_dans_ds: Field::Number,
duree_conservation_etendue_par_ds: Field::Boolean
max_duree_conservation_dossiers_dans_ds: Field::Number
}.freeze
# COLLECTION_ATTRIBUTES
@ -88,7 +88,7 @@ class ProcedureDashboard < Administrate::BaseDashboard
:attestation_template,
:procedure_expires_when_termine_enabled,
:duree_conservation_dossiers_dans_ds,
:duree_conservation_etendue_par_ds
:max_duree_conservation_dossiers_dans_ds
].freeze
# FORM_ATTRIBUTES
@ -97,7 +97,7 @@ class ProcedureDashboard < Administrate::BaseDashboard
FORM_ATTRIBUTES = [
:procedure_expires_when_termine_enabled,
:duree_conservation_dossiers_dans_ds,
:duree_conservation_etendue_par_ds
:max_duree_conservation_dossiers_dans_ds
].freeze
# Overwrite this method to customize how procedures are displayed

View file

@ -32,6 +32,7 @@
# lien_dpo :string
# lien_notice :string
# lien_site_web :string
# max_duree_conservation_dossiers_dans_ds :integer default(12)
# monavis_embed :text
# opendata :boolean default(TRUE)
# organisation :string
@ -275,18 +276,15 @@ class Procedure < ApplicationRecord
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
greater_than_or_equal_to: 1,
less_than_or_equal_to: :max_duree_conservation_dossiers_dans_ds
}
validates :max_duree_conservation_dossiers_dans_ds, allow_nil: false,
numericality: {
only_integer: true,
greater_than_or_equal_to: 1,
less_than_or_equal_to: 60
}
validates :lien_dpo, email_or_link: true, allow_nil: true
validates_with MonAvisEmbedValidator

View file

@ -8,7 +8,8 @@ fr:
procedure:
path: Lien public
organisation: Organisme
duree_conservation_dossiers_dans_ds: Durée de conservation des dossiers sur demarches-simplifiees.fr
duree_conservation_dossiers_dans_ds: Durée de conservation des dossiers sur demarches-simplifiees.fr (choisi par un usager)
max_duree_conservation_dossiers_dans_ds: Durée de conservation des dossiers maximum (autorisé par un super admin de DS)
aasm_state/brouillon: Brouillon
aasm_state/publiee: Publiée
aasm_state/close: Close

View file

@ -0,0 +1,6 @@
class MaxColumnDureeConservationDossiersDansDsToProcedure < ActiveRecord::Migration[6.1]
def change
add_column :procedures, :max_duree_conservation_dossiers_dans_ds, :integer
change_column_default :procedures, :max_duree_conservation_dossiers_dans_ds, Procedure::NEW_MAX_DUREE_CONSERVATION
end
end

View file

@ -0,0 +1,10 @@
class BackfillProcedureMaxDureeConservationDossiersDansDs < ActiveRecord::Migration[6.1]
def change
Procedure.where(duree_conservation_etendue_par_ds: true).in_batches do |batch|
batch.update_all(duree_conservation_dossiers_dans_ds: Procedure::OLD_MAX_DUREE_CONSERVATION)
end
Procedure.where(duree_conservation_etendue_par_ds: false).in_batches do |batch|
batch.update_all(duree_conservation_dossiers_dans_ds: Procedure::NEW_MAX_DUREE_CONSERVATION)
end
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_09_11_134914) do
ActiveRecord::Schema.define(version: 2022_10_05_145646) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
@ -652,6 +652,7 @@ ActiveRecord::Schema.define(version: 2022_09_11_134914) do
t.string "lien_dpo"
t.string "lien_notice"
t.string "lien_site_web"
t.integer "max_duree_conservation_dossiers_dans_ds", default: 12
t.text "monavis_embed"
t.boolean "opendata", default: true
t.string "organisation"

View file

@ -283,23 +283,22 @@ describe Procedure 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) }
context 'by default is caped to 12' do
subject { create(:procedure, duree_conservation_dossiers_dans_ds: 12) }
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) }
it { is_expected.to validate_numericality_of(field_name).is_less_than_or_equal_to(12) }
end
context 'for new procedures, duree_conservation_required it true, the field gets validated' do
subject { create(:procedure, duree_conservation_etendue_par_ds: false) }
context 'can be over riden' do
subject { create(:procedure, duree_conservation_dossiers_dans_ds: 60, max_duree_conservation_dossiers_dans_ds: 60) }
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) }
it { is_expected.to allow_value(3).for(field_name) }
it { is_expected.to allow_value(60).for(field_name) }
it { is_expected.to validate_numericality_of(field_name).is_less_than_or_equal_to(60) }
end
end