tech(refactor): centralise/documente les constantes de duree de retentions dans le ns dedié à l'expiration
This commit is contained in:
parent
c9d470d9ec
commit
3186b0aa68
8 changed files with 29 additions and 14 deletions
|
@ -131,7 +131,7 @@ module Administrateurs
|
|||
end
|
||||
|
||||
def create
|
||||
new_procedure_params = { max_duree_conservation_dossiers_dans_ds: Procedure::NEW_MAX_DUREE_CONSERVATION }
|
||||
new_procedure_params = { max_duree_conservation_dossiers_dans_ds: Expired::DEFAULT_DOSSIER_RENTENTION_IN_MONTH }
|
||||
.merge(procedure_params)
|
||||
.merge(administrateurs: [current_administrateur])
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class Procedure < ApplicationRecord
|
|||
default_scope -> { kept }
|
||||
|
||||
OLD_MAX_DUREE_CONSERVATION = 36
|
||||
NEW_MAX_DUREE_CONSERVATION = ENV.fetch('NEW_MAX_DUREE_CONSERVATION') { 12 }.to_i
|
||||
NEW_MAX_DUREE_CONSERVATION = Expired::DEFAULT_DOSSIER_RENTENTION_IN_MONTH
|
||||
|
||||
MIN_WEIGHT = 350000
|
||||
|
||||
|
@ -262,7 +262,7 @@ class Procedure < ApplicationRecord
|
|||
numericality: {
|
||||
only_integer: true,
|
||||
greater_than_or_equal_to: 1,
|
||||
less_than_or_equal_to: 60
|
||||
less_than_or_equal_to: Expired::MAX_DOSSIER_RENTENTION_IN_MONTH
|
||||
}
|
||||
|
||||
validates_with MonAvisEmbedValidator
|
||||
|
|
|
@ -1,6 +1,23 @@
|
|||
module Expired
|
||||
# User is considered inactive after two years of idleness regarding
|
||||
# when he does not have a dossier en instruction
|
||||
# or when his users.last_signed_in_at is smaller than two years ago
|
||||
INACTIVE_USER_RETATION_IN_YEAR = 2
|
||||
|
||||
# Dossier are automatically destroyed after a period (it's configured per Procedure)
|
||||
# a Dossier.en_instruction? is never destroyed
|
||||
# otherwise, a dossier is considered for expiracy after its last traitement
|
||||
DEFAULT_DOSSIER_RENTENTION_IN_MONTH = ENV.fetch('NEW_MAX_DUREE_CONSERVATION') { 12 }.to_i
|
||||
|
||||
# Administateur can ask for higher dossier rentention
|
||||
# but we double check if it's a valid usage
|
||||
MAX_DOSSIER_RENTENTION_IN_MONTH = 60
|
||||
|
||||
# User are always reminded two weeks prior expiracy (for their account as well as their dossier)
|
||||
REMAINING_WEEKS_BEFORE_EXPIRATION = 2
|
||||
|
||||
# Expiracy jobs are run daily.
|
||||
# it send a lot o email, so we spread our jobs through the day
|
||||
def self.schedule_at(caller)
|
||||
case caller.name
|
||||
when 'Cron::ExpiredPrefilledDossiersDeletionJob'
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
class Expired::UsersDeletionService < Expired::MailRateLimiter
|
||||
EXPIRABLE_AFTER_IN_YEAR = 2
|
||||
|
||||
def process_expired
|
||||
[expiring_users_without_dossiers, expiring_users_with_dossiers].each do |expiring_segment|
|
||||
delete_expired_users(expiring_segment)
|
||||
|
@ -42,14 +40,14 @@ class Expired::UsersDeletionService < Expired::MailRateLimiter
|
|||
.and(dossiers[:state].not_eq(Dossier.states.fetch(:en_instruction))))
|
||||
.join_sources
|
||||
)
|
||||
.having('MAX(dossiers.created_at) < ?', EXPIRABLE_AFTER_IN_YEAR.years.ago)
|
||||
.having('MAX(dossiers.created_at) < ?', Expired::INACTIVE_USER_RETATION_IN_YEAR.years.ago)
|
||||
.group('users.id')
|
||||
end
|
||||
|
||||
def expiring_users_without_dossiers
|
||||
User.unscoped
|
||||
.where.missing(:expert, :instructeur, :administrateur, :dossiers)
|
||||
.where(last_sign_in_at: ..EXPIRABLE_AFTER_IN_YEAR.years.ago)
|
||||
.where(last_sign_in_at: ..Expired::INACTIVE_USER_RETATION_IN_YEAR.years.ago)
|
||||
end
|
||||
# rubocop:enable DS/Unscoped
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
- c.with_body do
|
||||
%p
|
||||
= t(:notice, scope: [:administrateurs, :duree_conservation_dossiers_dans_ds])
|
||||
- if f.object.duree_conservation_dossiers_dans_ds.to_i < Procedure::NEW_MAX_DUREE_CONSERVATION
|
||||
- if f.object.duree_conservation_dossiers_dans_ds.to_i < Expired::DEFAULT_DOSSIER_RENTENTION_IN_MONTH
|
||||
%p
|
||||
= t(:new_duration_constraint, scope: [:administrateurs, :duree_conservation_dossiers_dans_ds], new_duration_in_month: f.object.max_duree_conservation_dossiers_dans_ds)
|
||||
|
||||
|
|
|
@ -442,7 +442,7 @@ describe Administrateurs::ProceduresController, type: :controller do
|
|||
let(:duree_conservation_dossiers_dans_ds) { 17 }
|
||||
|
||||
before do
|
||||
stub_const("Procedure::NEW_MAX_DUREE_CONSERVATION", 18)
|
||||
stub_const("Expired::DEFAULT_DOSSIER_RENTENTION_IN_MONTH", 18)
|
||||
end
|
||||
|
||||
subject { post :create, params: { procedure: procedure_params } }
|
||||
|
@ -453,7 +453,7 @@ describe Administrateurs::ProceduresController, type: :controller do
|
|||
subject
|
||||
last_procedure = Procedure.last
|
||||
expect(last_procedure.duree_conservation_dossiers_dans_ds).to eq(duree_conservation_dossiers_dans_ds)
|
||||
expect(last_procedure.max_duree_conservation_dossiers_dans_ds).to eq(Procedure::NEW_MAX_DUREE_CONSERVATION)
|
||||
expect(last_procedure.max_duree_conservation_dossiers_dans_ds).to eq(Expired::DEFAULT_DOSSIER_RENTENTION_IN_MONTH)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -604,7 +604,7 @@ describe Procedure do
|
|||
|
||||
it 'should reset duree_conservation_etendue_par_ds' do
|
||||
expect(subject.duree_conservation_etendue_par_ds).to eq(false)
|
||||
expect(subject.duree_conservation_dossiers_dans_ds).to eq(Procedure::NEW_MAX_DUREE_CONSERVATION)
|
||||
expect(subject.duree_conservation_dossiers_dans_ds).to eq(Expired::DEFAULT_DOSSIER_RENTENTION_IN_MONTH)
|
||||
end
|
||||
|
||||
it 'should duplicate specific objects with different id' do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
describe Expired::UsersDeletionService do
|
||||
let(:last_signed_in_not_expired) { (Expired::UsersDeletionService::EXPIRABLE_AFTER_IN_YEAR - 1).years.ago }
|
||||
let(:last_signed_in_expired) { (Expired::UsersDeletionService::EXPIRABLE_AFTER_IN_YEAR + 1).years.ago }
|
||||
let(:last_signed_in_not_expired) { (Expired::INACTIVE_USER_RETATION_IN_YEAR - 1).years.ago }
|
||||
let(:last_signed_in_expired) { (Expired::INACTIVE_USER_RETATION_IN_YEAR + 1).years.ago }
|
||||
let(:before_close_to_expiration) { nil }
|
||||
let(:notified_close_to_expiration) { (Expired::REMAINING_WEEKS_BEFORE_EXPIRATION - 1).weeks.ago }
|
||||
let(:due_close_to_expiration) { (Expired::REMAINING_WEEKS_BEFORE_EXPIRATION + 1).weeks.ago }
|
||||
|
|
Loading…
Reference in a new issue