Rename delete_and_keep_track -> discard_and_keep_track

This commit is contained in:
Paul Chavard 2020-03-25 18:08:32 +01:00
parent b974020785
commit c707a21f97
10 changed files with 27 additions and 23 deletions

View file

@ -189,7 +189,7 @@ GEM
activejob (>= 5.0)
devise (>= 4.0)
diff-lcs (1.3)
discard (1.1.0)
discard (1.2.0)
activerecord (>= 4.2, < 7)
domain_name (0.5.20180417)
unf (>= 0.0.5, < 1.0.0)

View file

@ -8,11 +8,11 @@ module Manager
# this will be used to set the records shown on the `index` action.
def scoped_resource
if unfiltered_list?
# Don't display deleted dossiers in the unfiltered list…
Dossier
# Don't display discarded dossiers in the unfiltered list…
Dossier.kept
else
# … but allow them to be searched and displayed.
Dossier.unscope(:where)
Dossier.with_discarded
end
end
@ -20,9 +20,9 @@ module Manager
# Custom actions
#
def hide
def discard
dossier = Dossier.find(params[:id])
dossier.delete_and_keep_track!(current_administration, :manager_request)
dossier.discard_and_keep_track!(current_administration, :manager_request)
logger.info("Le dossier #{dossier.id} est supprimé par #{current_administration.email}")
flash[:notice] = "Le dossier #{dossier.id} a été supprimé."

View file

@ -209,7 +209,7 @@ module Users
dossier = current_user.dossiers.includes(:user, procedure: :administrateurs).find(params[:id])
if dossier.can_be_deleted_by_user?
dossier.delete_and_keep_track!(current_user, :user_request)
dossier.discard_and_keep_track!(current_user, :user_request)
flash.notice = 'Votre dossier a bien été supprimé.'
redirect_to dossiers_path
else

View file

@ -340,6 +340,10 @@ class Dossier < ApplicationRecord
brouillon? || en_construction?
end
def can_be_deleted_by_manager?
kept? && can_be_deleted_by_user?
end
def messagerie_available?
!brouillon? && !archived
end
@ -467,7 +471,7 @@ class Dossier < ApplicationRecord
end
end
def delete_and_keep_track!(author, reason)
def discard_and_keep_track!(author, reason)
if keep_track_on_deletion? && en_construction?
deleted_dossier = DeletedDossier.create_from_dossier(self, reason)

View file

@ -120,7 +120,7 @@ class User < ApplicationRecord
end
dossiers.each do |dossier|
dossier.delete_and_keep_track!(administration, :user_removed)
dossier.discard_and_keep_track!(administration, :user_removed)
end
dossiers.with_discarded.destroy_all
destroy!

View file

@ -22,7 +22,7 @@ as well as a link to its edit page.
<header class="main-content__header" role="banner">
<h1 class="main-content__page-title">
<%= content_for(:title) %>
<% if dossier.hidden_at %>
<% if dossier.discarded? %>
(Supprimé)
<% end %>
</h1>
@ -31,8 +31,8 @@ as well as a link to its edit page.
<% if dossier.accepte? %>
<%= link_to 'Repasser en instruction', repasser_en_instruction_manager_dossier_path(dossier), method: :post, class: 'button', data: { confirm: "Confirmez vous le passage en instruction du dossier ?" } %>
<% end %>
<% if dossier.hidden_at.nil? %>
<%= link_to 'Supprimer le dossier', hide_manager_dossier_path(dossier), method: :post, class: 'button', data: { confirm: "Confirmez vous la suppression du dossier ?" } %>
<% if dossier.can_be_deleted_by_manager? %>
<%= link_to 'Supprimer le dossier', discard_manager_dossier_path(dossier), method: :post, class: 'button', data: { confirm: "Confirmez vous la suppression du dossier ?" } %>
<% end %>
</div>
</header>

View file

@ -15,7 +15,7 @@ Rails.application.routes.draw do
end
resources :dossiers, only: [:index, :show] do
post 'hide', on: :member
post 'discard', on: :member
post 'repasser_en_instruction', on: :member
end

View file

@ -1,20 +1,20 @@
describe Manager::DossiersController, type: :controller do
describe '#hide' do
describe '#discard' do
let(:administration) { create :administration }
let!(:dossier) { create(:dossier) }
let(:dossier) { create(:dossier) }
before do
sign_in administration
post :hide, params: { id: dossier.id }
post :discard, params: { id: dossier.id }
dossier.reload
end
it { expect(dossier.hidden_at).not_to be_nil }
it { expect(dossier.discarded?).to be_truthy }
end
describe '#repasser_en_instruction' do
let(:administration) { create :administration }
let!(:dossier) { create(:dossier, :accepte) }
let(:dossier) { create(:dossier, :accepte) }
before do
sign_in administration
@ -22,6 +22,6 @@ describe Manager::DossiersController, type: :controller do
dossier.reload
end
it { expect(dossier.en_instruction?).to be true }
it { expect(dossier.en_instruction?).to be_truthy }
end
end

View file

@ -670,7 +670,7 @@ describe Dossier do
end
end
describe "#delete_and_keep_track!" do
describe "#discard_and_keep_track!" do
let(:dossier) { create(:dossier, :en_construction) }
let(:deleted_dossier) { DeletedDossier.find_by(dossier_id: dossier.id) }
let(:last_operation) { dossier.dossier_operation_logs.last }
@ -681,7 +681,7 @@ describe Dossier do
allow(DossierMailer).to receive(:notify_deletion_to_administration).and_return(double(deliver_later: nil))
end
subject! { dossier.delete_and_keep_track!(dossier.user, reason) }
subject! { dossier.discard_and_keep_track!(dossier.user, reason) }
context 'brouillon' do
let(:dossier) { create(:dossier) }

View file

@ -278,7 +278,7 @@ describe User, type: :model do
end
it "keep track of dossiers and delete user" do
dossier_cache.delete_and_keep_track!(administration, :user_request)
dossier_cache.discard_and_keep_track!(administration, :user_request)
user.delete_and_keep_track_dossiers(administration)
expect(DeletedDossier.find_by(dossier_id: dossier_en_construction)).to be_present
@ -287,7 +287,7 @@ describe User, type: :model do
end
it "doesn't destroy dossiers of another user" do
dossier_cache.delete_and_keep_track!(administration, :user_request)
dossier_cache.discard_and_keep_track!(administration, :user_request)
user.delete_and_keep_track_dossiers(administration)
expect(Dossier.find_by(id: dossier_from_another_user.id)).to be_present