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:
commit
246d53fa99
12 changed files with 145 additions and 4 deletions
|
@ -16,6 +16,27 @@ module Manager
|
||||||
end
|
end
|
||||||
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
|
private
|
||||||
|
|
||||||
def unfiltered_list?
|
def unfiltered_list?
|
||||||
|
|
|
@ -29,6 +29,7 @@ class DossierTransfer < ApplicationRecord
|
||||||
{
|
{
|
||||||
dossier: dossier,
|
dossier: dossier,
|
||||||
from: dossier.user.email,
|
from: dossier.user.email,
|
||||||
|
from_support: transfer.from_support,
|
||||||
to: transfer.email
|
to: transfer.email
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -26,9 +26,25 @@ as well as a link to its edit page.
|
||||||
(Supprimé)
|
(Supprimé)
|
||||||
<% end %>
|
<% end %>
|
||||||
</h1>
|
</h1>
|
||||||
|
<div>
|
||||||
|
<%= link_to(
|
||||||
|
"Transférer le dossier",
|
||||||
|
[:transfer_edit, namespace, page.resource],
|
||||||
|
class: "button",
|
||||||
|
) if valid_action? :transfer_edit %>
|
||||||
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<section class="main-content__body">
|
<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>
|
<dl>
|
||||||
<% page.attributes.each do |attribute| %>
|
<% page.attributes.each do |attribute| %>
|
||||||
<dt class="attribute-label" id="<%= attribute.name %>">
|
<dt class="attribute-label" id="<%= attribute.name %>">
|
||||||
|
|
46
app/views/manager/dossiers/transfer_edit.html.erb
Normal file
46
app/views/manager/dossiers/transfer_edit.html.erb
Normal 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>
|
|
@ -68,6 +68,9 @@
|
||||||
= render Dsfr::AlertComponent.new(state: :info, size: :sm) do |c|
|
= render Dsfr::AlertComponent.new(state: :info, size: :sm) do |c|
|
||||||
- c.body do
|
- c.body do
|
||||||
%p
|
%p
|
||||||
|
- 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)
|
= t('views.users.dossiers.transfers.receiver_demande_en_cours', id: dossier.id, email: dossier.user.email)
|
||||||
%p
|
%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.accept'), transfer_path(dossier.transfer), class: "fr-link fr-mr-1w", method: :put
|
||||||
|
@ -76,6 +79,9 @@
|
||||||
= render Dsfr::AlertComponent.new(state: :info, size: :sm, extra_class_names: "fr-mb-2w") do |c|
|
= render Dsfr::AlertComponent.new(state: :info, size: :sm, extra_class_names: "fr-mb-2w") do |c|
|
||||||
- c.body do
|
- c.body do
|
||||||
%p
|
%p
|
||||||
|
- 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)
|
= t('views.users.dossiers.transfers.sender_demande_en_cours', id: dossier.id, email: dossier.transfer.email)
|
||||||
%p
|
%p
|
||||||
= link_to t('views.users.dossiers.transfers.revoke'), transfer_path(dossier.transfer), class: 'fr-link', method: :delete
|
= link_to t('views.users.dossiers.transfers.revoke'), transfer_path(dossier.transfer), class: 'fr-link', method: :delete
|
||||||
|
|
|
@ -479,7 +479,9 @@ en:
|
||||||
deleted_badge: Deleted
|
deleted_badge: Deleted
|
||||||
transfers:
|
transfers:
|
||||||
sender_demande_en_cours: "A transfer request is pending on file Nº %{id} to %{email}"
|
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: "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
|
revoke: Revoke this request
|
||||||
accept: Accept
|
accept: Accept
|
||||||
reject: Reject
|
reject: Reject
|
||||||
|
|
|
@ -493,7 +493,9 @@ fr:
|
||||||
other_actions: "Autres actions"
|
other_actions: "Autres actions"
|
||||||
transfers:
|
transfers:
|
||||||
sender_demande_en_cours: "Une demande de transfert est en cours sur le dossier Nº %{id} pour %{email}"
|
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: "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
|
revoke: Révoquer cette demande
|
||||||
accept: Accepter
|
accept: Accepter
|
||||||
reject: Rejeter
|
reject: Rejeter
|
||||||
|
|
|
@ -71,7 +71,11 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
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]
|
resources :bill_signatures, only: [:index]
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pgcrypto"
|
enable_extension "pgcrypto"
|
||||||
enable_extension "plpgsql"
|
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.datetime "created_at", null: false
|
||||||
t.bigint "dossier_id", null: false
|
t.bigint "dossier_id", null: false
|
||||||
t.string "from", null: false
|
t.string "from", null: false
|
||||||
|
t.boolean "from_support", default: false, null: false
|
||||||
t.string "to", null: false
|
t.string "to", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.index ["dossier_id"], name: "index_dossier_transfer_logs_on_dossier_id"
|
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.datetime "created_at", null: false
|
||||||
t.string "email", null: false
|
t.string "email", null: false
|
||||||
t.datetime "updated_at", 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"
|
t.index ["email"], name: "index_dossier_transfers_on_email"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -34,4 +34,35 @@ describe Manager::DossiersController, type: :controller do
|
||||||
|
|
||||||
it { expect(subject).to match(%r{Nom\s+\*\s+Texte court\s+🟢\s+rempli}) }
|
it { expect(subject).to match(%r{Nom\s+\*\s+Texte court\s+🟢\s+rempli}) }
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue