allow transfer sender to revoke a transfer

This commit is contained in:
Lisa Durand 2023-03-01 17:19:06 +01:00
parent 7c22e0840e
commit 3d5bf40c0f
6 changed files with 80 additions and 39 deletions

View file

@ -78,6 +78,10 @@
margin-bottom: 0;
}
}
.no-border {
background-image: none;
}
}
.file-hidden-by-user {

View file

@ -19,7 +19,10 @@ module Users
end
def destroy
transfer = DossierTransfer.find_by!(id: params[:id], email: current_user.email)
transfer = DossierTransfer.find(params[:id])
authorized_email = (transfer.email == current_user.email || transfer.dossiers.where(dossiers: { user: current_user }).present?)
return if !authorized_email
transfer.destroy_and_nullify
redirect_to dossiers_path

View file

@ -1,36 +1,45 @@
- if dossiers.present?
%table.table.dossiers-table.hoverable
%caption= t('views.users.dossiers.dossiers_list.caption')
%thead
%tr
%th.number-col{ scope: :col }= t('views.users.dossiers.dossiers_list.n_dossier')
%th{ scope: :col }= t('views.users.dossiers.dossiers_list.procedure')
- if dossiers.present?
%th{ scope: :col }= t('views.users.dossiers.dossiers_list.requester')
%th.status-col{ scope: :col }= t('views.users.dossiers.dossiers_list.status')
%th.updated-at-col{ scope: :col }= t('views.users.dossiers.dossiers_list.updated')
%th.sr-only{ scope: :col }= t('views.users.dossiers.dossiers_list.actions')
%tbody
- dossiers.each do |dossier|
%tr{ data: { 'dossier-id': dossier.id } }
%th.number-col{ scope: :row }
= link_to(url_for_dossier(dossier), class: 'cell-link', tabindex: -1) do
%span.icon.folder
= dossier.id
%td
= link_to(url_for_dossier(dossier), class: 'cell-link') do
= procedure_libelle(dossier.procedure)
.fr-table.fr-table--bordered
%table.table.dossiers-table.hoverable
%caption= t('views.users.dossiers.dossiers_list.caption')
%thead
%tr
%th.number-col{ scope: :col }= t('views.users.dossiers.dossiers_list.n_dossier')
%th{ scope: :col }= t('views.users.dossiers.dossiers_list.procedure')
- if dossiers.present?
%td
%span.cell-link= demandeur_dossier(dossier)
%td.status-col
= status_badge(dossier.state)
%td.updated-at-col.cell-link
= try_format_date(dossier.updated_at)
%td.action-col
= render partial: 'dossier_actions', locals: { dossier: dossier }
%th{ scope: :col }= t('views.users.dossiers.dossiers_list.requester')
%th.status-col{ scope: :col }= t('views.users.dossiers.dossiers_list.status')
%th.updated-at-col{ scope: :col }= t('views.users.dossiers.dossiers_list.updated')
%th.sr-only{ scope: :col }= t('views.users.dossiers.dossiers_list.actions')
%tbody
- dossiers.each do |dossier|
- if dossier.transfer.present?
%tr.fr-background-alt--blue-france.no-border
%td.fr-py-2w.text-center{ colspan: 100 }
%p
%small
= t('views.users.dossiers.transfers.demande_en_cours', id: dossier.id, email: dossier.transfer.email)
= link_to t('views.users.dossiers.transfers.revoke'), transfer_path(dossier.transfer), class: 'fr-btn fr-btn--sm fr-btn--tertiary-no-outline', method: :delete
= paginate(dossiers)
%tr{ data: { 'dossier-id': dossier.id } }
%th.number-col{ scope: :row }
= link_to(url_for_dossier(dossier), class: 'cell-link', tabindex: -1) do
%span.icon.folder
= dossier.id
%td
= link_to(url_for_dossier(dossier), class: 'cell-link') do
= procedure_libelle(dossier.procedure)
- if dossiers.present?
%td
%span.cell-link= demandeur_dossier(dossier)
%td.status-col
= status_badge(dossier.state)
%td.updated-at-col.cell-link
= try_format_date(dossier.updated_at)
%td.action-col
= render partial: 'dossier_actions', locals: { dossier: dossier }
= paginate(dossiers)
- else
.blank-tab

View file

@ -357,6 +357,9 @@ en:
status: "Status"
updated: "Updated"
actions: "Actions"
transfers:
demande_en_cours: "Une demande de transfert est en cours sur le dossier %{id} pour %{email}"
revoke: Révoquer cette demande
dossier_action:
edit_dossier: "Edit the file"
start_other_dossier: "Start another empty file"

View file

@ -361,6 +361,9 @@ fr:
transfer_dossier: "Transférer le dossier"
edit_draft: "Modifier le brouillon"
actions: "Actions"
transfers:
demande_en_cours: "Une demande de transfert est en cours sur le dossier %{id} pour %{email}"
revoke: Révoquer cette demande
sessions:
new:
sign_in: Connexion à %{application_name}

View file

@ -4,19 +4,38 @@ describe Users::TransfersController, type: :controller do
let(:dossier) { create(:dossier, user: sender_user) }
describe 'DELETE destroy' do
let(:dossier_transfert) { DossierTransfer.initiate(recipient_user.email, [dossier]) }
context "as transfer receiver" do
let(:dossier_transfert) { DossierTransfer.initiate(recipient_user.email, [dossier]) }
subject { delete :destroy, params: { id: dossier_transfert.id } }
subject { delete :destroy, params: { id: dossier_transfert.id } }
before do
sign_in(recipient_user)
before do
sign_in(recipient_user)
end
it { expect { subject }.not_to raise_error }
it "deletes dossier transfert" do
subject
expect { dossier_transfert.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
it { expect { subject }.not_to raise_error }
context "as transfer sender" do
let(:dossier_transfert) { DossierTransfer.initiate(recipient_user.email, [dossier]) }
it "deletes dossier transfert" do
subject
expect { dossier_transfert.reload }.to raise_error(ActiveRecord::RecordNotFound)
subject { delete :destroy, params: { id: dossier_transfert.id } }
before do
sign_in(sender_user)
end
it { expect { subject }.not_to raise_error }
it "deletes dossier transfert" do
subject
expect { dossier_transfert.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
end