Merge pull request #9754 from demarches-simplifiees/9435-transfer-dossier

En tant que superadmin, je peux transférer un dossier d'un utilistateur à un autre
This commit is contained in:
krichtof 2023-12-12 14:44:39 +00:00 committed by GitHub
commit 246d53fa99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 145 additions and 4 deletions

View file

@ -16,6 +16,27 @@ module Manager
end
end
def transfer_edit
@dossier = Dossier.find params[:id]
end
def transfer
transfer = DossierTransfer.create(email: params[:email], dossiers: [Dossier.find(params[:id])], from_support: true)
if transfer.persisted?
flash[:success] = "Une invitation de transfert a été envoyée à #{params[:email]}"
else
flash[:alert] = transfer.errors.full_messages.join("<br>")
end
redirect_to manager_dossier_path(params[:id])
end
def transfer_destroy
dossier = Dossier.find(params[:id])
dossier.transfer.destroy_and_nullify
redirect_to manager_dossier_path(dossier), notice: t("users.dossiers.transferer.destroy")
end
private
def unfiltered_list?

View file

@ -29,6 +29,7 @@ class DossierTransfer < ApplicationRecord
{
dossier: dossier,
from: dossier.user.email,
from_support: transfer.from_support,
to: transfer.email
}
end)

View file

@ -26,9 +26,25 @@ as well as a link to its edit page.
(Supprimé)
<% end %>
</h1>
<div>
<%= link_to(
"Transférer le dossier",
[:transfer_edit, namespace, page.resource],
class: "button",
) if valid_action? :transfer_edit %>
</div>
</header>
<section class="main-content__body">
<div>
<% if dossier.transfer&.from_support %>
<p>
<%= t('views.users.dossiers.transfers.sender_demande_en_cours_from_support', id: dossier.id, email: dossier.transfer.email) %>
<br>
<%= link_to t('views.users.dossiers.transfers.revoke'), transfer_destroy_manager_dossier_path(dossier), class: 'fr-link', method: :delete %>
</p>
<% end %>
</div>
<dl>
<% page.attributes.each do |attribute| %>
<dt class="attribute-label" id="<%= attribute.name %>">

View file

@ -0,0 +1,46 @@
<% content_for(:title) { "Transfert d'un dossier vers un autre utilisateur" } %>
<header class="main-content__header" role="banner">
<h1 class="main-content__page-title">
<%= content_for(:title) %>
</h1>
</header>
<section class="main-content__body">
<dl>
<dt class="attribute-label" id="user">User</dt>
<dd class="attribute-data attribute-data--belongs-to">
<%= link_to @dossier.user.email, manager_user_path(@dossier.user) %>
</dd>
<dt class="attribute-label" id="text_summary">Text summary</dt>
<dd class="attribute-data attribute-data--string">
<%= @dossier.text_summary %>
</dd>
<dt class="attribute-label" id="state">State</dt>
<dd class="attribute-data attribute-data--enum">
<%= dossier_display_state(@dossier) %>
</dd>
</dl>
</section>
<section>
<%= form_for([namespace, DossierTransfer.new], method: :post, url: transfer_manager_dossier_path(@dossier), html: { class: "form" }) do |f| %>
<div class="field-unit field-unit--string field-unit--optional">
<div class="field-unit__label">
<label for="user_email">A qui souhaitez-vous transferer le dossier ?</label>
</div>
<div class="field-unit__field">
<input type="text" name="email" required placeholder="chouette.gars@laposte.net">
</div>
</div>
<div class="form-actions">
<%= f.submit "Transférer le dossier" %>
</div>
<% end %>
</section>

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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]

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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("Ladresse 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