create a method to extend and restore

This commit is contained in:
Lisa Durand 2024-07-23 15:06:23 +02:00
parent ae1a6e1b3d
commit b820577461
No known key found for this signature in database
GPG key ID: 0DF91F2CA1E8B816
8 changed files with 27 additions and 16 deletions

View file

@ -18,11 +18,15 @@ module Instructeurs
after_action :mark_annotations_privees_as_read, only: [:annotations_privees, :update_annotations]
def extend_conservation
dossier.extend_conservation(1.month, current_instructeur)
dossier.extend_conservation(1.month)
flash[:notice] = t('views.instructeurs.dossiers.archived_dossier')
redirect_back(fallback_location: instructeur_dossier_path(@dossier.procedure, @dossier))
end
def extend_conservation_and_restore
dossier.extend_conservation_and_restore(1.month, current_instructeur)
end
def geo_data
send_data dossier.to_feature_collection.to_json,
type: 'application/json',

View file

@ -254,11 +254,15 @@ module Users
end
def extend_conservation
dossier.extend_conservation(dossier.procedure.duree_conservation_dossiers_dans_ds.months, current_user)
dossier.extend_conservation(dossier.procedure.duree_conservation_dossiers_dans_ds.months)
flash[:notice] = t('views.users.dossiers.archived_dossier', duree_conservation_dossiers_dans_ds: dossier.procedure.duree_conservation_dossiers_dans_ds)
redirect_back(fallback_location: dossier_path(@dossier))
end
def extend_conservation_and_restore
dossier.extend_conservation_and_restore(conservation_extension, author)
end
def modifier
@dossier = dossier_with_champs
end

View file

@ -92,7 +92,7 @@ class BatchOperation < ApplicationRecord
when BatchOperation.operations.fetch(:follow)
instructeur.follow(dossier)
when BatchOperation.operations.fetch(:repousser_expiration)
dossier.extend_conservation(1.month, instructeur)
dossier.extend_conservation(1.month)
when BatchOperation.operations.fetch(:repasser_en_construction)
dossier.repasser_en_construction!(instructeur: instructeur)
when BatchOperation.operations.fetch(:unfollow)

View file

@ -681,16 +681,17 @@ class Dossier < ApplicationRecord
brouillon? || en_construction?
end
def extend_conservation(conservation_extension, author)
def extend_conservation(conservation_extension)
update(conservation_extension: self.conservation_extension + conservation_extension,
brouillon_close_to_expiration_notice_sent_at: nil,
en_construction_close_to_expiration_notice_sent_at: nil,
termine_close_to_expiration_notice_sent_at: nil)
end
if hidden_by_expired?
update(hidden_by_expired_at: nil, hidden_by_reason: nil)
restore(author)
end
def extend_conservation_and_restore(conservation_extension, author)
extend_conservation(conservation_extension)
update(hidden_by_expired_at: nil, hidden_by_reason: nil)
restore(current_user)
end
def show_procedure_state_warning?

View file

@ -1,6 +1,6 @@
- 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
= button_to repousser_expiration_and_restore_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

View file

@ -108,7 +108,7 @@
- else
- if dossier.expiration_can_be_extended?
= button_to users_dossier_repousser_expiration_path(dossier), class: 'fr-btn fr-btn--sm' do
= button_to users_dossier_extend_conservation_and_restore_path(dossier), class: 'fr-btn fr-btn--sm' do
Restaurer et étendre la conservation

View file

@ -268,6 +268,7 @@ Rails.application.routes.draw do
get '/carte' => 'carte#show'
post '/carte' => 'carte#save'
post '/repousser-expiration' => 'dossiers#extend_conservation'
post '/repousser-expiration-and-restore' => 'dossiers#extend_conservation_and_restore'
end
# Redirection of legacy "/users/dossiers" route to "/dossiers"
@ -489,6 +490,7 @@ Rails.application.routes.draw do
member do
resources :commentaires, only: [:destroy]
post 'repousser-expiration' => 'dossiers#extend_conservation'
post 'repousser-expiration-and-restore' => 'dossiers#extend_conservation_and_restore'
get 'geo_data'
get 'apercu_attestation'
get 'bilans_bdf'

View file

@ -107,8 +107,8 @@ describe Dossier, type: :model do
context 'does not include an expiring dossier that has been postponed' do
before do
expiring_dossier.extend_conservation(1.month, user)
expiring_dossier_with_notification.extend_conservation(1.month, user)
expiring_dossier.extend_conservation(1.month)
expiring_dossier_with_notification.extend_conservation(1.month)
expiring_dossier.reload
expiring_dossier_with_notification.reload
end
@ -158,8 +158,8 @@ describe Dossier, type: :model do
context 'does not include an expiring dossier that has been postponed' do
before do
expiring_dossier.extend_conservation(1.month, user)
expiring_dossier_with_notification.extend_conservation(1.month, user)
expiring_dossier.extend_conservation(1.month)
expiring_dossier_with_notification.extend_conservation(1.month)
expiring_dossier.reload
expiring_dossier_with_notification.reload
end
@ -218,8 +218,8 @@ describe Dossier, type: :model do
context 'does not include an expiring dossier that has been postponed' do
before do
expiring_dossier.extend_conservation(1.month, user)
expiring_dossier_with_notification.extend_conservation(1.month, user)
expiring_dossier.extend_conservation(1.month)
expiring_dossier_with_notification.extend_conservation(1.month)
expiring_dossier.reload
expiring_dossier_with_notification.reload
end