feat(dossier): add dossier transfers UI

This commit is contained in:
Paul Chavard 2021-09-07 10:37:42 +02:00
parent 5985755229
commit 3235f42a63
12 changed files with 135 additions and 8 deletions

View file

@ -4,7 +4,7 @@ module Users
layout 'procedure_context', only: [:identite, :update_identite, :siret, :update_siret]
ACTIONS_ALLOWED_TO_ANY_USER = [:index, :recherche, :new]
ACTIONS_ALLOWED_TO_ANY_USER = [:index, :recherche, :new, :transferer_all]
ACTIONS_ALLOWED_TO_OWNER_OR_INVITE = [:show, :demande, :messagerie, :brouillon, :update_brouillon, :modifier, :update, :create_commentaire]
before_action :ensure_ownership!, except: ACTIONS_ALLOWED_TO_ANY_USER + ACTIONS_ALLOWED_TO_OWNER_OR_INVITE
@ -19,7 +19,12 @@ module Users
@user_dossiers = current_user.dossiers.includes(:procedure).order_by_updated_at.page(page)
@dossiers_invites = current_user.dossiers_invites.includes(:procedure).order_by_updated_at.page(page)
@dossiers_supprimes = current_user.deleted_dossiers.order_by_updated_at.page(page)
@statut = statut(@user_dossiers, @dossiers_invites, @dossiers_supprimes, params[:statut])
@dossier_transfers = DossierTransfer
.includes(dossiers: :user)
.with_dossiers
.where(email: current_user.email)
.page(page)
@statut = statut(@user_dossiers, @dossiers_invites, @dossiers_supprimes, @dossier_transfers, params[:statut])
end
def show
@ -273,16 +278,25 @@ module Users
@dossier || (dossier_id.present? && Dossier.find_by(id: dossier_id.to_i))
end
def transferer
@transfer = DossierTransfer.new(dossiers: [dossier])
end
def transferer_all
@transfer = DossierTransfer.new(dossiers: current_user.dossiers)
end
private
# if the status tab is filled, then this tab
# else first filled tab
# else mes-dossiers
def statut(mes_dossiers, dossiers_invites, dossiers_supprimes, params_statut)
def statut(mes_dossiers, dossiers_invites, dossiers_supprimes, dossier_transfers, params_statut)
tabs = {
'mes-dossiers' => mes_dossiers.present?,
'dossiers-invites' => dossiers_invites.present?,
'dossiers-supprimes' => dossiers_supprimes.present?
'dossiers-supprimes' => dossiers_supprimes.present?,
'dossiers-transferes' => dossier_transfers.present?
}
if tabs[params_statut]
params_statut

View file

@ -0,0 +1,31 @@
module Users
class TransfersController < UserController
def create
transfer = DossierTransfer.new(transfer_params)
transfer.save!
redirect_to dossiers_path
end
def update
DossierTransfer.accept(params[:id], current_user)
redirect_to dossiers_path
end
def destroy
transfer = DossierTransfer.find_by!(id: params[:id], dossiers: { user: current_user })
transfer.destroy
redirect_to dossiers_path
end
private
def transfer_params
transfer_params = params.require(:dossier_transfer).permit(:email, :dossiers)
if transfer_params[:dossiers].present?
transfer_params.merge(dossiers: [current_user.dossiers.find(transfer_params[:dossiers])])
else
transfer_params.merge(dossiers: current_user.dossiers)
end
end
end
end

View file

@ -1,7 +1,8 @@
- has_edit_action = !dossier.read_only?
- has_delete_action = dossier.can_be_deleted_by_user?
- has_new_dossier_action = dossier.procedure.accepts_new_dossiers?
- has_actions = has_delete_action || has_new_dossier_action
- has_transfer_action = dossier.user == current_user
- has_actions = has_edit_action || has_delete_action || has_new_dossier_action || has_transfer_action
- if has_actions
.dropdown.user-dossier-actions
@ -9,7 +10,7 @@
= t('views.users.dossiers.dossier_action.actions')
#actions-menu.dropdown-content.fade-in-down
%ul.dropdown-items
- if !dossier.read_only?
- if has_edit_action
- if dossier.brouillon?
%li
= link_to(url_for_dossier(dossier)) do
@ -23,6 +24,13 @@
.dropdown-description
= t('views.users.dossiers.dossier_action.edit_dossier')
- if has_transfer_action
%li
= link_to transferer_dossier_path(dossier) do
%span.icon.person
.dropdown-description
= t('views.users.dossiers.dossier_action.transfer_dossier')
- if has_new_dossier_action
%li
= link_to procedure_lien(dossier.procedure) do

View file

@ -0,0 +1,32 @@
- if dossier_transfers.present?
%ul.dossiers-transfers.mb-2
- dossier_transfers.each do |transfer|
%li.mb-4
.transfer-details.mb-2
Demande de transfert Nº #{transfer.id} envoyé par #{transfer.dossiers.first.user.email}
%table.table.dossiers-table.hoverable
%thead
%tr
%th.number-col= t('views.users.dossiers.dossiers_list.n_dossier')
%th= t('views.users.dossiers.dossiers_list.procedure')
%th= t('views.users.dossiers.dossiers_list.status')
%th Date de dépot
%tbody
- transfer.dossiers.each do |dossier|
%tr{ data: { 'transfer-id': transfer.id } }
%td.number-col
%span.icon.folder
= dossier.id
%td= dossier.procedure.libelle
%td= status_badge(dossier.state)
%td{ style: 'padding: 18px;' }= (dossier.en_construction_at || dossier.created_at).strftime('%d/%m/%Y')
.transfer-actions.mt-4
= link_to "Accepter", transfer_path(transfer), class: "button primary", method: :put
= link_to "Rejeter", transfer_path(transfer), class: "button danger", method: :delete
= paginate(dossier_transfers)
- else
.blank-tab
%h2.empty-text Aucune demande de transfert de dossiers ne vous a été adressée.

View file

@ -33,6 +33,11 @@
active: @statut == 'dossiers-supprimes',
badge: number_with_html_delimiter(@dossiers_supprimes.count))
- if @dossier_transfers.count > 0
= tab_item(t('pluralize.dossiers_transferes', count: @dossier_transfers.count),
dossiers_path(statut: 'dossiers-transferes'),
active: @statut == 'dossiers-transferes',
badge: number_with_html_delimiter(@dossier_transfers.count))
.container
- if @statut == "mes-dossiers"
@ -43,3 +48,6 @@
- if @statut == "dossiers-supprimes"
= render partial: "deleted_dossiers_list", locals: { deleted_dossiers: @dossiers_supprimes }
- if @statut == "dossiers-transferes"
= render partial: "transfered_dossiers_list", locals: { dossier_transfers: @dossier_transfers }

View file

@ -0,0 +1,9 @@
.container.mt-4
- dossier = @transfer.dossiers.first
Transferer le dossier #{dossier_display_state(dossier.state, lower: true)} nº #{@dossier.id} déposé par #{demandeur_dossier(dossier)} le #{try_format_date(dossier.created_at)} vers le compte dun autre usager :
= form_for @transfer, url: transfers_path, html: { class: 'form mt-2' } do |f|
= f.label :email, 'Email du compte destinataire'
= f.email_field :email
= f.hidden_field :dossiers, value: dossier.id
= f.submit "Envoyer la demande de transfert", class: 'button primary'

View file

@ -0,0 +1,7 @@
.container.mt-4
Transferer les #{@transfer.dossiers.size} dossiers de votre compte vers le compte dun autre usager :
= form_for @transfer, url: transfers_path, html: { class: 'form mt-2' } do |f|
= f.label :email, 'Email du compte destinataire'
= f.email_field :email
= f.submit "Envoyer la demande de transfert", class: 'button primary'

View file

@ -190,6 +190,7 @@ en:
edit_dossier: "Edit the file"
start_other_dossier: "Start an other file"
delete_dossier: "Delete the file"
transfer_dossier: "Transfer the file"
edit_draft: "Edit the draft"
actions: "Actions"
sessions:
@ -328,6 +329,10 @@ en:
zero: deleted file
one: deleted file
other: deleted files
dossiers_transferes:
zero: transfer request
one: transfer request
other: transfer requests
dossier_trouve:
zero: 0 file found
one: 1 file found

View file

@ -182,6 +182,7 @@ fr:
edit_dossier: "Modifier le dossier"
start_other_dossier: "Commencer un autre dossier"
delete_dossier: "Supprimer le dossier"
transfer_dossier: "Transferer le dossier"
edit_draft: "Modifier le brouillon"
actions: "Actions"
sessions:
@ -332,6 +333,10 @@ fr:
zero: dossier supprimé
one: dossier supprimé
other: dossiers supprimés
dossiers_transferes:
zero: demande de transfert
one: demande de transfert
other: demandes de transfert
dossier_trouve:
zero: 0 dossier trouvé
one: 1 dossier trouvé

View file

@ -264,12 +264,16 @@ Rails.application.routes.draw do
post 'commentaire' => 'dossiers#create_commentaire'
post 'ask_deletion'
get 'attestation'
get 'transferer', to: 'dossiers#transferer'
end
collection do
get 'transferer', to: 'dossiers#transferer_all'
get 'recherche'
resources :transfers, only: [:create, :update, :destroy]
end
end
resource :feedback, only: [:create]
get 'demarches' => 'demarches#index'

View file

@ -1,11 +1,13 @@
describe 'users/dossiers/dossier_actions.html.haml', type: :view do
let(:procedure) { create(:procedure, :published) }
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
let(:user) { dossier.user }
subject { render 'users/dossiers/dossier_actions.html.haml', dossier: dossier }
subject { render 'users/dossiers/dossier_actions.html.haml', dossier: dossier, current_user: user }
it { is_expected.to have_link('Commencer un autre dossier', href: commencer_url(path: procedure.path)) }
it { is_expected.to have_link('Supprimer le dossier', href: ask_deletion_dossier_path(dossier)) }
it { is_expected.to have_link('Transferer le dossier', href: transferer_dossier_path(dossier)) }
context 'when the dossier cannot be deleted' do
let(:dossier) { create(:dossier, :accepte, procedure: procedure) }
@ -20,6 +22,7 @@ describe 'users/dossiers/dossier_actions.html.haml', type: :view do
context 'when there are no actions to display' do
let(:procedure) { create(:procedure, :closed) }
let(:dossier) { create(:dossier, :accepte, procedure: procedure) }
let(:user) { create(:user) }
it 'doesnt render the menu at all' do
expect(subject).not_to have_selector('.dropdown')

View file

@ -12,6 +12,7 @@ describe 'users/dossiers/index.html.haml', type: :view do
assign(:user_dossiers, Kaminari.paginate_array(user_dossiers).page(1))
assign(:dossiers_invites, Kaminari.paginate_array(dossiers_invites).page(1))
assign(:dossiers_supprimes, Kaminari.paginate_array(user_dossiers).page(1))
assign(:dossier_transfers, Kaminari.paginate_array([]).page(1))
assign(:statut, statut)
render
end