From 243b8c239aae02a65be1c7640c81f0325451ab9a Mon Sep 17 00:00:00 2001 From: seb-by-ouidou Date: Mon, 24 Jul 2023 15:55:33 +0000 Subject: [PATCH] feat(administrateur): add environment variable for Administrateur::UNUSED_ADMIN_THRESHOLD --- app/models/administrateur.rb | 2 +- config/env.example.optional | 3 +++ spec/models/administrateur_spec.rb | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/models/administrateur.rb b/app/models/administrateur.rb index 2a2386af1..819f9a15c 100644 --- a/app/models/administrateur.rb +++ b/app/models/administrateur.rb @@ -8,7 +8,7 @@ # user_id :bigint not null # class Administrateur < ApplicationRecord - UNUSED_ADMIN_THRESHOLD = 6.months + UNUSED_ADMIN_THRESHOLD = ENV.fetch('UNUSED_ADMIN_THRESHOLD') { 6 }.to_i.months has_and_belongs_to_many :instructeurs has_many :administrateurs_procedures diff --git a/config/env.example.optional b/config/env.example.optional index 4d1d03627..a2a59e0c0 100644 --- a/config/env.example.optional +++ b/config/env.example.optional @@ -140,6 +140,9 @@ VITE_LEGACY="" # around july 2022, we changed the duree_conservation_dossiers_dans_ds, allow instances to choose their own duration NEW_MAX_DUREE_CONSERVATION=12 +#number of months after which DS considere an administrateur useless (if no service and no procedure) +#UNUSED_ADMIN_THRESHOLD=6 + # Open data OPENDATA_ENABLED="enabled" # disabled by default if `OPENDATA_ENABLED` not set diff --git a/spec/models/administrateur_spec.rb b/spec/models/administrateur_spec.rb index 03eaeb8e7..8770d55f4 100644 --- a/spec/models/administrateur_spec.rb +++ b/spec/models/administrateur_spec.rb @@ -232,6 +232,18 @@ describe Administrateur, type: :model do it { is_expected.to be_empty } end + + context 'with a custom longer threshold period' do + before { stub_const("Administrateur::UNUSED_ADMIN_THRESHOLD", 7.months) } + + it { is_expected.to be_empty } + end + + context 'with a custom shorter threshold period' do + before { stub_const("Administrateur::UNUSED_ADMIN_THRESHOLD", 5.months) } + + it { is_expected.to match([new_admin, unused_admin]) } + end end describe 'zones' do