From 3ac4a1b339a1c126734cbb33b4adea8de32fd929 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 7 Apr 2021 20:02:53 +0100 Subject: [PATCH 1/3] Revert "New attemp to fix orange badge hell" This reverts commit e83762c4e3b95aa99942036ba15dce0c96c03711. --- app/controllers/instructeurs/dossiers_controller.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/controllers/instructeurs/dossiers_controller.rb b/app/controllers/instructeurs/dossiers_controller.rb index f332392f0..74930bfcb 100644 --- a/app/controllers/instructeurs/dossiers_controller.rb +++ b/app/controllers/instructeurs/dossiers_controller.rb @@ -173,8 +173,6 @@ module Instructeurs if @commentaire.save @commentaire.dossier.update!(last_commentaire_updated_at: Time.zone.now) current_instructeur.follow(dossier) - # FIXME - mark_messagerie_as_read flash.notice = "Message envoyé" redirect_to messagerie_instructeur_dossier_path(procedure, dossier) else From 371d612fdb09a284116a5a26e3c33c2a774de3e0 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 7 Apr 2021 18:53:18 +0100 Subject: [PATCH 2/3] Remove unused columns --- app/models/assign_to.rb | 2 ++ app/models/avis.rb | 2 -- app/models/dossier.rb | 7 ++----- db/migrate/20210407174523_drop_unused_columns.rb | 11 +++++++++++ db/schema.rb | 10 +--------- 5 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 db/migrate/20210407174523_drop_unused_columns.rb diff --git a/app/models/assign_to.rb b/app/models/assign_to.rb index 82146a7d5..449159fb5 100644 --- a/app/models/assign_to.rb +++ b/app/models/assign_to.rb @@ -14,6 +14,8 @@ # procedure_id :integer # class AssignTo < ApplicationRecord + self.ignored_columns = [:procedure_id] + belongs_to :instructeur, optional: false belongs_to :groupe_instructeur, optional: false has_one :procedure_presentation, dependent: :destroy diff --git a/app/models/avis.rb b/app/models/avis.rb index 8d52d9bf6..11e8256f5 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -9,13 +9,11 @@ # email :string # introduction :text # revoked_at :datetime -# tmp_expert_migrated :boolean default(FALSE) # created_at :datetime not null # updated_at :datetime not null # claimant_id :integer not null # dossier_id :integer # experts_procedure_id :bigint -# instructeur_id :integer # class Avis < ApplicationRecord include EmailSanitizableConcern diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 2441035f0..ae6852cec 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -489,8 +489,7 @@ class Dossier < ApplicationRecord else avis .where(confidentiel: false) - .or(avis.where(claimant_id: instructeur.id, claimant_type: 'Instructeur')) - .or(avis.where(instructeur: instructeur)) + .or(avis.where(claimant: instructeur)) .order(created_at: :asc) end end @@ -499,11 +498,9 @@ class Dossier < ApplicationRecord if expert.dossiers.include?(self) avis.order(created_at: :asc) else - instructeur = expert.user.instructeur.id if expert.user.instructeur avis .where(confidentiel: false) - .or(avis.where(claimant_id: expert.id, claimant_type: 'Expert', tmp_expert_migrated: true)) - .or(avis.where(claimant_id: instructeur, claimant_type: 'Instructeur', tmp_expert_migrated: false)) + .or(avis.where(claimant: expert)) .order(created_at: :asc) end end diff --git a/db/migrate/20210407174523_drop_unused_columns.rb b/db/migrate/20210407174523_drop_unused_columns.rb new file mode 100644 index 000000000..244f8c952 --- /dev/null +++ b/db/migrate/20210407174523_drop_unused_columns.rb @@ -0,0 +1,11 @@ +class DropUnusedColumns < ActiveRecord::Migration[6.1] + def change + remove_column :avis, :instructeur_id + remove_column :avis, :tmp_expert_migrated + remove_column :etablissements, :entreprise_id + remove_column :procedures, :archived_at + remove_column :procedures, :csv_export_queued + remove_column :procedures, :xlsx_export_queued + remove_column :procedures, :ods_export_queued + end +end diff --git a/db/schema.rb b/db/schema.rb index ac440622d..73e62912b 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_04_02_163003) do +ActiveRecord::Schema.define(version: 2021_04_07_174523) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -121,7 +121,6 @@ ActiveRecord::Schema.define(version: 2021_04_02_163003) do t.string "email" t.text "introduction" t.text "answer" - t.integer "instructeur_id" t.integer "dossier_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false @@ -130,11 +129,9 @@ ActiveRecord::Schema.define(version: 2021_04_02_163003) do t.datetime "revoked_at" t.bigint "experts_procedure_id" t.string "claimant_type" - t.boolean "tmp_expert_migrated", default: false t.index ["claimant_id"], name: "index_avis_on_claimant_id" t.index ["dossier_id"], name: "index_avis_on_dossier_id" t.index ["experts_procedure_id"], name: "index_avis_on_experts_procedure_id" - t.index ["instructeur_id"], name: "index_avis_on_instructeur_id" end create_table "bill_signatures", force: :cascade do |t| @@ -291,7 +288,6 @@ ActiveRecord::Schema.define(version: 2021_04_02_163003) do t.string "localite" t.string "code_insee_localite" t.integer "dossier_id" - t.integer "entreprise_id" t.string "entreprise_siren" t.bigint "entreprise_capital_social" t.string "entreprise_numero_tva_intracommunautaire" @@ -532,7 +528,6 @@ ActiveRecord::Schema.define(version: 2021_04_02_163003) do t.date "auto_archive_on" t.datetime "published_at" t.datetime "hidden_at" - t.datetime "archived_at" t.datetime "whitelisted_at" t.boolean "ask_birthday", default: false, null: false t.string "web_hook_url" @@ -550,9 +545,6 @@ ActiveRecord::Schema.define(version: 2021_04_02_163003) do t.string "declarative_with_state" t.text "monavis_embed" t.text "routing_criteria_name", default: "Votre ville" - t.boolean "csv_export_queued" - t.boolean "xlsx_export_queued" - t.boolean "ods_export_queued" t.datetime "closed_at" t.datetime "unpublished_at" t.bigint "canonical_procedure_id" From 651a928b7c270c6e61c2a5b2ba55e31fdf261663 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 8 Apr 2021 11:47:29 +0100 Subject: [PATCH 3/3] Improuve export UI --- app/controllers/instructeurs/procedures_controller.rb | 5 +++++ app/models/export.rb | 6 +++++- .../procedures/_download_dossiers.html.haml | 11 ++++++----- config/locales/views/instructeurs/fr.yml | 10 ++++++++++ 4 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 config/locales/views/instructeurs/fr.yml diff --git a/app/controllers/instructeurs/procedures_controller.rb b/app/controllers/instructeurs/procedures_controller.rb index e9eb91690..5d6f78834 100644 --- a/app/controllers/instructeurs/procedures_controller.rb +++ b/app/controllers/instructeurs/procedures_controller.rb @@ -169,6 +169,11 @@ module Instructeurs export = Export.find_or_create_export(export_format, groupe_instructeurs) + if export.ready? && export.old? && params[:force_export] + export.destroy + export = Export.find_or_create_export(export_format, groupe_instructeurs) + end + if export.ready? respond_to do |format| format.js do diff --git a/app/models/export.rb b/app/models/export.rb index ef521e01e..be0d0816c 100644 --- a/app/models/export.rb +++ b/app/models/export.rb @@ -9,7 +9,7 @@ # updated_at :datetime not null # class Export < ApplicationRecord - MAX_DUREE_CONSERVATION_EXPORT = 1.hour + MAX_DUREE_CONSERVATION_EXPORT = 3.hours enum format: { csv: 'csv', @@ -45,6 +45,10 @@ class Export < ApplicationRecord file.attached? end + def old? + updated_at < 20.minutes.ago + end + def self.find_or_create_export(format, groupe_instructeurs) create_with(groupe_instructeurs: groupe_instructeurs) .create_or_find_by(format: format, key: generate_cache_key(groupe_instructeurs)) diff --git a/app/views/instructeurs/procedures/_download_dossiers.html.haml b/app/views/instructeurs/procedures/_download_dossiers.html.haml index 1a28d2292..87c2c7417 100644 --- a/app/views/instructeurs/procedures/_download_dossiers.html.haml +++ b/app/views/instructeurs/procedures/_download_dossiers.html.haml @@ -7,11 +7,12 @@ - [[xlsx_export, :xlsx], [ods_export, :ods], [csv_export, :csv]].each do |(export, format)| %li - if export.nil? - - export_text = "Demander un export au format .#{format}" - - if format == :csv - - export_text = "Demander un export au format .#{format}
(uniquement les dossiers, sans les champs répétables)".html_safe - = link_to export_text, download_export_instructeur_procedure_path(procedure, export_format: format), remote: true + = link_to t("#{format}_html", scope: [:instructeurs, :procedure, :export_stale]), download_export_instructeur_procedure_path(procedure, export_format: format), remote: true - elsif export.ready? - = link_to "Télécharger l'export au format .#{format}", export.file.service_url, target: "_blank", rel: "noopener" + = link_to t(:export_ready_html, export_time: time_ago_in_words(export.updated_at), export_format: ".#{format}", scope: [:instructeurs, :procedure]), export.file.service_url, target: "_blank", rel: "noopener" + - if export.old? + = button_to download_export_instructeur_procedure_path(procedure, export_format: format, force_export: true), class: "button small", style: "padding-right: 2px", title: t(:short, export_format: ".#{format}", scope: [:instructeurs, :procedure, :export_stale]), remote: true, method: :get, params: { export_format: format, force_export: true } do + .icon.retry - else %span{ 'data-export-poll-url': download_export_instructeur_procedure_path(procedure, export_format: format, no_progress_notification: true) } + = t(:export_pending_html, export_time: time_ago_in_words(export.created_at), export_format: ".#{format}", scope: [:instructeurs, :procedure]) diff --git a/config/locales/views/instructeurs/fr.yml b/config/locales/views/instructeurs/fr.yml new file mode 100644 index 000000000..3cc5fabdc --- /dev/null +++ b/config/locales/views/instructeurs/fr.yml @@ -0,0 +1,10 @@ +fr: + instructeurs: + procedure: + export_stale: + short: Demander un export au format %{export_format} + csv_html: Demander un export au format .csv
(uniquement les dossiers, sans les champs répétables) + xlsx_html: Demander un export au format .xlsx + ods_html: Demander un export au format .ods + export_ready_html: Télécharger l’export au format %{export_format}
(généré il y a %{export_time}) + export_pending_html: Un export au format %{export_format} est en train d’être généré
(demandé il y a %{export_time})