Merge pull request #5374 from betagouv/3451-revoquer-invite

usager: revoque un invité sur un dossier
This commit is contained in:
krichtof 2020-07-15 15:46:16 +02:00 committed by GitHub
commit 0c924be222
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 54 additions and 4 deletions

View file

@ -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;

View file

@ -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!

View file

@ -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.

View file

@ -0,0 +1,2 @@
<%= render_to_element('#invites-form', partial: 'invites/form', locals: { dossier: @dossier }, outer: true) %>
<%= render_flash %>

View file

@ -1,2 +1 @@
<%= render_to_element('#invites-form', partial: 'invites/form', locals: { dossier: @dossier }, outer: true) %>
<%= render_flash %>
<%= render 'redraw' %>

View file

@ -0,0 +1 @@
<%= render 'redraw' %>

View file

@ -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

View file

@ -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