Merge pull request #7365 from tchak/fix-messages-expert

fix(expert): expert should be allowed to delete messages
This commit is contained in:
Kara Diaby 2022-05-20 18:23:52 +02:00 committed by GitHub
commit 7003014831
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 19 deletions

View file

@ -124,6 +124,12 @@ class ApplicationController < ActionController::Base
end
end
def authenticate_instructeur_or_expert!
if !instructeur_signed_in? && !expert_signed_in?
redirect_to new_user_session_path
end
end
def authenticate_administrateur!
if !administrateur_signed_in?
redirect_to new_user_session_path

View file

@ -1,5 +1,6 @@
module Instructeurs
class CommentairesController < ProceduresController
class CommentairesController < ApplicationController
before_action :authenticate_instructeur_or_expert!
after_action :mark_messagerie_as_read
def destroy

View file

@ -1,16 +1,16 @@
# frozen_string_literal: true
describe Instructeurs::CommentairesController, type: :controller do
let(:expert) { create(:expert) }
let(:instructeur) { create(:instructeur) }
let(:procedure) { create(:procedure, :published, :for_individual, instructeurs: [instructeur]) }
let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: procedure) }
render_views
context 'as instructeur' do
before { sign_in(instructeur.user) }
describe 'destroy' do
render_views
context 'when it works' do
let(:commentaire) { create(:commentaire, instructeur: instructeur, dossier: dossier) }
subject { delete :destroy, params: { dossier_id: dossier.id, procedure_id: procedure.id, id: commentaire.id }, format: :turbo_stream }
@ -34,4 +34,23 @@ describe Instructeurs::CommentairesController, type: :controller do
end
end
end
end
context 'as expert' do
before { sign_in(expert.user) }
describe 'destroy' do
context 'when it works' do
let(:commentaire) { create(:commentaire, expert: expert, dossier: dossier) }
subject { delete :destroy, params: { dossier_id: dossier.id, procedure_id: procedure.id, id: commentaire.id }, format: :turbo_stream }
it 'respond with OK and flash' do
expect(subject).to have_http_status(:ok)
expect(subject.body).to include('Message supprimé')
expect(subject.body).to include('alert-success')
expect(subject.body).to include('Votre message a été supprimé')
end
end
end
end
end