From 37e991ccb8f924148d299e1b8f42b0bc715b6e5d Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Tue, 7 Dec 2021 15:38:37 +0100 Subject: [PATCH] User : delete the folder if the instructeur has hide it --- app/controllers/users/dossiers_controller.rb | 16 ++++------------ app/models/dossier.rb | 2 +- .../users/dossiers/_dossier_actions.html.haml | 11 ++--------- config/routes.rb | 3 +-- 4 files changed, 8 insertions(+), 24 deletions(-) diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index e6e377969..ecad8100c 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -212,16 +212,15 @@ module Users end end - def ask_deletion + def delete_dossier dossier = current_user.dossiers.includes(:user, procedure: :administrateurs).find(params[:id]) - if dossier.can_be_deleted_by_user? dossier.discard_and_keep_track!(current_user, :user_request) - flash.notice = t('.soft_deleted_dossier') + flash.notice = t('users.dossiers.ask_deletion.soft_deleted_dossier') redirect_to dossiers_path else - flash.notice = t('.undergoingreview') - redirect_to dossier_path(dossier) + flash.alert = t('users.dossiers.ask_deletion.undergoingreview') + redirect_to dossiers_path end end @@ -288,13 +287,6 @@ module Users @transfer = DossierTransfer.new(dossiers: current_user.dossiers) end - def hide_dossier - dossier = current_user.dossiers.includes(:user, procedure: :administrateurs).find(params[:id]) - dossier.update(hidden_by_user_at: Time.zone.now) - flash.notice = t('users.dossiers.ask_deletion.soft_deleted_dossier') - redirect_to dossiers_path - end - private # if the status tab is filled, then this tab diff --git a/app/models/dossier.rb b/app/models/dossier.rb index a7200dc5c..27ed1c626 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -526,7 +526,7 @@ class Dossier < ApplicationRecord end def can_be_deleted_by_user? - brouillon? || en_construction? + brouillon? || en_construction? || termine? end def can_be_deleted_by_manager? diff --git a/app/views/users/dossiers/_dossier_actions.html.haml b/app/views/users/dossiers/_dossier_actions.html.haml index 6e510222d..b59b203ae 100644 --- a/app/views/users/dossiers/_dossier_actions.html.haml +++ b/app/views/users/dossiers/_dossier_actions.html.haml @@ -2,8 +2,7 @@ - has_delete_action = dossier.can_be_deleted_by_user? - has_new_dossier_action = dossier.procedure.accepts_new_dossiers? - has_transfer_action = dossier.user == current_user -- has_hide_action = dossier.termine? && dossier.hidden_by_user_at.nil? -- has_actions = has_edit_action || has_delete_action || has_new_dossier_action || has_transfer_action || has_hide_action +- has_actions = has_edit_action || has_delete_action || has_new_dossier_action || has_transfer_action - if has_actions .dropdown.user-dossier-actions @@ -41,14 +40,8 @@ - if has_delete_action %li.danger - = link_to ask_deletion_dossier_path(dossier), method: :post, data: { disable: true, confirm: "En continuant, vous allez supprimer ce dossier ainsi que les informations qu’il contient. Toute suppression entraîne l’annulation de la démarche en cours.\n\nConfirmer la suppression ?" } do + = link_to delete_dossier_dossier_path(dossier), method: :patch, data: { disable: true, confirm: "En continuant, vous allez supprimer ce dossier ainsi que les informations qu’il contient. Toute suppression entraîne l’annulation de la démarche en cours.\n\nConfirmer la suppression ?" } do %span.icon.delete .dropdown-description = t('views.users.dossiers.dossier_action.delete_dossier') - - if has_hide_action - %li - = link_to hide_dossier_dossier_path(dossier), method: :patch do - %span.icon.delete - .dropdown-description - = t('views.users.dossiers.dossier_action.hide_dossier') diff --git a/config/routes.rb b/config/routes.rb index 4f13636ff..ddde58659 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -268,8 +268,7 @@ Rails.application.routes.draw do get 'demande' get 'messagerie' post 'commentaire' => 'dossiers#create_commentaire' - post 'ask_deletion' - patch 'hide_dossier' + patch 'delete_dossier' get 'attestation' get 'transferer', to: 'dossiers#transferer' end