diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index ebbd20585..5dc1517bb 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -329,6 +329,15 @@ module Users redirect_to dossiers_path end + def clone + cloned_dossier = @dossier.clone + flash.notice = t('users.dossiers.cloned_success') + redirect_to brouillon_dossier_path(cloned_dossier) + rescue ActiveRecord::ActiveRecordError => e + flash.alert = e.errors.full_messages + redirect_to dossier_path(@dossier) + end + private # if the status tab is filled, then this tab diff --git a/app/views/instructeurs/procedures/_dossier_actions.html.haml b/app/views/instructeurs/procedures/_dossier_actions.html.haml index 68765a6e6..61500bb6c 100644 --- a/app/views/instructeurs/procedures/_dossier_actions.html.haml +++ b/app/views/instructeurs/procedures/_dossier_actions.html.haml @@ -24,7 +24,6 @@ %span.icon.archive .dropdown-description Archiver le dossier - %li.danger = link_to instructeur_dossier_path(procedure_id, dossier_id), method: :delete do %span.icon.delete diff --git a/app/views/users/dossiers/_dossier_actions.html.haml b/app/views/users/dossiers/_dossier_actions.html.haml index 0f8b92326..b678cf8a9 100644 --- a/app/views/users/dossiers/_dossier_actions.html.haml +++ b/app/views/users/dossiers/_dossier_actions.html.haml @@ -37,6 +37,11 @@ %span.icon.new-folder .dropdown-description = t('views.users.dossiers.dossier_action.start_other_dossier') + %li + = link_to clone_dossier_path(dossier), method: :post do + %span.icon.new-folder + .dropdown-description + = t('views.users.dossiers.dossier_action.clone') - if has_delete_action %li.danger diff --git a/config/locales/en.yml b/config/locales/en.yml index 6ca5e5189..27a5ff473 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -249,7 +249,8 @@ en: actions: "Actions" dossier_action: edit_dossier: "Edit the file" - start_other_dossier: "Start an other file" + start_other_dossier: "Start an other empty file" + clone: "Clone this file" delete_dossier: "Delete the file" transfer_dossier: "Transfer the file" edit_draft: "Edit the draft" @@ -442,6 +443,7 @@ en: no_longer_editable: "Your file can no longer be edited" create_commentaire: message_send: "Your message has been sent to the instructor in charge of your file." + cloned_success: "Your file has been duplicated. Please review it then you can submit it" ask_deletion: undergoingreview: "Your file is undergoing review. It is no longer possible to delete your file. To cancel the undergoingreview contact the adminitration via the mailbox." soft_deleted_dossier: "Your file has been successfully deleted from your interface" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 6e5fa52a7..5cf68656c 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -245,7 +245,8 @@ fr: actions: "Actions" dossier_action: edit_dossier: "Modifier le dossier" - start_other_dossier: "Commencer un autre dossier" + start_other_dossier: "Commencer un autre dossier vide" + clone: "Dupliquer ce dossier" delete_dossier: "Supprimer le dossier" transfer_dossier: "Transferer le dossier" edit_draft: "Modifier le brouillon" @@ -450,9 +451,9 @@ fr: test_procedure: "Ce dossier est déposé sur une démarche en test. Toute modification de la démarche par l’administrateur (ajout d'un champ, publication de la démarche...) entraînera sa suppression." no_access: "Vous n’avez pas accès à ce dossier" no_longer_editable: "Votre dossier ne peut plus être modifié" - create_commentaire: message_send: "Votre message a bien été envoyé à l’instructeur en charge de votre dossier." + cloned_success: "Votre dossier a bien été dupliqué. Vous pouvez maintenant le vérifier, l’adapter puis le déposer." ask_deletion: undergoingreview: "L’instruction de votre dossier a commencé, il n’est plus possible de supprimer votre dossier. Si vous souhaitez annuler l’instruction contactez votre administration par la messagerie de votre dossier." soft_deleted_dossier: "Votre dossier a bien été supprimé de votre interface" diff --git a/config/routes.rb b/config/routes.rb index 3d38ba0a9..af179b328 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -275,6 +275,7 @@ Rails.application.routes.draw do member do get 'identite' patch 'update_identite' + post 'clone' get 'siret' post 'siret', to: 'dossiers#update_siret' get 'etablissement' diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 0e2b38c2f..a458f4d1f 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -1185,4 +1185,21 @@ describe Users::DossiersController, type: :controller do end end end + + describe '#clone' do + let(:procedure) { create(:procedure, :with_all_champs) } + let(:dossier) { create(:dossier, procedure: procedure) } + subject { post :clone, params: { id: dossier.id } } + + context 'not signed in' do + it { expect(subject).to redirect_to(new_user_session_path) } + end + + context 'signed with user dossier' do + before { sign_in dossier.user } + + it { expect(subject).to redirect_to(brouillon_dossier_path(Dossier.last)) } + it { expect { subject }.to change { dossier.user.dossiers.count }.by(1) } + end + end end diff --git a/spec/system/users/list_dossiers_spec.rb b/spec/system/users/list_dossiers_spec.rb index 843423c81..a0335f096 100644 --- a/spec/system/users/list_dossiers_spec.rb +++ b/spec/system/users/list_dossiers_spec.rb @@ -80,6 +80,25 @@ describe 'user access to the list of their dossiers', js: true do expect(page).not_to have_content(dossier_brouillon.procedure.libelle) end end + + describe 'clone' do + it 'should have links to clone dossiers' do + expect(page).to have_link(nil, href: clone_dossier_path(dossier_brouillon)) + expect(page).to have_link(nil, href: clone_dossier_path(dossier_en_construction)) + expect(page).to have_link(nil, href: clone_dossier_path(dossier_en_instruction)) + end + + context 'when user clicks on clone button', js: true do + scenario 'the dossier is deleted' do + within(:css, "tr[data-dossier-id=\"#{dossier_brouillon.id}\"]") do + click_on 'Actions' + click_on 'Dupliquer ce dossier' + end + + expect(page).to have_content("Votre dossier a bien été dupliqué. Vous pouvez maintenant le vérifier, l’adapter puis le déposer.") + end + end + end end describe "recherche" do