+ <%= t('views.users.dossiers.transfers.sender_demande_en_cours_from_support', id: dossier.id, email: dossier.transfer.email) %>
+
+ <%= link_to t('views.users.dossiers.transfers.revoke'), transfer_destroy_manager_dossier_path(dossier), class: 'fr-link', method: :delete %>
+
-
<% page.attributes.each do |attribute| %>
-
diff --git a/app/views/manager/dossiers/transfer_edit.html.erb b/app/views/manager/dossiers/transfer_edit.html.erb
new file mode 100644
index 000000000..bf2216774
--- /dev/null
+++ b/app/views/manager/dossiers/transfer_edit.html.erb
@@ -0,0 +1,46 @@
+<% content_for(:title) { "Transfert d'un dossier vers un autre utilisateur" } %>
+
+
+ + ++ <%= content_for(:title) %> +
+ ++ +-
+
- User + +
- + <%= link_to @dossier.user.email, manager_user_path(@dossier.user) %> + + +
- Text summary + +
- + <%= @dossier.text_summary %> + + +
- State + +
- + <%= dossier_display_state(@dossier) %> + +
+ <%= form_for([namespace, DossierTransfer.new], method: :post, url: transfer_manager_dossier_path(@dossier), html: { class: "form" }) do |f| %> + diff --git a/app/views/users/dossiers/_dossiers_list.html.haml b/app/views/users/dossiers/_dossiers_list.html.haml index d8914eb39..ed0714761 100644 --- a/app/views/users/dossiers/_dossiers_list.html.haml +++ b/app/views/users/dossiers/_dossiers_list.html.haml @@ -68,7 +68,10 @@ = render Dsfr::AlertComponent.new(state: :info, size: :sm) do |c| - c.body do %p - = t('views.users.dossiers.transfers.receiver_demande_en_cours', id: dossier.id, email: dossier.user.email) + - if dossier.transfer.from_support? + = t('views.users.dossiers.transfers.receiver_demande_en_cours_from_support', id: dossier.id, email: dossier.user.email) + - else + = t('views.users.dossiers.transfers.receiver_demande_en_cours', id: dossier.id, email: dossier.user.email) %p = link_to t('views.users.dossiers.transfers.accept'), transfer_path(dossier.transfer), class: "fr-link fr-mr-1w", method: :put = link_to t('views.users.dossiers.transfers.reject'), transfer_path(dossier.transfer), class: "fr-link", method: :delete @@ -76,7 +79,10 @@ = render Dsfr::AlertComponent.new(state: :info, size: :sm, extra_class_names: "fr-mb-2w") do |c| - c.body do %p - = t('views.users.dossiers.transfers.sender_demande_en_cours', id: dossier.id, email: dossier.transfer.email) + - if dossier.transfer.from_support? + = t('views.users.dossiers.transfers.sender_demande_en_cours_from_support', id: dossier.id, email: dossier.transfer.email) + - else + = t('views.users.dossiers.transfers.sender_demande_en_cours', id: dossier.id, email: dossier.transfer.email) %p = link_to t('views.users.dossiers.transfers.revoke'), transfer_path(dossier.transfer), class: 'fr-link', method: :delete diff --git a/config/locales/en.yml b/config/locales/en.yml index 65fafcd71..6d2f2c8bc 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -479,7 +479,9 @@ en: deleted_badge: Deleted transfers: sender_demande_en_cours: "A transfer request is pending on file Nº %{id} to %{email}" + sender_demande_en_cours: "A transfer request from technical support is pending on file Nº %{id} to %{email}" receiver_demande_en_cours: "Transfer request on file Nº %{id} sent by %{email}" + receiver_demande_en_cours_from_support: "Transfer request from technical support on file Nº %{id} of %{email}" revoke: Revoke this request accept: Accept reject: Reject diff --git a/config/locales/fr.yml b/config/locales/fr.yml index fd974f64e..69138e7f4 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -493,7 +493,9 @@ fr: other_actions: "Autres actions" transfers: sender_demande_en_cours: "Une demande de transfert est en cours sur le dossier Nº %{id} pour %{email}" + sender_demande_en_cours_from_support: "Une demande de transfert par le support technique est en cours sur le dossier Nº %{id} pour %{email}" receiver_demande_en_cours: "Demande de transfert pour le dossier Nº %{id} envoyé par %{email}" + receiver_demande_en_cours_from_support: "Demande de transfert par le support technique pour le dossier Nº %{id} de %{email}" revoke: Révoquer cette demande accept: Accepter reject: Rejeter diff --git a/config/routes.rb b/config/routes.rb index 4aceb9f48..aaa75f6ac 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -71,7 +71,11 @@ Rails.application.routes.draw do end end - resources :dossiers, only: [:show] + resources :dossiers, only: [:show] do + get 'transfer_edit', on: :member + post 'transfer', on: :member + delete 'transfer_destroy', on: :member + end resources :bill_signatures, only: [:index] diff --git a/db/migrate/20231127102633_add_from_support_to_dossier_transfers.rb b/db/migrate/20231127102633_add_from_support_to_dossier_transfers.rb new file mode 100644 index 000000000..4fa6bedca --- /dev/null +++ b/db/migrate/20231127102633_add_from_support_to_dossier_transfers.rb @@ -0,0 +1,5 @@ +class AddFromSupportToDossierTransfers < ActiveRecord::Migration[7.0] + def change + add_column :dossier_transfers, :from_support, :boolean, default: false, null: false + end +end diff --git a/db/migrate/20231128071043_add_from_support_to_dossier_transfer_logs.rb b/db/migrate/20231128071043_add_from_support_to_dossier_transfer_logs.rb new file mode 100644 index 000000000..f782c17df --- /dev/null +++ b/db/migrate/20231128071043_add_from_support_to_dossier_transfer_logs.rb @@ -0,0 +1,5 @@ +class AddFromSupportToDossierTransferLogs < ActiveRecord::Migration[7.0] + def change + add_column :dossier_transfer_logs, :from_support, :boolean, default: false, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index fd9d97f2c..a1fd0361d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_11_14_113317) do +ActiveRecord::Schema[7.0].define(version: 2023_11_28_071043) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -386,6 +386,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_11_14_113317) do t.datetime "created_at", null: false t.bigint "dossier_id", null: false t.string "from", null: false + t.boolean "from_support", default: false, null: false t.string "to", null: false t.datetime "updated_at", null: false t.index ["dossier_id"], name: "index_dossier_transfer_logs_on_dossier_id" @@ -395,6 +396,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_11_14_113317) do t.datetime "created_at", null: false t.string "email", null: false t.datetime "updated_at", null: false + t.boolean "from_support", default: false, null: false t.index ["email"], name: "index_dossier_transfers_on_email" end diff --git a/spec/controllers/manager/dossiers_controller_spec.rb b/spec/controllers/manager/dossiers_controller_spec.rb index 3bff00e01..4b83eee33 100644 --- a/spec/controllers/manager/dossiers_controller_spec.rb +++ b/spec/controllers/manager/dossiers_controller_spec.rb @@ -34,4 +34,35 @@ describe Manager::DossiersController, type: :controller do it { expect(subject).to match(%r{Nom\s+\*\s+Texte court\s+🟢\s+rempli}) } end + + describe "POST #transfer" do + before do + allow(DossierMailer).to receive(:notify_transfer).and_call_original + post :transfer, params: { id: @dossier.id, email: } + end + + context 'with valid email' do + let(:email) { "chouette.gars@laposte.net" } + + it { expect(flash[:success]).to eq("Une invitation de transfert a été envoyée à chouette.gars@laposte.net") } + it { expect(DossierMailer).to have_received(:notify_transfer) } + end + + context 'with invalid email' do + let(:email) { "chouette" } + + it { expect(flash[:alert]).to eq("L’adresse email est invalide") } + it { expect(DossierMailer).not_to have_received(:notify_transfer) } + end + end + + describe "DELETE #transfer_destroy" do + before do + DossierTransfer.create(email: 'coucou@laposte.net', dossiers: [@dossier]) + delete :transfer_destroy, params: { id: @dossier.id } + end + + it { expect(@dossier.transfer).to be_nil } + it { expect(flash[:notice]).to eq "La demande de transfert a été supprimée avec succès" } + end end+++ +++ ++ ++ <%= f.submit "Transférer le dossier" %> ++ <% end %> +