Merge pull request #5374 from betagouv/3451-revoquer-invite
usager: revoque un invité sur un dossier
This commit is contained in:
commit
0c924be222
8 changed files with 54 additions and 4 deletions
|
@ -58,6 +58,10 @@ sup {
|
|||
font-size: 0.83em;
|
||||
}
|
||||
|
||||
small {
|
||||
font-size: small;
|
||||
}
|
||||
|
||||
.container {
|
||||
@include horizontal-padding($default-padding);
|
||||
max-width: $page-width + 2 * $default-padding;
|
||||
|
|
|
@ -54,6 +54,22 @@ class InvitesController < ApplicationController
|
|||
redirect_to dossiers_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
invite = Invite.find(params[:id])
|
||||
dossier = invite.dossier
|
||||
if dossier.user == current_user
|
||||
invite.destroy!
|
||||
flash.notice = "L'autorisation de #{invite.email} vient d'être révoquée."
|
||||
else
|
||||
flash.alert = "Vous ne pouvez pas révoquer cette autorisation"
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_back(fallback_location: helpers.url_for_dossier(dossier)) }
|
||||
format.js { @dossier = dossier }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def store_user_location!
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
%h4 Personnes invitées à participer à ce dossier
|
||||
%ul
|
||||
- dossier.invites.each do |invite|
|
||||
%li= invite.email
|
||||
%li
|
||||
= invite.email
|
||||
%small= link_to("Révoquer l'autorisation", invite_path(invite), data: { confirm: "Souhaitez-vous supprimer l'autorisation ?" }, method: :delete, remote: true)
|
||||
%p Ces personnes peuvent modifier ce dossier.
|
||||
- if dossier.brouillon?
|
||||
%p Une fois le dossier complet, vous devez le déposer vous-même.
|
||||
|
|
2
app/views/invites/_redraw.js.erb
Normal file
2
app/views/invites/_redraw.js.erb
Normal file
|
@ -0,0 +1,2 @@
|
|||
<%= render_to_element('#invites-form', partial: 'invites/form', locals: { dossier: @dossier }, outer: true) %>
|
||||
<%= render_flash %>
|
|
@ -1,2 +1 @@
|
|||
<%= render_to_element('#invites-form', partial: 'invites/form', locals: { dossier: @dossier }, outer: true) %>
|
||||
<%= render_flash %>
|
||||
<%= render 'redraw' %>
|
||||
|
|
1
app/views/invites/destroy.js.erb
Normal file
1
app/views/invites/destroy.js.erb
Normal file
|
@ -0,0 +1 @@
|
|||
<%= render 'redraw' %>
|
|
@ -215,7 +215,7 @@ Rails.application.routes.draw do
|
|||
resources :instructeurs, only: [:index, :create, :destroy]
|
||||
end
|
||||
|
||||
resources :invites, only: [:show] do
|
||||
resources :invites, only: [:show, :destroy] do
|
||||
collection do
|
||||
post 'dossier/:dossier_id', to: 'invites#create', as: :dossier
|
||||
end
|
||||
|
|
|
@ -249,4 +249,30 @@ describe InvitesController, type: :controller do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#DELETE destroy' do
|
||||
let!(:invite) { create :invite, email: email, dossier: dossier }
|
||||
let(:signed_in_profile) { dossier.user }
|
||||
|
||||
before do
|
||||
sign_in signed_in_profile
|
||||
end
|
||||
|
||||
subject { delete :destroy, params: { id: invite.id } }
|
||||
|
||||
context 'when user is signed in' do
|
||||
it "destroy invites" do
|
||||
expect { subject }.to change { Invite.count }.from(1).to(0)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when dossier does not belong to user' do
|
||||
let(:another_user) { create(:user) }
|
||||
|
||||
it 'does not destroy invite' do
|
||||
sign_in another_user
|
||||
expect { subject }.not_to change { Invite.count }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue