Skip to content

Commit

Permalink
create a method to extend and restore
Browse files Browse the repository at this point in the history
  • Loading branch information
lisa-durand committed Jul 23, 2024
1 parent 5a4faed commit cb51ac0
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 16 deletions.
6 changes: 5 additions & 1 deletion app/controllers/instructeurs/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ class DossiersController < ProceduresController
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',
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/users/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,15 @@ def submit_brouillon
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
Expand Down
2 changes: 1 addition & 1 deletion app/models/batch_operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def process_one(dossier)
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)
Expand Down
11 changes: 6 additions & 5 deletions app/models/dossier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -686,16 +686,17 @@ def expiration_can_be_extended?
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?
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/dossiers/_dossiers_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
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"
Expand Down Expand Up @@ -489,6 +490,7 @@
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'
Expand Down
12 changes: 6 additions & 6 deletions spec/models/dossier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@

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
Expand Down Expand Up @@ -158,8 +158,8 @@

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
Expand Down Expand Up @@ -218,8 +218,8 @@

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
Expand Down

0 comments on commit cb51ac0

Please sign in to comment.