Merge pull request #6142 from tchak/enable_brouillon_extend_conservation

Enable brouillon extend conservation
This commit is contained in:
Paul Chavard 2021-04-30 10:19:22 +02:00 committed by GitHub
commit 48eb4d9778
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 65 additions and 16 deletions

View file

@ -161,7 +161,7 @@ module Users
end
def extend_conservation
dossier.update(en_construction_conservation_extension: dossier.en_construction_conservation_extension + 1.month)
dossier.update(conservation_extension: dossier.conservation_extension + 1.month)
flash[:notice] = 'Votre dossier sera conservé un mois supplémentaire'
redirect_to dossier_path(@dossier)
end

View file

@ -7,6 +7,7 @@
# archived :boolean default(FALSE)
# autorisation_donnees :boolean
# brouillon_close_to_expiration_notice_sent_at :datetime
# conservation_extension :interval default(0 seconds)
# en_construction_at :datetime
# en_construction_close_to_expiration_notice_sent_at :datetime
# en_construction_conservation_extension :interval default(0 seconds)
@ -253,21 +254,22 @@ class Dossier < ApplicationRecord
scope :brouillon_close_to_expiration, -> do
state_brouillon
.joins(:procedure)
.where("dossiers.created_at + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
.where("dossiers.created_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
end
scope :en_construction_close_to_expiration, -> do
state_en_construction
.joins(:procedure)
.where("dossiers.en_construction_at + dossiers.en_construction_conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
.where("dossiers.en_construction_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
end
scope :en_instruction_close_to_expiration, -> do
state_en_instruction
.joins(:procedure)
.where("dossiers.en_instruction_at + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
end
def self.termine_close_to_expiration
dossier_ids = Traitement.termine_close_to_expiration.pluck(:dossier_id).uniq
Dossier.where(id: dossier_ids)
scope :termine_close_to_expiration, -> do
state_termine
.joins(:procedure)
.where(id: Traitement.termine_close_to_expiration.pluck(:dossier_id).uniq)
end
scope :brouillon_expired, -> do
@ -431,7 +433,15 @@ class Dossier < ApplicationRecord
end
def en_construction_close_to_expiration?
Dossier.en_construction_close_to_expiration.where(id: self).present?
self.class.en_construction_close_to_expiration.exists?(id: self)
end
def brouillon_close_to_expiration?
self.class.brouillon_close_to_expiration.exists?(id: self)
end
def close_to_expiration?
en_construction_close_to_expiration? || brouillon_close_to_expiration?
end
def show_groupe_instructeur_details?
@ -609,6 +619,7 @@ class Dossier < ApplicationRecord
end
def after_passer_en_construction
update!(conservation_extension: 0.days)
update!(en_construction_at: Time.zone.now) if self.en_construction_at.nil?
end
@ -625,6 +636,7 @@ class Dossier < ApplicationRecord
end
def after_repasser_en_construction(instructeur)
update!(conservation_extension: 0.days)
log_dossier_operation(instructeur, :repasser_en_construction)
end

View file

@ -22,11 +22,17 @@
%li
= link_to "Tout le dossier", dossier_path(dossier, format: :pdf), target: "_blank", rel: "noopener", class: "menu-item menu-link"
- if dossier.en_construction_close_to_expiration?
- if dossier.close_to_expiration?
.card.warning
.card-title Votre dossier va expirer
- if dossier.brouillon?
%p
Votre dossier a été déposé, mais va bientôt expirer. Cela signifie qu'il va bientôt être supprimé sans avoir été traité par ladministration.
Votre dossier est en brouillon, mais va bientôt expirer. Cela signifie quil va bientôt être supprimé sans avoir été déposé.
Si vous souhaitez le conserver afin de poursuivre la démarche, vous pouvez le conserver
un mois de plus en cliquant sur le bouton ci-dessous.
- else
%p
Votre dossier a été déposé, mais va bientôt expirer. Cela signifie quil va bientôt être supprimé sans avoir été traité par ladministration.
Si vous souhaitez le conserver afin de poursuivre la démarche, vous pouvez le conserver
un mois de plus en cliquant sur le bouton ci-dessous.
%br

View file

@ -8,5 +8,5 @@ fr:
one: "Afin de limiter la conservation de vos données personnelles, le dossier en brouillon suivant sera bientôt automatiquement supprimé :"
other: "Afin de limiter la conservation de vos données personnelles, les dossiers en brouillon suivant seront bientôt automatiquement supprimés :"
footer:
one: "Si vous souhaitez toujours déposer ce dossier, vous pouvez retrouver votre brouillon pendant encore <b>un mois</b>. Et sinon, vous navez rien à faire."
other: "Si vous souhaitez toujours déposer ces dossiers, vous pouvez retrouver vos brouillons pendant encore <b>un mois</b>. Et sinon, vous navez rien à faire."
one: "Si vous souhaitez toujours déposer ce dossier, vous pouvez retrouver votre brouillon pendant encore <b>un mois</b>. Si vous souhaitez conserver votre dossier plus longtemps, vous pouvez <b>prolonger sa durée de conservation</b> dans l'interface. Et sinon, vous navez rien à faire."
other: "Si vous souhaitez toujours déposer ces dossiers, vous pouvez retrouver vos brouillons pendant encore <b>un mois</b>. Si vous souhaitez conserver vos dossiers plus longtemps, vous pouvez <b>prolonger leur durée de conservation</b> au cas par cas dans l'interface. Et sinon, vous navez rien à faire."

View file

@ -0,0 +1,5 @@
class AddConservationExtensionToDossiers < ActiveRecord::Migration[6.1]
def change
add_column :dossiers, :conservation_extension, :interval, default: 0.days
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_04_27_124500) do
ActiveRecord::Schema.define(version: 2021_04_28_104228) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -274,6 +274,7 @@ ActiveRecord::Schema.define(version: 2021_04_27_124500) do
t.datetime "last_avis_updated_at"
t.datetime "last_commentaire_updated_at"
t.string "api_entreprise_job_exceptions", array: true
t.interval "conservation_extension", default: "PT0S"
t.index "to_tsvector('french'::regconfig, (search_terms || private_search_terms))", name: "index_dossiers_on_search_terms_private_search_terms", using: :gin
t.index "to_tsvector('french'::regconfig, search_terms)", name: "index_dossiers_on_search_terms", using: :gin
t.index ["archived"], name: "index_dossiers_on_archived"

View file

@ -0,0 +1,16 @@
namespace :after_party do
desc 'Deployment task: rename_conservation_extension'
task rename_conservation_extension: :environment do
puts "Running deploy task 'rename_conservation_extension'"
dossiers = Dossier.state_en_construction.where.not(en_construction_conservation_extension: 0.days)
dossiers.find_each do |dossier|
dossier.update_column(:conservation_extension, dossier.en_construction_conservation_extension)
end
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end

View file

@ -52,6 +52,15 @@ describe Dossier do
is_expected.to include(just_expired_dossier)
is_expected.to include(long_expired_dossier)
end
context 'does not include an expiring dossier that has been postponed' do
before do
expiring_dossier.update(conservation_extension: 1.month)
expiring_dossier.reload
end
it { is_expected.not_to include(expiring_dossier) }
end
end
describe 'en_construction_close_to_expiration' do
@ -72,7 +81,7 @@ describe Dossier do
context 'does not include an expiring dossier that has been postponed' do
before do
expiring_dossier.update(en_construction_conservation_extension: 1.month)
expiring_dossier.update(conservation_extension: 1.month)
expiring_dossier.reload
end