superadmin can transfer dossier from a user to another user
This commit is contained in:
parent
116ba085bf
commit
332570bfba
5 changed files with 93 additions and 1 deletions
|
@ -16,6 +16,21 @@ 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])])
|
||||
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
|
||||
|
||||
private
|
||||
|
||||
def unfiltered_list?
|
||||
|
|
|
@ -26,6 +26,13 @@ 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">
|
||||
|
|
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>
|
|
@ -69,7 +69,10 @@ 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
|
||||
end
|
||||
|
||||
resources :bill_signatures, only: [:index]
|
||||
|
||||
|
|
|
@ -34,4 +34,25 @@ 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
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue