add correct action for instructeur

This commit is contained in:
Lisa Durand 2024-06-11 15:54:54 +02:00
parent c2abceaa72
commit 8b88fafc25
No known key found for this signature in database
GPG key ID: 0DF91F2CA1E8B816
9 changed files with 37 additions and 4 deletions

View file

@ -376,6 +376,10 @@ module Instructeurs
Dossier Dossier
.where(id: current_instructeur.dossiers.visible_by_administration) .where(id: current_instructeur.dossiers.visible_by_administration)
.or(Dossier.where(id: current_user.dossiers.for_procedure_preview)) .or(Dossier.where(id: current_user.dossiers.for_procedure_preview))
elsif action_name == 'extend_conservation'
Dossier
.where(id: current_instructeur.dossiers.visible_by_administration)
.or(Dossier.where(id: current_instructeur.dossiers.hidden_by_automatic))
else else
current_instructeur.dossiers.visible_by_administration current_instructeur.dossiers.visible_by_administration
end end

View file

@ -689,6 +689,10 @@ class Dossier < ApplicationRecord
brouillon_close_to_expiration_notice_sent_at: nil, brouillon_close_to_expiration_notice_sent_at: nil,
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?
update(hidden_at: nil, hidden_by_reason: nil)
end
end end
def show_procedure_state_warning? def show_procedure_state_warning?

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, :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_at, :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,13 +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' }
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, for_tiers_field, individual_first_name, individual_last_name, batch_operation_field, dossier_corrections] + fields) # the view needs state and archived dossier attributes ([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)
.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|
@ -73,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, 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_at_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
@ -150,6 +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],
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,6 +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?,
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,7 +1,13 @@
- if hidden_by_administration - if hidden_by_administration && hidden_at
%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')
- elsif hidden_by_administration
%li %li
= button_to restore_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: "fr-btn fr-icon-refresh-line" do = button_to restore_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: "fr-btn fr-icon-refresh-line" do
= t('views.instructeurs.dossiers.restore') = t('views.instructeurs.dossiers.restore')
- elsif close_to_expiration || Dossier::TERMINE.include?(state) - elsif close_to_expiration || Dossier::TERMINE.include?(state)
%li %li
- if close_to_expiration - if close_to_expiration

View file

@ -172,6 +172,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?,
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,6 +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,
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

@ -409,6 +409,7 @@ fr:
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"
restore_and_extend: "Restaurer et étendre la conservation"
filters: filters:
title: Sélectionner un filtre title: Sélectionner un filtre
select_all: Tout selectionner select_all: Tout selectionner

View file

@ -1307,6 +1307,19 @@ describe Instructeurs::DossiersController, type: :controller do
end end
end end
describe '#extend_conservation and restore' do
before do
dossier.update(hidden_at: 1.hour.ago, hidden_by_reason: 'expired')
end
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
subject
expect(dossier.reload.hidden_at).to eq(nil)
expect(dossier.reload.conservation_extension).to eq(1.month)
end
end
describe '#reaffectation' do describe '#reaffectation' do
let!(:gi_2) { GroupeInstructeur.create(label: 'deuxième groupe', procedure: procedure) } let!(:gi_2) { GroupeInstructeur.create(label: 'deuxième groupe', procedure: procedure) }
let!(:gi_3) { GroupeInstructeur.create(label: 'troisième groupe', procedure: procedure) } let!(:gi_3) { GroupeInstructeur.create(label: 'troisième groupe', procedure: procedure) }