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
|
class CommentairesController < ProceduresController
|
||||||
|
|
||||||
def destroy
|
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
|
if result.status
|
||||||
flash_message = { notice: 'Votre commentaire a bien été supprimé' }
|
flash[:notice] = 'Votre message a été supprimé'
|
||||||
else
|
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
|
end
|
||||||
redirect_to(messagerie_instructeur_dossier_path(params[:procedure_id], params[:dossier_id]),
|
redirect_to(messagerie_instructeur_dossier_path(params[:procedure_id], params[:dossier_id]))
|
||||||
flash: flash_message)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,13 +24,13 @@ class CommentaireService
|
||||||
def soft_delete(user, params)
|
def soft_delete(user, params)
|
||||||
commentaire = Dossier.find(params[:dossier_id])
|
commentaire = Dossier.find(params[:dossier_id])
|
||||||
.commentaires
|
.commentaires
|
||||||
.find(params[:commentaire_id])
|
.find(params[:id])
|
||||||
if commentaire.sent_by?(user)
|
if commentaire.sent_by?(user)
|
||||||
commentaire.piece_jointe.purge_later if commentaire.piece_jointe.attached?
|
commentaire.piece_jointe.purge_later if commentaire.piece_jointe.attached?
|
||||||
commentaire.update!(body: "Message supprimé", deleted_at: Time.now.utc)
|
commentaire.update!(body: "Message supprimé", deleted_at: Time.now.utc)
|
||||||
OpenStruct.new(status: true)
|
OpenStruct.new(status: true)
|
||||||
else
|
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
|
end
|
||||||
rescue ActiveRecord::RecordNotFound => e
|
rescue ActiveRecord::RecordNotFound => e
|
||||||
return OpenStruct.new(status: false, error_message: "#{e.model.humanize} introuvable")
|
return OpenStruct.new(status: false, error_message: "#{e.model.humanize} introuvable")
|
||||||
|
|
|
@ -11,8 +11,10 @@
|
||||||
.rich-text= pretty_commentaire(commentaire)
|
.rich-text= pretty_commentaire(commentaire)
|
||||||
|
|
||||||
.message-extras.flex.justify-start
|
.message-extras.flex.justify-start
|
||||||
- if commentaire.sent_by?(connected_user) && commentaire.sent_by_instructeur?
|
- if commentaire.sent_by?(connected_user) && commentaire.sent_by_instructeur? && commentaire.deleted_at.nil?
|
||||||
%div{"data-test-delete-id" => 1} Suppr
|
= button_to instructeur_commentaire_path(commentaire.dossier.procedure, commentaire.dossier, commentaire), method: :delete do
|
||||||
|
Supprimer
|
||||||
|
|
||||||
- if commentaire.piece_jointe.attached?
|
- if commentaire.piece_jointe.attached?
|
||||||
.attachment-link
|
.attachment-link
|
||||||
= render partial: "shared/attachment/show", locals: { attachment: commentaire.piece_jointe.attachment }
|
= 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
|
resources :dossiers, only: [:show], param: :dossier_id do
|
||||||
member do
|
member do
|
||||||
|
resources :commentaires, only: [:destroy]
|
||||||
|
|
||||||
get 'attestation'
|
get 'attestation'
|
||||||
get 'geo_data'
|
get 'geo_data'
|
||||||
get 'apercu_attestation'
|
get 'apercu_attestation'
|
||||||
|
|
|
@ -7,18 +7,18 @@ describe Instructeurs::CommentairesController, type: :controller do
|
||||||
before { sign_in(instructeur.user) }
|
before { sign_in(instructeur.user) }
|
||||||
|
|
||||||
describe 'destroy' do
|
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 } }
|
subject { delete :destroy, params: { dossier_id: dossier.id, procedure_id: procedure.id, id: commentaire.id } }
|
||||||
it 'redirect to dossier' do
|
it 'redirect to dossier' do
|
||||||
expect(subject).to redirect_to(messagerie_instructeur_dossier_path(dossier.procedure, dossier))
|
expect(subject).to redirect_to(messagerie_instructeur_dossier_path(dossier.procedure, dossier))
|
||||||
end
|
end
|
||||||
it 'flash success' do
|
it 'flash success' do
|
||||||
subject
|
subject
|
||||||
expect(flash[:success]).to eq('Votre commentaire a bien été supprimé')
|
expect(flash[:notice]).to eq('Votre message a été supprimé')
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when it fails' do
|
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
|
before do
|
||||||
expect(CommentaireService).to receive(:soft_delete).and_return(error)
|
expect(CommentaireService).to receive(:soft_delete).and_return(error)
|
||||||
end
|
end
|
||||||
|
@ -27,7 +27,7 @@ describe Instructeurs::CommentairesController, type: :controller do
|
||||||
end
|
end
|
||||||
it 'flash success' do
|
it 'flash success' do
|
||||||
subject
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -65,12 +65,12 @@ describe CommentaireService do
|
||||||
let(:user) { create(:instructeur) }
|
let(:user) { create(:instructeur) }
|
||||||
let(:dossier) { create(:dossier) }
|
let(:dossier) { create(:dossier) }
|
||||||
let(:params) { { dossier_id: dossier.id,
|
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
|
it 'returns error struct' do
|
||||||
expect(subject.status).to eq(false)
|
expect(subject.status).to eq(false)
|
||||||
end
|
end
|
||||||
it 'returns error message' do
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ describe CommentaireService do
|
||||||
piece_jointe: fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf'))
|
piece_jointe: fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf'))
|
||||||
end
|
end
|
||||||
let(:params) { { dossier_id: dossier.id,
|
let(:params) { { dossier_id: dossier.id,
|
||||||
commentaire_id: commentaire.id } }
|
id: commentaire.id } }
|
||||||
it 'returns error struct' do
|
it 'returns error struct' do
|
||||||
expect(subject.status).to eq(true)
|
expect(subject.status).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
|
@ -52,29 +52,36 @@ describe 'shared/dossiers/messages/message.html.haml', type: :view do
|
||||||
let(:procedure) { create(:procedure) }
|
let(:procedure) { create(:procedure) }
|
||||||
let(:dossier) { create(:dossier, :en_construction, commentaires: [commentaire], procedure: 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 }
|
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
|
context 'on a procedure where commentaire had been written by connected instructeur' do
|
||||||
let(:commentaire) { create(:commentaire, instructeur: instructeur, body: 'Second message') }
|
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
|
end
|
||||||
|
|
||||||
context 'on a procedure where commentaire had been written by connected an user' do
|
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') }
|
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
|
end
|
||||||
|
|
||||||
context 'on a procedure where commentaire had been written by connected an expert' do
|
context 'on a procedure where commentaire had been written by connected an expert' do
|
||||||
let(:commentaire) { create(:commentaire, expert: create(:expert), body: 'Second message') }
|
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
|
end
|
||||||
|
|
||||||
context 'on a procedure where commentaire had been written another instructeur' do
|
context 'on a procedure where commentaire had been written another instructeur' do
|
||||||
let(:commentaire) { create(:commentaire, instructeur: create(:instructeur), body: 'Second message') }
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue