dont use depreciated column hidden_at

This commit is contained in:
Lisa Durand 2024-06-12 16:32:42 +02:00
parent 8b88fafc25
commit 9346020889
No known key found for this signature in database
GPG key ID: 0DF91F2CA1E8B816
17 changed files with 63 additions and 59 deletions

View file

@ -379,7 +379,7 @@ module Instructeurs
elsif action_name == 'extend_conservation' elsif action_name == 'extend_conservation'
Dossier Dossier
.where(id: current_instructeur.dossiers.visible_by_administration) .where(id: current_instructeur.dossiers.visible_by_administration)
.or(Dossier.where(id: current_instructeur.dossiers.hidden_by_automatic)) .or(Dossier.where(id: current_instructeur.dossiers.hidden_by_expired))
else else
current_instructeur.dossiers.visible_by_administration current_instructeur.dossiers.visible_by_administration
end end

View file

@ -57,7 +57,7 @@ module Users
@user_dossiers = current_user.dossiers.state_not_termine.merge(@dossiers_visibles) @user_dossiers = current_user.dossiers.state_not_termine.merge(@dossiers_visibles)
@dossiers_traites = current_user.dossiers.state_termine.merge(@dossiers_visibles) @dossiers_traites = current_user.dossiers.state_termine.merge(@dossiers_visibles)
@dossiers_invites = current_user.dossiers_invites.merge(@dossiers_visibles) @dossiers_invites = current_user.dossiers_invites.merge(@dossiers_visibles)
@dossiers_supprimes_recemment = (current_user.dossiers.hidden_by_user.or(current_user.dossiers.hidden_by_automatic)).merge(ordered_dossiers) @dossiers_supprimes_recemment = current_user.dossiers.hidden_by_user.merge(ordered_dossiers)
@dossier_transferes = @dossiers_visibles.where(dossier_transfer_id: DossierTransfer.for_email(current_user.email)) @dossier_transferes = @dossiers_visibles.where(dossier_transfer_id: DossierTransfer.for_email(current_user.email))
@dossiers_close_to_expiration = current_user.dossiers.close_to_expiration.merge(@dossiers_visibles) @dossiers_close_to_expiration = current_user.dossiers.close_to_expiration.merge(@dossiers_visibles)
@dossiers_supprimes_definitivement = deleted_dossiers @dossiers_supprimes_definitivement = deleted_dossiers
@ -256,8 +256,8 @@ module Users
def extend_conservation def extend_conservation
dossier.extend_conservation(dossier.procedure.duree_conservation_dossiers_dans_ds.months) dossier.extend_conservation(dossier.procedure.duree_conservation_dossiers_dans_ds.months)
if dossier.hidden_at.present? if dossier.hidden_by_reason == 'expired'
dossier.update!(hidden_at: nil, hidden_by_reason: nil) dossier.update!(hidden_by_administration_at: nil, hidden_by_user_at: nil, hidden_by_reason: nil)
end end
flash[:notice] = t('views.users.dossiers.archived_dossier', duree_conservation_dossiers_dans_ds: dossier.procedure.duree_conservation_dossiers_dans_ds) flash[:notice] = t('views.users.dossiers.archived_dossier', duree_conservation_dossiers_dans_ds: dossier.procedure.duree_conservation_dossiers_dans_ds)
@ -536,7 +536,7 @@ module Users
elsif action_name == 'restore' elsif action_name == 'restore'
Dossier.hidden_by_user Dossier.hidden_by_user
elsif action_name == 'extend_conservation' elsif action_name == 'extend_conservation'
Dossier.visible_by_user.or(Dossier.hidden_by_automatic) Dossier.visible_by_user.or(Dossier.hidden_by_expired)
else else
Dossier.visible_by_user Dossier.visible_by_user
end end

View file

@ -208,7 +208,6 @@ class Dossier < ApplicationRecord
scope :state_en_construction, -> { where(state: states.fetch(:en_construction)) } scope :state_en_construction, -> { where(state: states.fetch(:en_construction)) }
scope :state_not_en_construction, -> { where.not(state: states.fetch(:en_construction)) } scope :state_not_en_construction, -> { where.not(state: states.fetch(:en_construction)) }
scope :state_en_instruction, -> { where(state: states.fetch(:en_instruction)) } scope :state_en_instruction, -> { where(state: states.fetch(:en_instruction)) }
scope :state_not_en_instruction, -> { where.not(state: states.fetch(:en_instruction)) }
scope :state_en_construction_ou_instruction, -> { where(state: EN_CONSTRUCTION_OU_INSTRUCTION) } scope :state_en_construction_ou_instruction, -> { where(state: EN_CONSTRUCTION_OU_INSTRUCTION) }
scope :state_instruction_commencee, -> { where(state: INSTRUCTION_COMMENCEE) } scope :state_instruction_commencee, -> { where(state: INSTRUCTION_COMMENCEE) }
scope :state_termine, -> { where(state: TERMINE) } scope :state_termine, -> { where(state: TERMINE) }
@ -221,13 +220,12 @@ class Dossier < ApplicationRecord
scope :not_archived, -> { where(archived: false) } scope :not_archived, -> { where(archived: false) }
scope :prefilled, -> { where(prefilled: true) } scope :prefilled, -> { where(prefilled: true) }
scope :hidden_by_user, -> { where.not(hidden_by_user_at: nil) } scope :hidden_by_user, -> { where.not(hidden_by_user_at: nil) }
scope :hidden_by_automatic, -> { where.not(hidden_at: nil).where(hidden_by_reason: 'expired') }
scope :hidden_by_administration, -> { where.not(hidden_by_administration_at: nil) } scope :hidden_by_administration, -> { where.not(hidden_by_administration_at: nil) }
scope :visible_by_user, -> { where(for_procedure_preview: false).where(hidden_by_user_at: nil, editing_fork_origin_id: nil).where(hidden_at: nil) } scope :hidden_by_expired, -> { where(hidden_by_reason: 'expired') }
scope :visible_by_user, -> { where(for_procedure_preview: false).where(hidden_by_user_at: nil, editing_fork_origin_id: nil) }
scope :visible_by_administration, -> { scope :visible_by_administration, -> {
state_not_brouillon state_not_brouillon
.where(hidden_by_administration_at: nil) .where(hidden_by_administration_at: nil)
.where(hidden_at: nil)
.merge(visible_by_user.or(state_not_en_construction)) .merge(visible_by_user.or(state_not_en_construction))
} }
scope :visible_by_user_or_administration, -> { visible_by_user.or(visible_by_administration) } scope :visible_by_user_or_administration, -> { visible_by_user.or(visible_by_administration) }
@ -366,14 +364,11 @@ class Dossier < ApplicationRecord
scope :without_brouillon_expiration_notice_sent, -> { where(brouillon_close_to_expiration_notice_sent_at: nil) } scope :without_brouillon_expiration_notice_sent, -> { where(brouillon_close_to_expiration_notice_sent_at: nil) }
scope :without_en_construction_expiration_notice_sent, -> { where(en_construction_close_to_expiration_notice_sent_at: nil) } scope :without_en_construction_expiration_notice_sent, -> { where(en_construction_close_to_expiration_notice_sent_at: nil) }
scope :without_termine_expiration_notice_sent, -> { where(termine_close_to_expiration_notice_sent_at: nil) } scope :without_termine_expiration_notice_sent, -> { where(termine_close_to_expiration_notice_sent_at: nil) }
scope :deleted_by_user_expired, -> { where('dossiers.hidden_by_user_at < ?', 1.week.ago) } scope :deleted_by_user_expired, -> { where('dossiers.hidden_by_user_at < ?', 1.week.ago) }
scope :deleted_by_automatic_expired, -> { where('dossiers.hidden_at < ?', 1.week.ago) }
scope :deleted_by_administration_expired, -> { where('dossiers.hidden_by_administration_at < ?', 1.week.ago) } scope :deleted_by_administration_expired, -> { where('dossiers.hidden_by_administration_at < ?', 1.week.ago) }
scope :en_brouillon_expired_to_delete, -> { state_brouillon.deleted_by_user_expired } scope :en_brouillon_expired_to_delete, -> { state_brouillon.deleted_by_user_expired }
scope :en_construction_expired_to_delete, -> { state_en_construction.deleted_by_user_expired } scope :en_construction_expired_to_delete, -> { state_en_construction.deleted_by_user_expired }
scope :termine_expired_to_delete, -> { state_termine.deleted_by_user_expired.deleted_by_administration_expired } scope :termine_expired_to_delete, -> { state_termine.deleted_by_user_expired.deleted_by_administration_expired }
scope :not_en_instruction_expired_to_delete, -> { state_not_en_instruction.deleted_by_automatic_expired }
scope :brouillon_near_procedure_closing_date, -> do scope :brouillon_near_procedure_closing_date, -> do
# select users who have submitted dossier for the given 'procedures.id' # select users who have submitted dossier for the given 'procedures.id'
@ -420,7 +415,7 @@ class Dossier < ApplicationRecord
when 'tous' when 'tous'
visible_by_administration.all_state visible_by_administration.all_state
when 'supprimes_recemment' when 'supprimes_recemment'
hidden_by_administration.state_termine.or(hidden_by_automatic) hidden_by_administration
when 'archives' when 'archives'
visible_by_administration.archived visible_by_administration.archived
when 'expirant' when 'expirant'
@ -606,7 +601,7 @@ class Dossier < ApplicationRecord
end end
def can_be_deleted_by_automatic?(reason) def can_be_deleted_by_automatic?(reason)
reason == :expired brouillon? || en_construction? || termine? || reason == :expired
end end
def can_terminer_automatiquement_by_sva_svr? def can_terminer_automatiquement_by_sva_svr?
@ -690,8 +685,8 @@ class Dossier < ApplicationRecord
en_construction_close_to_expiration_notice_sent_at: nil, en_construction_close_to_expiration_notice_sent_at: nil,
termine_close_to_expiration_notice_sent_at: nil) termine_close_to_expiration_notice_sent_at: nil)
if hidden_at.present? if hidden_by_reason == 'expired'
update(hidden_at: nil, hidden_by_reason: nil) update(hidden_by_administration_at: nil, hidden_by_user_at: nil, hidden_by_reason: nil)
end end
end end
@ -857,7 +852,7 @@ class Dossier < ApplicationRecord
elsif author_is_user(author) && can_be_deleted_by_user? elsif author_is_user(author) && can_be_deleted_by_user?
update(hidden_by_user_at: Time.zone.now, dossier_transfer_id: nil, hidden_by_reason: reason) update(hidden_by_user_at: Time.zone.now, dossier_transfer_id: nil, hidden_by_reason: reason)
elsif author_is_automatic(author) && can_be_deleted_by_automatic?(reason) elsif author_is_automatic(author) && can_be_deleted_by_automatic?(reason)
update(hidden_at: Time.zone.now, hidden_by_reason: reason) update(hidden_by_administration_at: Time.zone.now, hidden_by_user_at: Time.zone.now, hidden_by_reason: reason)
else else
raise "Unauthorized dossier hide attempt Dossier##{id} by #{author} for reason #{reason}" raise "Unauthorized dossier hide attempt Dossier##{id} by #{author} for reason #{reason}"
end end
@ -1113,7 +1108,6 @@ class Dossier < ApplicationRecord
en_brouillon_expired_to_delete.find_each(&:purge_discarded) en_brouillon_expired_to_delete.find_each(&:purge_discarded)
en_construction_expired_to_delete.find_each(&:purge_discarded) en_construction_expired_to_delete.find_each(&:purge_discarded)
termine_expired_to_delete.find_each(&:purge_discarded) termine_expired_to_delete.find_each(&:purge_discarded)
not_en_instruction_expired_to_delete.find_each(&:purge_discarded)
end end
def skip_user_notification_email? def skip_user_notification_email?

View file

@ -227,18 +227,19 @@ class Instructeur < ApplicationRecord
def dossiers_count_summary(groupe_instructeur_ids) def dossiers_count_summary(groupe_instructeur_ids)
query = <<~EOF query = <<~EOF
SELECT SELECT
COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NULL AND dossiers.hidden_at IS NULL AND not archived AND dossiers.state in ('en_construction', 'en_instruction') AND follows.id IS NULL) AS a_suivre, COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NULL AND not archived AND dossiers.state in ('en_construction', 'en_instruction') AND follows.id IS NULL) AS a_suivre,
COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NULL AND dossiers.hidden_at IS NULL AND not archived AND dossiers.state in ('en_construction', 'en_instruction') AND follows.instructeur_id = :instructeur_id) AS suivis, COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NULL AND not archived AND dossiers.state in ('en_construction', 'en_instruction') AND follows.instructeur_id = :instructeur_id) AS suivis,
COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NULL AND dossiers.hidden_at IS NULL AND not archived AND dossiers.state in ('accepte', 'refuse', 'sans_suite')) AS traites, COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NULL AND not archived AND dossiers.state in ('accepte', 'refuse', 'sans_suite')) AS traites,
COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NULL AND dossiers.hidden_at IS NULL AND not archived) AS tous, COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NULL AND not archived) AS tous,
COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NULL AND dossiers.hidden_at IS NULL AND archived) AS archives, COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NULL AND archived) AS archives,
COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NOT NULL AND not archived OR dossiers.hidden_at IS NOT NULL) AS supprimes_recemment, COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NOT NULL AND not archived AND dossiers.state in ('en_construction', 'accepte', 'refuse', 'sans_suite')) AS supprimes_recemment,
COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NULL AND dossiers.hidden_at IS NULL AND procedures.procedure_expires_when_termine_enabled COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NULL AND procedures.procedure_expires_when_termine_enabled
AND ( AND (
dossiers.state in ('accepte', 'refuse', 'sans_suite') dossiers.state in ('accepte', 'refuse', 'sans_suite')
AND dossiers.processed_at + dossiers.conservation_extension + (procedures.duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now AND dossiers.processed_at + dossiers.conservation_extension + (procedures.duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now
) OR ( ) OR (
dossiers.state in ('en_construction') AND dossiers.hidden_at IS NULL dossiers.state in ('en_construction')
AND dossiers.hidden_by_administration_at IS NULL
AND dossiers.en_construction_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now AND dossiers.en_construction_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now
) )
) AS expirant ) AS expirant
@ -252,7 +253,6 @@ class Instructeur < ApplicationRecord
AND follows.unfollowed_at IS NULL AND follows.unfollowed_at IS NULL
WHERE dossiers.state != 'brouillon' WHERE dossiers.state != 'brouillon'
AND dossiers.groupe_instructeur_id in (:groupe_instructeur_ids) AND dossiers.groupe_instructeur_id in (:groupe_instructeur_ids)
AND (dossiers.hidden_by_user_at IS NULL OR dossiers.state != 'en_construction')
EOF EOF
sanitized_query = ActiveRecord::Base.sanitize_sql([ sanitized_query = ActiveRecord::Base.sanitize_sql([

View file

@ -1,5 +1,5 @@
class DossierProjectionService class DossierProjectionService
class DossierProjection < Struct.new(:dossier_id, :state, :archived, :hidden_by_user_at, :hidden_by_administration_at, :hidden_at, :for_tiers, :prenom, :nom, :batch_operation_id, :sva_svr_decision_on, :corrections, :columns) do class DossierProjection < Struct.new(:dossier_id, :state, :archived, :hidden_by_user_at, :hidden_by_administration_at, :hidden_by_reason, :for_tiers, :prenom, :nom, :batch_operation_id, :sva_svr_decision_on, :corrections, :columns) do
def pending_correction? def pending_correction?
return false if corrections.blank? return false if corrections.blank?
@ -44,14 +44,14 @@ class DossierProjectionService
batch_operation_field = { TABLE => 'self', COLUMN => 'batch_operation_id' } batch_operation_field = { TABLE => 'self', COLUMN => 'batch_operation_id' }
hidden_by_user_at_field = { TABLE => 'self', COLUMN => 'hidden_by_user_at' } hidden_by_user_at_field = { TABLE => 'self', COLUMN => 'hidden_by_user_at' }
hidden_by_administration_at_field = { TABLE => 'self', COLUMN => 'hidden_by_administration_at' } hidden_by_administration_at_field = { TABLE => 'self', COLUMN => 'hidden_by_administration_at' }
hidden_at_field = { TABLE => 'self', COLUMN => 'hidden_at' } hidden_by_reason_field = { TABLE => 'self', COLUMN => 'hidden_by_reason' }
for_tiers_field = { TABLE => 'self', COLUMN => 'for_tiers' } for_tiers_field = { TABLE => 'self', COLUMN => 'for_tiers' }
individual_first_name = { TABLE => 'individual', COLUMN => 'prenom' } individual_first_name = { TABLE => 'individual', COLUMN => 'prenom' }
individual_last_name = { TABLE => 'individual', COLUMN => 'nom' } individual_last_name = { TABLE => 'individual', COLUMN => 'nom' }
sva_svr_decision_on_field = { TABLE => 'self', COLUMN => 'sva_svr_decision_on' } sva_svr_decision_on_field = { TABLE => 'self', COLUMN => 'sva_svr_decision_on' }
dossier_corrections = { TABLE => 'dossier_corrections', COLUMN => 'resolved_at' } dossier_corrections = { TABLE => 'dossier_corrections', COLUMN => 'resolved_at' }
champ_value = champ_value_formatter(dossiers_ids, fields) champ_value = champ_value_formatter(dossiers_ids, fields)
([state_field, archived_field, sva_svr_decision_on_field, hidden_by_user_at_field, hidden_by_administration_at_field, hidden_at_field, for_tiers_field, individual_first_name, individual_last_name, batch_operation_field, dossier_corrections] + fields) ([state_field, archived_field, sva_svr_decision_on_field, hidden_by_user_at_field, hidden_by_administration_at_field, hidden_by_reason_field, for_tiers_field, individual_first_name, individual_last_name, batch_operation_field, dossier_corrections] + fields)
.each { |f| f[:id_value_h] = {} } .each { |f| f[:id_value_h] = {} }
.group_by { |f| f[TABLE] } # one query per table .group_by { |f| f[TABLE] } # one query per table
.each do |table, fields| .each do |table, fields|
@ -74,7 +74,7 @@ class DossierProjectionService
.pluck(:id, *fields.map { |f| f[COLUMN].to_sym }) .pluck(:id, *fields.map { |f| f[COLUMN].to_sym })
.each do |id, *columns| .each do |id, *columns|
fields.zip(columns).each do |field, value| fields.zip(columns).each do |field, value|
if [state_field, archived_field, hidden_by_user_at_field, hidden_by_administration_at_field, hidden_at_field, for_tiers_field, batch_operation_field, sva_svr_decision_on_field].include?(field) if [state_field, archived_field, hidden_by_user_at_field, hidden_by_administration_at_field, hidden_by_reason_field, for_tiers_field, batch_operation_field, sva_svr_decision_on_field].include?(field)
field[:id_value_h][id] = value field[:id_value_h][id] = value
else else
field[:id_value_h][id] = value&.strftime('%d/%m/%Y') # other fields are datetime field[:id_value_h][id] = value&.strftime('%d/%m/%Y') # other fields are datetime
@ -151,7 +151,7 @@ class DossierProjectionService
archived_field[:id_value_h][dossier_id], archived_field[:id_value_h][dossier_id],
hidden_by_user_at_field[:id_value_h][dossier_id], hidden_by_user_at_field[:id_value_h][dossier_id],
hidden_by_administration_at_field[:id_value_h][dossier_id], hidden_by_administration_at_field[:id_value_h][dossier_id],
hidden_at_field[:id_value_h][dossier_id], hidden_by_reason_field[:id_value_h][dossier_id],
for_tiers_field[:id_value_h][dossier_id], for_tiers_field[:id_value_h][dossier_id],
individual_first_name[:id_value_h][dossier_id], individual_first_name[:id_value_h][dossier_id],
individual_last_name[:id_value_h][dossier_id], individual_last_name[:id_value_h][dossier_id],

View file

@ -8,7 +8,7 @@
dossier_is_followed: current_instructeur&.follow?(dossier), dossier_is_followed: current_instructeur&.follow?(dossier),
close_to_expiration: dossier.close_to_expiration?, close_to_expiration: dossier.close_to_expiration?,
hidden_by_administration: dossier.hidden_by_administration?, hidden_by_administration: dossier.hidden_by_administration?,
hidden_at: dossier.hidden_at.present?, hidden_by_expired: dossier.hidden_by_reason == 'expired',
has_pending_correction: dossier.pending_correction?, has_pending_correction: dossier.pending_correction?,
has_blocking_pending_correction: dossier.procedure.feature_enabled?(:blocking_pending_correction) && dossier.pending_correction?, has_blocking_pending_correction: dossier.procedure.feature_enabled?(:blocking_pending_correction) && dossier.pending_correction?,
turbo: true, turbo: true,

View file

@ -1,4 +1,4 @@
- if hidden_by_administration && hidden_at - if hidden_by_administration && hidden_by_expired
%li %li
= button_to repousser_expiration_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: "fr-btn fr-icon-refresh-line" do = button_to repousser_expiration_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: "fr-btn fr-icon-refresh-line" do
= t('views.instructeurs.dossiers.restore_and_extend') = t('views.instructeurs.dossiers.restore_and_extend')

View file

@ -144,11 +144,12 @@
- if p.hidden_by_administration_at.present? - if p.hidden_by_administration_at.present?
%span.cell-link %span.cell-link
= column = column
= "- #{t('views.instructeurs.dossiers.deleted_by_user')}" if p.hidden_by_user_at.present? - if p.hidden_by_user_at.present?
= "- #{t("views.instructeurs.dossiers.deleted_reason.#{p.hidden_by_reason}")}"
- else - else
%a.cell-link{ href: path } %a.cell-link{ href: path }
= column = column
= "- #{t('views.instructeurs.dossiers.deleted_by_user')}" if p.hidden_by_user_at.present? = "- #{t('views.instructeurs.dossiers.deleted_reason', reason: p.hidden_by_reason)}" if p.hidden_by_user_at.present?
%td.status-col %td.status-col
- status = [status_badge(p.state)] - status = [status_badge(p.state)]
@ -172,7 +173,7 @@
dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id), dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id),
close_to_expiration: @statut == 'expirant', close_to_expiration: @statut == 'expirant',
hidden_by_administration: @statut == 'supprimes_recemment', hidden_by_administration: @statut == 'supprimes_recemment',
hidden_at: p.hidden_at.present?, hidden_by_expired: p.hidden_by_reason == 'expired',
sva_svr: @procedure.sva_svr_enabled?, sva_svr: @procedure.sva_svr_enabled?,
has_blocking_pending_correction: @procedure.feature_enabled?(:blocking_pending_correction) && p.pending_correction?, has_blocking_pending_correction: @procedure.feature_enabled?(:blocking_pending_correction) && p.pending_correction?,
turbo: false, turbo: false,

View file

@ -102,7 +102,7 @@
dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id), dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id),
close_to_expiration: nil, close_to_expiration: nil,
hidden_by_administration: nil, hidden_by_administration: nil,
hidden_at: nil, hidden_by_expired: nil,
sva_svr: p.sva_svr_decision_on.present?, sva_svr: p.sva_svr_decision_on.present?,
has_blocking_pending_correction: p.pending_correction? && Flipper.enabled?(:blocking_pending_correction, ProcedureFlipperActor.new(procedure_id)), has_blocking_pending_correction: p.pending_correction? && Flipper.enabled?(:blocking_pending_correction, ProcedureFlipperActor.new(procedure_id)),
turbo: false, turbo: false,

View file

@ -16,12 +16,12 @@
%p.fr-icon--sm.fr-icon-user-line %p.fr-icon--sm.fr-icon-user-line
= demandeur_dossier(dossier) = demandeur_dossier(dossier)
- if dossier.hidden_by_user? - if dossier.hidden_by_reason == 'expired'
%p.fr-icon--sm.fr-icon-delete-line
= t('views.users.dossiers.dossiers_list.deleted_by_automatic', date: l(dossier.hidden_by_user_at.to_date))
- elsif dossier.hidden_by_user?
%p.fr-icon--sm.fr-icon-delete-line %p.fr-icon--sm.fr-icon-delete-line
= t('views.users.dossiers.dossiers_list.deleted_by_user', date: l(dossier.hidden_by_user_at.to_date)) = t('views.users.dossiers.dossiers_list.deleted_by_user', date: l(dossier.hidden_by_user_at.to_date))
- elsif dossier.hidden_at?
%p.fr-icon--sm.fr-icon-delete-line
= t('views.users.dossiers.dossiers_list.deleted_by_automatic', date: l(dossier.hidden_at.to_date))
- else - else
%p.fr-icon--sm.fr-icon-edit-box-line %p.fr-icon--sm.fr-icon-edit-box-line
- if dossier.depose_at.present? - if dossier.depose_at.present?
@ -108,7 +108,7 @@
- if @statut == "dossiers-supprimes-recemment" - if @statut == "dossiers-supprimes-recemment"
.flex.justify-end .flex.justify-end
- if dossier.hidden_at.blank? - if dossier.hidden_by_reason != 'expired'
= link_to restore_dossier_path(dossier.id), method: :patch, class: "fr-btn fr-btn--sm" do = link_to restore_dossier_path(dossier.id), method: :patch, class: "fr-btn fr-btn--sm" do
Restaurer Restaurer

View file

@ -406,7 +406,6 @@ en:
expirant: Records will not expire prior to the data retention period. expirant: Records will not expire prior to the data retention period.
archived_dossier: "This file will be kept for an additional month" archived_dossier: "This file will be kept for an additional month"
delete_dossier: "Delete file" delete_dossier: "Delete file"
deleted_by_user: "File deleted by user"
acts_on_behalf: "acts for" acts_on_behalf: "acts for"
deleted_by_administration: "File deleted by administration" deleted_by_administration: "File deleted by administration"
restore: "Restore" restore: "Restore"

View file

@ -405,7 +405,9 @@ fr:
expirant: Les dossiers nexpireront pas avant la période de conservation des données. expirant: Les dossiers nexpireront pas avant la période de conservation des données.
archived_dossier: "Le dossier sera conservé 1 mois supplémentaire" archived_dossier: "Le dossier sera conservé 1 mois supplémentaire"
delete_dossier: "Supprimer le dossier" delete_dossier: "Supprimer le dossier"
deleted_by_user: "Dossier supprimé par lusager" deleted_reason:
user_request: supprimé par l'usager
expired: a expiré
acts_on_behalf: "agit pour" acts_on_behalf: "agit pour"
deleted_by_administration: "Dossier supprimé par ladministration" deleted_by_administration: "Dossier supprimé par ladministration"
restore: "Restaurer" restore: "Restaurer"

View file

@ -1309,13 +1309,14 @@ describe Instructeurs::DossiersController, type: :controller do
describe '#extend_conservation and restore' do describe '#extend_conservation and restore' do
before do before do
dossier.update(hidden_at: 1.hour.ago, hidden_by_reason: 'expired') dossier.update(hidden_by_administration_at: 1.hour.ago, hidden_by_user_at: 1.hour.ago, hidden_by_reason: 'expired')
end end
subject { post :extend_conservation, params: { procedure_id: procedure.id, dossier_id: dossier.id } } subject { post :extend_conservation, params: { procedure_id: procedure.id, dossier_id: dossier.id } }
it "puts hidden_at to nil and extends conservation_extension by 1 month" do it "puts hidden_by to nil and extends conservation_extension by 1 month" do
subject subject
expect(dossier.reload.hidden_at).to eq(nil) expect(dossier.reload.hidden_by_administration_at).to eq(nil)
expect(dossier.reload.hidden_by_user_at).to eq(nil)
expect(dossier.reload.conservation_extension).to eq(1.month) expect(dossier.reload.conservation_extension).to eq(1.month)
end end
end end

View file

@ -114,8 +114,9 @@ FactoryBot.define do
hidden_at { Time.zone.now } hidden_at { Time.zone.now }
end end
trait :hidden_by_automatic do trait :hidden_by_expired do
hidden_at { Time.zone.now } hidden_by_user_at { 1.day.ago }
hidden_by_administration_at { 1.day.ago }
hidden_by_reason { DeletedDossier.reasons.fetch(:expired) } hidden_by_reason { DeletedDossier.reasons.fetch(:expired) }
end end

View file

@ -10,7 +10,7 @@ RSpec.describe Cron::DiscardedDossiersDeletionJob, type: :job do
dossier.send(:log_dossier_operation, instructeur, :supprimer, dossier) dossier.send(:log_dossier_operation, instructeur, :supprimer, dossier)
dossier.update_columns(hidden_by_user_at: hidden_at, hidden_by_administration_at: hidden_at) dossier.update_columns(hidden_by_user_at: hidden_at, hidden_by_administration_at: hidden_at)
dossier.update_column(:hidden_by_reason, "user_request") dossier.update_column(:hidden_by_reason, "user_request")
dossier_2.update_columns(hidden_at: hidden_at) dossier_2.update_columns(hidden_by_user_at: hidden_at, hidden_by_administration_at: hidden_at)
dossier_2.update_column(:hidden_by_reason, "expired") dossier_2.update_column(:hidden_by_reason, "expired")
end end

View file

@ -246,7 +246,8 @@ describe Expired::DossiersDeletionService do
it { expect(DossierMailer).to have_received(:notify_automatic_deletion_to_administration).with([dossier], dossier.procedure.administrateurs.first.email) } it { expect(DossierMailer).to have_received(:notify_automatic_deletion_to_administration).with([dossier], dossier.procedure.administrateurs.first.email) }
it { expect(DossierMailer).to have_received(:notify_automatic_deletion_to_administration).with([dossier], dossier.followers_instructeurs.first.email) } it { expect(DossierMailer).to have_received(:notify_automatic_deletion_to_administration).with([dossier], dossier.followers_instructeurs.first.email) }
it { expect(dossier.reload.hidden_at).to be_an_instance_of(ActiveSupport::TimeWithZone) } it { expect(dossier.reload.hidden_by_user_at).to be_an_instance_of(ActiveSupport::TimeWithZone) }
it { expect(dossier.reload.hidden_by_administration_at).to be_an_instance_of(ActiveSupport::TimeWithZone) }
it { expect(dossier.reload.hidden_by_reason).to eq('expired') } it { expect(dossier.reload.hidden_by_reason).to eq('expired') }
end end
end end
@ -270,9 +271,11 @@ describe Expired::DossiersDeletionService do
it { expect(DossierMailer).to have_received(:notify_automatic_deletion_to_administration).with([dossier_1], dossier_1.procedure.administrateurs.first.email) } it { expect(DossierMailer).to have_received(:notify_automatic_deletion_to_administration).with([dossier_1], dossier_1.procedure.administrateurs.first.email) }
it { expect(DossierMailer).to have_received(:notify_automatic_deletion_to_administration).with([dossier_2], dossier_2.procedure.administrateurs.first.email) } it { expect(DossierMailer).to have_received(:notify_automatic_deletion_to_administration).with([dossier_2], dossier_2.procedure.administrateurs.first.email) }
it { expect(dossier_1.reload.hidden_at).to be_an_instance_of(ActiveSupport::TimeWithZone) } it { expect(dossier_1.reload.hidden_by_user_at).to be_an_instance_of(ActiveSupport::TimeWithZone) }
it { expect(dossier_1.reload.hidden_by_administration_at).to be_an_instance_of(ActiveSupport::TimeWithZone) }
it { expect(dossier_1.reload.hidden_by_reason).to eq('expired') } it { expect(dossier_1.reload.hidden_by_reason).to eq('expired') }
it { expect(dossier_2.reload.hidden_at).to be_an_instance_of(ActiveSupport::TimeWithZone) } it { expect(dossier_2.reload.hidden_by_user_at).to be_an_instance_of(ActiveSupport::TimeWithZone) }
it { expect(dossier_2.reload.hidden_by_administration_at).to be_an_instance_of(ActiveSupport::TimeWithZone) }
it { expect(dossier_2.reload.hidden_by_reason).to eq('expired') } it { expect(dossier_2.reload.hidden_by_reason).to eq('expired') }
end end
end end
@ -389,7 +392,8 @@ describe Expired::DossiersDeletionService do
context 'when a notice has been sent a long time ago' do context 'when a notice has been sent a long time ago' do
let(:notice_sent_at) { (warning_period + 4.days).ago } let(:notice_sent_at) { (warning_period + 4.days).ago }
it { expect(dossier.reload.hidden_at).to be_an_instance_of(ActiveSupport::TimeWithZone) } it { expect(dossier.reload.hidden_by_user_at).to be_an_instance_of(ActiveSupport::TimeWithZone) }
it { expect(dossier.reload.hidden_by_administration_at).to be_an_instance_of(ActiveSupport::TimeWithZone) }
it { expect(dossier.reload.hidden_by_reason).to eq('expired') } it { expect(dossier.reload.hidden_by_reason).to eq('expired') }
it { expect(DossierMailer).to have_received(:notify_automatic_deletion_to_user).once } it { expect(DossierMailer).to have_received(:notify_automatic_deletion_to_user).once }
@ -420,9 +424,11 @@ describe Expired::DossiersDeletionService do
it { expect(DossierMailer).to have_received(:notify_automatic_deletion_to_administration).with([dossier_1], dossier_1.procedure.administrateurs.first.email) } it { expect(DossierMailer).to have_received(:notify_automatic_deletion_to_administration).with([dossier_1], dossier_1.procedure.administrateurs.first.email) }
it { expect(DossierMailer).to have_received(:notify_automatic_deletion_to_administration).with([dossier_2], dossier_2.procedure.administrateurs.first.email) } it { expect(DossierMailer).to have_received(:notify_automatic_deletion_to_administration).with([dossier_2], dossier_2.procedure.administrateurs.first.email) }
it { expect(dossier_1.reload.hidden_at).to be_an_instance_of(ActiveSupport::TimeWithZone) } it { expect(dossier_1.reload.hidden_by_user_at).to be_an_instance_of(ActiveSupport::TimeWithZone) }
it { expect(dossier_1.reload.hidden_by_administration_at).to be_an_instance_of(ActiveSupport::TimeWithZone) }
it { expect(dossier_1.reload.hidden_by_reason).to eq('expired') } it { expect(dossier_1.reload.hidden_by_reason).to eq('expired') }
it { expect(dossier_2.reload.hidden_at).to be_an_instance_of(ActiveSupport::TimeWithZone) } it { expect(dossier_2.reload.hidden_by_user_at).to be_an_instance_of(ActiveSupport::TimeWithZone) }
it { expect(dossier_2.reload.hidden_by_administration_at).to be_an_instance_of(ActiveSupport::TimeWithZone) }
it { expect(dossier_2.reload.hidden_by_reason).to eq('expired') } it { expect(dossier_2.reload.hidden_by_reason).to eq('expired') }
end end

View file

@ -12,8 +12,8 @@ describe 'user access to the list of their dossiers', js: true do
let!(:dossier_for_tiers) { create(:dossier, :en_instruction, :for_tiers_with_notification, user: user) } let!(:dossier_for_tiers) { create(:dossier, :en_instruction, :for_tiers_with_notification, user: user) }
let!(:dossier_en_construction_with_accuse_lecture) { create(:dossier, :en_construction, user: user, procedure: procedure_accuse_lecture) } let!(:dossier_en_construction_with_accuse_lecture) { create(:dossier, :en_construction, user: user, procedure: procedure_accuse_lecture) }
let!(:dossier_accepte_with_accuse_lecture) { create(:dossier, :accepte, user: user, procedure: procedure_accuse_lecture) } let!(:dossier_accepte_with_accuse_lecture) { create(:dossier, :accepte, user: user, procedure: procedure_accuse_lecture) }
let!(:dossier_en_construction_expire) { create(:dossier, :en_construction, :hidden_by_automatic, user: user) } let!(:dossier_en_construction_expire) { create(:dossier, :en_construction, :hidden_by_expired, user: user) }
let!(:dossier_traite_expire) { create(:dossier, :accepte, :hidden_by_automatic, user: user) } let!(:dossier_traite_expire) { create(:dossier, :accepte, :hidden_by_expired, user: user) }
let!(:dossier_en_construction_supprime) { create(:dossier, :with_individual, :with_populated_champs, :en_construction, :hidden_by_user, user: user) } let!(:dossier_en_construction_supprime) { create(:dossier, :with_individual, :with_populated_champs, :en_construction, :hidden_by_user, user: user) }
let(:dossiers_per_page) { 25 } let(:dossiers_per_page) { 25 }
let(:last_updated_dossier) { dossier_en_construction } let(:last_updated_dossier) { dossier_en_construction }