From 0488c451bae6aea0cb7bb2874aedcd6379196a40 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Tue, 6 Nov 2018 19:56:01 +0100 Subject: [PATCH] Mass-process dossiers for procedure 8670 --- ..._mass_process_procedure_8670_dossiers.rake | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 lib/tasks/deployment/20181106170434_mass_process_procedure_8670_dossiers.rake diff --git a/lib/tasks/deployment/20181106170434_mass_process_procedure_8670_dossiers.rake b/lib/tasks/deployment/20181106170434_mass_process_procedure_8670_dossiers.rake new file mode 100644 index 000000000..14eb5c7ba --- /dev/null +++ b/lib/tasks/deployment/20181106170434_mass_process_procedure_8670_dossiers.rake @@ -0,0 +1,128 @@ +require Rails.root.join("lib", "tasks", "task_helper") + +namespace :after_party do + desc 'Deployment task: approve / reject dossiers for procedure 8670' + task mass_process_procedure_8670_dossiers: :environment do + class MassProcessProcedure8670 + DOSSIER_IDS_TO_ACCEPT = [ + 194722, 172178, 170186, 177122, 171783, 173930, 176042, 183202, 192081, 170387, + 171136, 171765, 173743, 173784, 173802, 173904, 173915, 171744, 173945, 170839, + 173954, 173967, 173990, 174003, 172217, 170449, 176603, 175921, 172634, 179048, + 180970, 181508, 182035, 181526, 178543, 170822, 170782, 186579, 187928, 188183, + 188399, 176860, 170614, 194011, 194100, 196307, 200282, 171544, 201953, 176316, + 205882, 205907, 205962, 178940, 181650, 202114, 180333, 174687, 192439, 169826, + 170121, 169894, 170635, 170626, 171896, 171993, 171935, 172028, 172087, 172094, + 172138, 172206, 172456, 172468, 172533, 172627, 172758, 172834, 172845, 172879, + 172884, 173411, 173662, 172256, 173909, 191259, 197681, 200041, 177306, 202624, + 203230, 204556, 205785, 198252, 170227, 173513, 172296, 174292, 174483, 174492, + 175076, 176540, 177177, 177322, 183210, 183498, 184353, 195189, 195967, 186147, + 170799, 178152, 177440, 184132, 169967, 175335, 177364, 179365, 197527, 172820, + 187060, 200326, 169921, 183622, 174745, 175484, 174512, 180860, 189163, 170054, + 170106, 206667, 170263, 173759, 169879, 170632, 190310, 170325, 170336, 170650, + 171520, 171050, 170414, 173804, 173911, 173947, 178986, 172030, 177428, 182875, + 198458, 199080, 172489, 200406, 204297, 171184, 171265, 171338, 171347, 172620, + 173162, 171939, 171597, 173878, 173758, 175861, 175923, 176851, 176957, 172479, + 183279, 177429, 185382, 185586, 188898, 172840, 180340, 195351, 171135, 170583, + 171680, 174150, 175066, 177164, 172951, 170623, 172863, 178732, 178268, 179848, + 179896, 179923, 179283, 180083, 185764, 192455, 190329, 197121, 169897, 170005, + 170023, 170127, 170399, 170371, 170351, 170519, 170654, 170680, 170774, 170781, + 171892, 169828, 171989, 172070, 171952, 171923, 172184, 174859, 175560, 175865, + 172922, 171889, 173550, 181501, 179897, 185241, 190364, 193743, 178551, 199361, + 173739, 169885, 169893, 171777, 179338, 179818, 170339, 178090, 187012, 191063, + 179911, 195101, 177916, 170242, 173537, 173895, 173700, 174642, 174749, 174880, + 174818, 175011, 174863, 175422, 175644, 177797, 177829, 174276, 200208, 204312, + 204356, 179106, 177928, 180376, 181086, 180048, 192202, 194193, 204479, 204979, + 183388, 185549 + ] + + DOSSIER_IDS_TO_REJECT = [ + 172516, 177423, 177002, 179031, 176856, 179193, 179237, 179333, 179912, 179949, + 181001, 185704, 185710, 177001, 186898, 175420, 175412, 195668, 174463, 175347, + 174606, 176668, 176749, 177007, 177037, 174306, 177373, 174496, 174583, 205297, + 191646, 178553, 184288, 174296, 199563, 202567, 180596, 194441, 196523, 183504, + 190011, 184563, 175047, 177243, 174108, 174423, 170552, 171931, 170955, 170415, + 170652, 170145, 170044, 169841, 171280, 177569, 174711, 180357, 180554, 175594, + 181370, 180370, 180279, 182877, 188432, 183516, 191845, 184965, 198962, 199250, + 202324, 205887, 172006, 196073, 197861, 198389, 188855, 198639, 203881, 205520, + 205626, 206468, 196904, 206619, 206730, 175088, 191405, 173038, 195082, 185849, + 188454, 188501, 188713, 171057, 177541, 177882, 178185, 178951, 178962, 178997, + 179090, 179234, 173959, 177621, 174022, 181414, 181895, 183081, 175935, 175951, + 176156, 176200, 176506, 176567, 173898, 173906, 173905, 173932, 173810, 173949, + 173961, 174033, 172939, 174227, 172362, 173008, 174979, 173396, 173196, 172143, + 173790, 173745, 173779, 172151, 170332, 171424, 171434, 170459, 171635, 171689, + 170409, 171429, 171940, 170266, 172632, 172742, 170689, 206612, 169877, 170402, + 170563, 170605, 170658, 170653, 170699, 170511, 170835, 183559, 187911, 188163, + 188685, 188702, 170678, 183994, 173899, 194530, 194873, 194433, 173971, 174004, + 174239, 174430, 175849, 175850, 176265, 176630, 176789, 175946, 172407, 177398, + 170027, 170002, 170404, 173678, 170655, 170328, 170405, 170686, 171106, 171763, + 172317, 172763, 172880, 173250, 174938, 170714, 175798, 175899, 176015, 176041, + 176258, 176341, 176909, 176944, 174031, 180109, 170316, 174100, 174540, 175910, + 177872, 178117, 179092, 183923, 175005, 185795, 186580, 181383, 189186, 194998, + 177475, 174446, 180508, 181216, 181290, 181905, 191344, 187745, 192016, 193188, + 170201, 170288, 170568 + ] + + def run + rake_puts "Running deploy task 'mass_process_procedure_8670_dossiers'\n" + + reject_dossiers + accept_dossiers + + AfterParty::TaskRecord.create version: '20181106170434' + end + + def reject_dossiers + rake_puts "Rejecting dossiers\n" + + dossiers_for_traitement.where(id: DOSSIER_IDS_TO_REJECT).find_each do |dossier| + if skip_dossier?(dossier) + next + end + + dossier.update( + state: Dossier.states.fetch(:refuse), + motivation: "Malheureusement, votre dossier n'a pas été tiré au sort", + processed_at: Time.zone.now + ) + NotificationMailer.send_refused_notification(dossier).deliver_later + end + end + + def accept_dossiers + rake_puts "Accepting dossiers\n" + + dossiers_for_traitement.where(id: DOSSIER_IDS_TO_ACCEPT).find_each do |dossier| + if skip_dossier?(dossier) + next + end + + dossier.update( + state: Dossier.states.fetch(:accepte), + processed_at: Time.zone.now + ) + dossier.attestation = dossier.build_attestation + dossier.save + NotificationMailer.send_closed_notification(dossier).deliver_later + end + end + + def dossiers_for_traitement + Dossier.includes(:procedure, :user, :etablissement, :champs, :champs_private) + end + + def skip_dossier?(dossier) + if dossier.procedure_id != 8670 + rake_puts "Skipping dossier #{dossier.id} (wrong procedure)\n" + return true + end + if !dossier.en_instruction? + rake_puts "Skipping dossier #{dossier.id} (not en instruction)\n" + return true + end + return false + end + end + + MassProcessProcedure8670.new.run + end +end