Skip to content

Commit

Permalink
dont use depreciated column hidden_at
Browse files Browse the repository at this point in the history
  • Loading branch information
lisa-durand committed Jun 13, 2024
1 parent c942fcd commit ff5bf79
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 59 deletions.
2 changes: 1 addition & 1 deletion app/controllers/instructeurs/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def dossier_scope
elsif action_name == 'extend_conservation'
Dossier
.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
current_instructeur.dossiers.visible_by_administration
end
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/users/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def index
@user_dossiers = current_user.dossiers.state_not_termine.merge(@dossiers_visibles)
@dossiers_traites = current_user.dossiers.state_termine.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))
@dossiers_close_to_expiration = current_user.dossiers.close_to_expiration.merge(@dossiers_visibles)
@dossiers_supprimes_definitivement = deleted_dossiers
Expand Down Expand Up @@ -252,8 +252,8 @@ def submit_brouillon
def extend_conservation
dossier.extend_conservation(dossier.procedure.duree_conservation_dossiers_dans_ds.months)

if dossier.hidden_at.present?
dossier.update!(hidden_at: nil, hidden_by_reason: nil)
if dossier.hidden_by_reason == 'expired'
dossier.update!(hidden_by_administration_at: nil, hidden_by_user_at: nil, hidden_by_reason: nil)
end

flash[:notice] = t('views.users.dossiers.archived_dossier', duree_conservation_dossiers_dans_ds: dossier.procedure.duree_conservation_dossiers_dans_ds)
Expand Down Expand Up @@ -532,7 +532,7 @@ def dossier_scope
elsif action_name == 'restore'
Dossier.hidden_by_user
elsif action_name == 'extend_conservation'
Dossier.visible_by_user.or(Dossier.hidden_by_automatic)
Dossier.visible_by_user.or(Dossier.hidden_by_expired)
else
Dossier.visible_by_user
end
Expand Down
20 changes: 7 additions & 13 deletions app/models/dossier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ def classer_sans_suite(motivation: nil, instructeur: nil, processed_at: Time.zon
scope :state_en_construction, -> { where(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_not_en_instruction, -> { where.not(state: states.fetch(:en_instruction)) }
scope :state_en_construction_ou_instruction, -> { where(state: EN_CONSTRUCTION_OU_INSTRUCTION) }
scope :state_instruction_commencee, -> { where(state: INSTRUCTION_COMMENCEE) }
scope :state_termine, -> { where(state: TERMINE) }
Expand All @@ -221,13 +220,12 @@ def classer_sans_suite(motivation: nil, instructeur: nil, processed_at: Time.zon
scope :not_archived, -> { where(archived: false) }
scope :prefilled, -> { where(prefilled: true) }
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 :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, -> {
state_not_brouillon
.where(hidden_by_administration_at: nil)
.where(hidden_at: nil)
.merge(visible_by_user.or(state_not_en_construction))
}
scope :visible_by_user_or_administration, -> { visible_by_user.or(visible_by_administration) }
Expand Down Expand Up @@ -371,14 +369,11 @@ def classer_sans_suite(motivation: nil, instructeur: nil, processed_at: Time.zon
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_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_automatic_expired, -> { where('dossiers.hidden_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_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 :not_en_instruction_expired_to_delete, -> { state_not_en_instruction.deleted_by_automatic_expired }

scope :brouillon_near_procedure_closing_date, -> do
# select users who have submitted dossier for the given 'procedures.id'
Expand Down Expand Up @@ -425,7 +420,7 @@ def classer_sans_suite(motivation: nil, instructeur: nil, processed_at: Time.zon
when 'tous'
visible_by_administration.all_state
when 'supprimes_recemment'
hidden_by_administration.state_termine.or(hidden_by_automatic)
hidden_by_administration
when 'archives'
visible_by_administration.archived
when 'expirant'
Expand Down Expand Up @@ -601,7 +596,7 @@ def can_be_deleted_by_administration?(reason)
end

def can_be_deleted_by_automatic?(reason)
reason == :expired
brouillon? || en_construction? || termine? || reason == :expired
end

def can_terminer_automatiquement_by_sva_svr?
Expand Down Expand Up @@ -685,8 +680,8 @@ def extend_conservation(conservation_extension)
en_construction_close_to_expiration_notice_sent_at: nil,
termine_close_to_expiration_notice_sent_at: nil)

if hidden_at.present?
update(hidden_at: nil, hidden_by_reason: nil)
if hidden_by_reason == 'expired'
update(hidden_by_administration_at: nil, hidden_by_user_at: nil, hidden_by_reason: nil)
end
end

Expand Down Expand Up @@ -852,7 +847,7 @@ def hide_and_keep_track!(author, reason)
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)
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)

Check warning on line 850 in app/models/dossier.rb

View check run for this annotation

Codecov / codecov/patch

app/models/dossier.rb#L850

Added line #L850 was not covered by tests
else
raise "Unauthorized dossier hide attempt Dossier##{id} by #{author} for reason #{reason}"
end
Expand Down Expand Up @@ -1098,7 +1093,6 @@ def self.purge_discarded
en_brouillon_expired_to_delete.find_each(&:purge_discarded)
en_construction_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

def skip_user_notification_email?
Expand Down
18 changes: 9 additions & 9 deletions app/models/instructeur.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,19 @@ def flipper_id
def dossiers_count_summary(groupe_instructeur_ids)
query = <<~EOF
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 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 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 dossiers.hidden_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 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 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 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.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 ('accepte', 'refuse', 'sans_suite')) AS traites,
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 archived) AS archives,
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 procedures.procedure_expires_when_termine_enabled
AND (
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
) 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
)
) AS expirant
Expand All @@ -252,7 +253,6 @@ def dossiers_count_summary(groupe_instructeur_ids)
AND follows.unfollowed_at IS NULL
WHERE dossiers.state != 'brouillon'
AND dossiers.groupe_instructeur_id in (:groupe_instructeur_ids)
AND (dossiers.hidden_by_user_at IS NULL OR dossiers.state != 'en_construction')
EOF

sanitized_query = ActiveRecord::Base.sanitize_sql([
Expand Down
10 changes: 5 additions & 5 deletions app/services/dossier_projection_service.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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?
return false if corrections.blank?

Expand Down Expand Up @@ -44,14 +44,14 @@ def self.project(dossiers_ids, fields)
batch_operation_field = { TABLE => 'self', COLUMN => 'batch_operation_id' }
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_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' }
individual_first_name = { TABLE => 'individual', COLUMN => 'prenom' }
individual_last_name = { TABLE => 'individual', COLUMN => 'nom' }
sva_svr_decision_on_field = { TABLE => 'self', COLUMN => 'sva_svr_decision_on' }
dossier_corrections = { TABLE => 'dossier_corrections', COLUMN => 'resolved_at' }
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] = {} }
.group_by { |f| f[TABLE] } # one query per table
.each do |table, fields|
Expand All @@ -74,7 +74,7 @@ def self.project(dossiers_ids, fields)
.pluck(:id, *fields.map { |f| f[COLUMN].to_sym })
.each do |id, *columns|
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
else
field[:id_value_h][id] = value&.strftime('%d/%m/%Y') # other fields are datetime
Expand Down Expand Up @@ -151,7 +151,7 @@ def self.project(dossiers_ids, fields)
archived_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_at_field[:id_value_h][dossier_id],
hidden_by_reason_field[:id_value_h][dossier_id],
for_tiers_field[:id_value_h][dossier_id],
individual_first_name[:id_value_h][dossier_id],
individual_last_name[:id_value_h][dossier_id],
Expand Down
2 changes: 1 addition & 1 deletion app/views/instructeurs/dossiers/_header_actions.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
dossier_is_followed: current_instructeur&.follow?(dossier),
close_to_expiration: dossier.close_to_expiration?,
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_blocking_pending_correction: dossier.procedure.feature_enabled?(:blocking_pending_correction) && dossier.pending_correction?,
turbo: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- if hidden_by_administration && hidden_at
- if hidden_by_administration && hidden_by_expired
%li
= 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')
Expand Down
7 changes: 4 additions & 3 deletions app/views/instructeurs/procedures/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,12 @@
- if p.hidden_by_administration_at.present?
%span.cell-link
= 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
%a.cell-link{ href: path }
= 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
- status = [status_badge(p.state)]
Expand All @@ -178,7 +179,7 @@
dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id),
close_to_expiration: @statut == 'expirant',
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?,
has_blocking_pending_correction: @procedure.feature_enabled?(:blocking_pending_correction) && p.pending_correction?,
turbo: false,
Expand Down
2 changes: 1 addition & 1 deletion app/views/recherche/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id),
close_to_expiration: nil,
hidden_by_administration: nil,
hidden_at: nil,
hidden_by_expired: nil,
sva_svr: p.sva_svr_decision_on.present?,
has_blocking_pending_correction: p.pending_correction? && Flipper.enabled?(:blocking_pending_correction, ProcedureFlipperActor.new(procedure_id)),
turbo: false,
Expand Down
10 changes: 5 additions & 5 deletions app/views/users/dossiers/_dossiers_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
%p.fr-icon--sm.fr-icon-user-line
= 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_user', date: l(dossier.hidden_by_user_at.to_date))
- elsif dossier.hidden_at?
= 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
= t('views.users.dossiers.dossiers_list.deleted_by_automatic', date: l(dossier.hidden_at.to_date))
= t('views.users.dossiers.dossiers_list.deleted_by_user', date: l(dossier.hidden_by_user_at.to_date))
- else
%p.fr-icon--sm.fr-icon-edit-box-line
- if dossier.depose_at.present?
Expand Down Expand Up @@ -108,7 +108,7 @@

- if @statut == "dossiers-supprimes-recemment"
.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
Restaurer

Expand Down
1 change: 0 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ en:
expirant: Records will not expire prior to the data retention period.
archived_dossier: "This file will be kept for an additional month"
delete_dossier: "Delete file"
deleted_by_user: "File deleted by user"
acts_on_behalf: "acts for"
deleted_by_administration: "File deleted by administration"
restore: "Restore"
Expand Down
Loading

0 comments on commit ff5bf79

Please sign in to comment.