feat(rc): first stable
This commit is contained in:
parent
8b931a57d4
commit
3b78a9d81a
7 changed files with 30 additions and 20 deletions
|
@ -4,14 +4,13 @@ module Instructeurs
|
|||
class CommentairesController < ProceduresController
|
||||
|
||||
def destroy
|
||||
result = CommentaireService.soft_delete(current_instructeur, params.permit(:dossier_id, :commentaire_id))
|
||||
result = CommentaireService.soft_delete(current_instructeur, params.permit(:dossier_id, :id))
|
||||
if result.status
|
||||
flash_message = { notice: 'Votre commentaire a bien été supprimé' }
|
||||
flash[:notice] = 'Votre message a été supprimé'
|
||||
else
|
||||
flash_message = { error: "Votre commentaire ne peut être supprimé: #{result.error_messages}" }
|
||||
flash[:alert] = "Votre message ne peut être supprimé: #{result.error_message}"
|
||||
end
|
||||
redirect_to(messagerie_instructeur_dossier_path(params[:procedure_id], params[:dossier_id]),
|
||||
flash: flash_message)
|
||||
redirect_to(messagerie_instructeur_dossier_path(params[:procedure_id], params[:dossier_id]))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,13 +24,13 @@ class CommentaireService
|
|||
def soft_delete(user, params)
|
||||
commentaire = Dossier.find(params[:dossier_id])
|
||||
.commentaires
|
||||
.find(params[:commentaire_id])
|
||||
.find(params[:id])
|
||||
if commentaire.sent_by?(user)
|
||||
commentaire.piece_jointe.purge_later if commentaire.piece_jointe.attached?
|
||||
commentaire.update!(body: "Message supprimé", deleted_at: Time.now.utc)
|
||||
OpenStruct.new(status: true)
|
||||
else
|
||||
OpenStruct.new(status: false, error_message: "Impossible de supprimer le commentaire, celui ci ne vous appartient pas")
|
||||
OpenStruct.new(status: false, error_message: "Impossible de supprimer le message, celui ci ne vous appartient pas")
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound => e
|
||||
return OpenStruct.new(status: false, error_message: "#{e.model.humanize} introuvable")
|
||||
|
|
|
@ -11,8 +11,10 @@
|
|||
.rich-text= pretty_commentaire(commentaire)
|
||||
|
||||
.message-extras.flex.justify-start
|
||||
- if commentaire.sent_by?(connected_user) && commentaire.sent_by_instructeur?
|
||||
%div{"data-test-delete-id" => 1} Suppr
|
||||
- if commentaire.sent_by?(connected_user) && commentaire.sent_by_instructeur? && commentaire.deleted_at.nil?
|
||||
= button_to instructeur_commentaire_path(commentaire.dossier.procedure, commentaire.dossier, commentaire), method: :delete do
|
||||
Supprimer
|
||||
|
||||
- if commentaire.piece_jointe.attached?
|
||||
.attachment-link
|
||||
= render partial: "shared/attachment/show", locals: { attachment: commentaire.piece_jointe.attachment }
|
||||
|
|
|
@ -351,6 +351,8 @@ Rails.application.routes.draw do
|
|||
|
||||
resources :dossiers, only: [:show], param: :dossier_id do
|
||||
member do
|
||||
resources :commentaires, only: [:destroy]
|
||||
|
||||
get 'attestation'
|
||||
get 'geo_data'
|
||||
get 'apercu_attestation'
|
||||
|
|
|
@ -7,18 +7,18 @@ describe Instructeurs::CommentairesController, type: :controller do
|
|||
before { sign_in(instructeur.user) }
|
||||
|
||||
describe 'destroy' do
|
||||
let(:commentaire) { create(:commentaire, instructeur: instructeur)}
|
||||
let(:commentaire) { create(:commentaire, instructeur: instructeur, dossier: dossier)}
|
||||
subject { delete :destroy, params: { dossier_id: dossier.id, procedure_id: procedure.id, id: commentaire.id } }
|
||||
it 'redirect to dossier' do
|
||||
expect(subject).to redirect_to(messagerie_instructeur_dossier_path(dossier.procedure, dossier))
|
||||
end
|
||||
it 'flash success' do
|
||||
subject
|
||||
expect(flash[:success]).to eq('Votre commentaire a bien été supprimé')
|
||||
expect(flash[:notice]).to eq('Votre message a été supprimé')
|
||||
end
|
||||
|
||||
context 'when it fails' do
|
||||
let(:error) { OpenStruct.new(status: false, error_messages: "boom") }
|
||||
let(:error) { OpenStruct.new(status: false, error_message: "boom") }
|
||||
before do
|
||||
expect(CommentaireService).to receive(:soft_delete).and_return(error)
|
||||
end
|
||||
|
@ -27,7 +27,7 @@ describe Instructeurs::CommentairesController, type: :controller do
|
|||
end
|
||||
it 'flash success' do
|
||||
subject
|
||||
expect(flash[:error]).to eq("Votre commentaire ne peut être supprimé: #{error.error_messages}")
|
||||
expect(flash[:alert]).to eq("Votre message ne peut être supprimé: #{error.error_message}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -65,12 +65,12 @@ describe CommentaireService do
|
|||
let(:user) { create(:instructeur) }
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:params) { { dossier_id: dossier.id,
|
||||
commentaire_id: create(:commentaire, dossier: dossier, instructeur: create(:instructeur)).id } }
|
||||
id: create(:commentaire, dossier: dossier, instructeur: create(:instructeur)).id } }
|
||||
it 'returns error struct' do
|
||||
expect(subject.status).to eq(false)
|
||||
end
|
||||
it 'returns error message' do
|
||||
expect(subject.error_message).to eq("Impossible de supprimer le commentaire, celui ci ne vous appartient pas")
|
||||
expect(subject.error_message).to eq("Impossible de supprimer le message, celui ci ne vous appartient pas")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -84,7 +84,7 @@ describe CommentaireService do
|
|||
piece_jointe: fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf'))
|
||||
end
|
||||
let(:params) { { dossier_id: dossier.id,
|
||||
commentaire_id: commentaire.id } }
|
||||
id: commentaire.id } }
|
||||
it 'returns error struct' do
|
||||
expect(subject.status).to eq(true)
|
||||
end
|
||||
|
|
|
@ -52,29 +52,36 @@ describe 'shared/dossiers/messages/message.html.haml', type: :view do
|
|||
let(:procedure) { create(:procedure) }
|
||||
let(:dossier) { create(:dossier, :en_construction, commentaires: [commentaire], procedure: procedure) }
|
||||
subject { render 'shared/dossiers/messages/message.html.haml', commentaire: commentaire, messagerie_seen_at: seen_at, connected_user: instructeur, show_reply_button: true }
|
||||
let(:form_url) { instructeur_commentaire_path(commentaire.dossier.procedure, commentaire.dossier, commentaire) }
|
||||
|
||||
context 'on a procedure where commentaire had been written by connected instructeur' do
|
||||
let(:commentaire) { create(:commentaire, instructeur: instructeur, body: 'Second message') }
|
||||
|
||||
it { is_expected.to have_css("div[data-test-delete-id=1]")}
|
||||
it { is_expected.to have_selector("form[action=\"#{form_url}\"]")}
|
||||
end
|
||||
|
||||
context 'on a procedure where commentaire had been written by connected instructeur and deleted' do
|
||||
let(:commentaire) { create(:commentaire, instructeur: instructeur, body: 'Second message', deleted_at: 2.days.ago) }
|
||||
|
||||
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]")}
|
||||
end
|
||||
|
||||
context 'on a procedure where commentaire had been written by connected an user' do
|
||||
let(:commentaire) { create(:commentaire, email: create(:user).email, body: 'Second message') }
|
||||
|
||||
it { is_expected.not_to have_css("div[data-test-delete-id=1]")}
|
||||
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]")}
|
||||
end
|
||||
|
||||
context 'on a procedure where commentaire had been written by connected an expert' do
|
||||
let(:commentaire) { create(:commentaire, expert: create(:expert), body: 'Second message') }
|
||||
|
||||
it { is_expected.not_to have_css("div[data-test-delete-id=1]")}
|
||||
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]")}
|
||||
end
|
||||
|
||||
context 'on a procedure where commentaire had been written another instructeur' do
|
||||
let(:commentaire) { create(:commentaire, instructeur: create(:instructeur), body: 'Second message') }
|
||||
|
||||
it { is_expected.not_to have_css("div[data-test-delete-id=1]")}
|
||||
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]")}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue