diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 987939cc6..67c67335c 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -161,7 +161,8 @@ module Users end def extend_conservation - dossier.update(en_construction_conservation_extension: dossier.en_construction_conservation_extension + 1.month) + dossier.update(en_construction_conservation_extension: dossier.en_construction_conservation_extension + 1.month, + conservation_extension: dossier.en_construction_conservation_extension + 1.month) flash[:notice] = 'Votre dossier sera conservé un mois supplémentaire' redirect_to dossier_path(@dossier) end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 08dd41243..a448a41c4 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -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) # deleted_user_email_never_send :string # en_construction_at :datetime # en_construction_close_to_expiration_notice_sent_at :datetime @@ -636,6 +637,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 @@ -652,6 +654,7 @@ class Dossier < ApplicationRecord end def after_repasser_en_construction(instructeur) + update!(conservation_extension: 0.days) log_dossier_operation(instructeur, :repasser_en_construction) end diff --git a/db/migrate/20210428104228_add_conservation_extension_to_dossiers.rb b/db/migrate/20210428104228_add_conservation_extension_to_dossiers.rb new file mode 100644 index 000000000..8b72f17ca --- /dev/null +++ b/db/migrate/20210428104228_add_conservation_extension_to_dossiers.rb @@ -0,0 +1,5 @@ +class AddConservationExtensionToDossiers < ActiveRecord::Migration[6.1] + def change + add_column :dossiers, :conservation_extension, :interval + end +end diff --git a/db/schema.rb b/db/schema.rb index ccf0e6e28..911ebb453 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_05_04_115445) do +ActiveRecord::Schema.define(version: 2021_05_05_115445) 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_05_04_115445) 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" t.string "deleted_user_email_never_send" 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 diff --git a/lib/tasks/deployment/20210429172327_rename_conservation_extension.rake b/lib/tasks/deployment/20210429172327_rename_conservation_extension.rake new file mode 100644 index 000000000..62a9658ae --- /dev/null +++ b/lib/tasks/deployment/20210429172327_rename_conservation_extension.rake @@ -0,0 +1,29 @@ +namespace :after_party do + desc 'Deployment task: rename_conservation_extension' + task rename_conservation_extension: :environment do + puts "Running deploy task 'rename_conservation_extension'" + + BATCH_SIZE = 20_000 + + dossiers = Dossier.state_en_construction.where.not(en_construction_conservation_extension: 0.days) + progress = ProgressReport.new((dossiers.count.to_f / BATCH_SIZE).round) + dossiers.in_batches(of: BATCH_SIZE) do |relation| + relation.update_all("conservation_extension = en_construction_conservation_extension") + progress.inc + end + progress.finish + + dossiers_without_conservation_extension = Dossier.where(conservation_extension: nil) + progress = ProgressReport.new((dossiers_without_conservation_extension.count.to_f / BATCH_SIZE).round) + dossiers_without_conservation_extension.in_batches(of: BATCH_SIZE) do |relation| + relation.update_all(conservation_extension: 'PT0S') + progress.inc + end + progress.finish + + # 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 diff --git a/yarn.lock b/yarn.lock index 322c51cbd..6b8bf6958 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6367,9 +6367,9 @@ hoopy@^0.1.4: integrity sha512-HRcs+2mr52W0K+x8RzcLzuPPmVIKMSv97RGHy0Ea9y/mpcaK+xTrjICA04KAHi4GRzxliNqNJEFYWHghy3rSfQ== hosted-git-info@^2.1.4: - version "2.8.8" - resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.8.tgz#7539bd4bc1e0e0a895815a2e0262420b12858488" - integrity sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg== + version "2.8.9" + resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9" + integrity sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw== hpack.js@^2.1.6: version "2.1.6" @@ -7751,15 +7751,10 @@ lodash.uniq@^4.5.0: resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M= -lodash@^4.0.0, lodash@^4.17.13, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.5, lodash@~4.17.12: - version "4.17.19" - resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b" - integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ== - -lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.14: - version "4.17.20" - resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52" - integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA== +lodash@^4.0.0, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.5, lodash@~4.17.12: + version "4.17.21" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" + integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== log-process-errors@^5.1.2: version "5.1.2" @@ -12523,9 +12518,9 @@ url-parse-lax@^3.0.0: prepend-http "^2.0.0" url-parse@^1.4.3: - version "1.4.7" - resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.4.7.tgz#a8a83535e8c00a316e403a5db4ac1b9b853ae278" - integrity sha512-d3uaVyzDB9tQoSXFvuSUNFibTd9zxd2bkVrDRvF5TmvWWQwqE4lgYJ5m+x1DbecWkw+LK4RNl2CU1hHuOKPVlg== + version "1.5.1" + resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.1.tgz#d5fa9890af8a5e1f274a2c98376510f6425f6e3b" + integrity sha512-HOfCOUJt7iSYzEx/UqgtwKRMC6EU91NFhsCHMv9oM03VJcVo2Qrp8T8kI9D7amFf1cu+/3CEhgb3rF9zL7k85Q== dependencies: querystringify "^2.1.1" requires-port "^1.0.0"