From 947ef3498b49c74a79051d565b47cd4b82cb4823 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 8 Nov 2024 14:14:01 +0100 Subject: [PATCH 1/2] clean: remove old procedure_presentation methods from procedures_controller --- .../instructeurs/procedures_controller.rb | 50 ------------------- config/routes.rb | 7 --- .../procedures_controller_spec.rb | 41 --------------- 3 files changed, 98 deletions(-) diff --git a/app/controllers/instructeurs/procedures_controller.rb b/app/controllers/instructeurs/procedures_controller.rb index d110d1434..4aababff6 100644 --- a/app/controllers/instructeurs/procedures_controller.rb +++ b/app/controllers/instructeurs/procedures_controller.rb @@ -132,44 +132,6 @@ module Instructeurs @statut = 'supprime' end - # TODO: to remove because of new procedure_presentation_controller - def update_displayed_fields - ids = (params['values'].presence || []).reject(&:empty?) - - procedure_presentation.update!(displayed_columns: ids) - - redirect_back(fallback_location: instructeur_procedure_url(procedure)) - end - - # TODO: to remove because of new procedure_presentation_controller - def update_sort - procedure_presentation.update!(sorted_column_params) - - redirect_back(fallback_location: instructeur_procedure_url(procedure)) - end - - # TODO: to remove because of new procedure_presentation_controller - def add_filter - if !procedure_presentation.update(filter_params) - # complicated way to display inner error messages - flash.alert = procedure_presentation.errors - .flat_map { _1.detail[:value].flat_map { |c| c.errors.full_messages } } - end - - redirect_back(fallback_location: instructeur_procedure_url(procedure)) - end - - # TODO: to remove because of new procedure_presentation_controller - def update_filter - @statut = statut - @procedure = procedure - @procedure_presentation = procedure_presentation - current_filter = procedure_presentation.filters_name_for(@statut) - # According to the html, the selected column is the last one - h_id = JSON.parse(params[current_filter].last[:id], symbolize_names: true) - @column = procedure.find_column(h_id:) - end - def download_export groupe_instructeurs = current_instructeur .groupe_instructeurs @@ -410,17 +372,5 @@ module Instructeurs def cookies_export_key "exports_#{@procedure.id}_seen_at" end - - # TODO: to remove because of new procedure_presentation_controller - def sorted_column_params - params.permit(sorted_column: [:order, :id]) - end - - # TODO: to remove because of new procedure_presentation_controller - def filter_params - keys = [:tous_filters, :a_suivre_filters, :suivis_filters, :traites_filters, :expirant_filters, :archives_filters, :supprimes_filters] - h = keys.index_with { [:id, :filter] } - params.permit(h) - end end end diff --git a/config/routes.rb b/config/routes.rb index 4ecc68874..518f513aa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -490,13 +490,6 @@ Rails.application.routes.draw do end end - # TODO: to remove because of new procedure_presentation_controller - patch 'update_displayed_fields' - get 'update_sort' => 'procedures#update_sort', as: 'update_sort' - post 'add_filter' - post 'update_filter' - get 'remove_filter' - get 'download_export' post 'download_export' get 'polling_last_export' diff --git a/spec/controllers/instructeurs/procedures_controller_spec.rb b/spec/controllers/instructeurs/procedures_controller_spec.rb index 8fcd18be9..d759412f9 100644 --- a/spec/controllers/instructeurs/procedures_controller_spec.rb +++ b/spec/controllers/instructeurs/procedures_controller_spec.rb @@ -905,45 +905,4 @@ describe Instructeurs::ProceduresController, type: :controller do it { is_expected.to have_http_status(:forbidden) } end end - - describe '#update_filter' do - let(:instructeur) { create(:instructeur) } - let(:procedure) { create(:procedure, :for_individual) } - def procedure_presentation = instructeur.assign_to.first.procedure_presentation_or_default_and_errors.first - - before do - create(:assign_to, instructeur:, groupe_instructeur: build(:groupe_instructeur, procedure:)) - - sign_in(instructeur.user) - end - - it 'can change order' do - column = procedure.find_column(label: "Nom") - expect { get :update_sort, params: { procedure_id: procedure.id, sorted_column: { id: column.id, order: 'asc' } } } - .to change { procedure_presentation.sorted_column } - .from(procedure.default_sorted_column) - .to(SortedColumn.new(column:, order: 'asc')) - end - end - - describe '#add_filter' do - let(:instructeur) { create(:instructeur) } - let(:procedure) { create(:procedure, :for_individual) } - - before do - create(:assign_to, instructeur:, groupe_instructeur: build(:groupe_instructeur, procedure:)) - - sign_in(instructeur.user) - end - - subject do - column = procedure.find_column(label: "Nom") - post :add_filter, params: { procedure_id: procedure.id, a_suivre_filters: [{ id: column.id, filter: "n" * 4049 }] } - end - - it 'should render the error' do - subject - expect(flash.alert[0]).to include("Le filtre « Nom » est trop long (maximum: 4048 caractères)") - end - end end From cdc45cd6afa3db0759191361ba8cf20b4fd3592c Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 8 Nov 2024 14:19:53 +0100 Subject: [PATCH 2/2] clean: ignore obsolete procedure_presentation columns --- app/models/procedure_presentation.rb | 2 + spec/factories/procedure_presentation.rb | 1 - ...1_migrate_filters_to_use_stable_id_spec.rb | 62 ------------------- ...remove_migration_status_on_filters_spec.rb | 50 --------------- ...n_from_procedure_presentation.rake_spec.rb | 27 -------- ...edure_presentation_to_columns.rake_spec.rb | 56 ----------------- spec/models/procedure_presentation_spec.rb | 12 ---- ...nvalid_procedure_presentation_task_spec.rb | 31 ---------- ...procedure_presentation_naming_task_spec.rb | 31 ---------- 9 files changed, 2 insertions(+), 270 deletions(-) delete mode 100644 spec/lib/tasks/deployment/20201001161931_migrate_filters_to_use_stable_id_spec.rb delete mode 100644 spec/lib/tasks/deployment/20210720133539_remove_migration_status_on_filters_spec.rb delete mode 100644 spec/lib/tasks/deployment/20240912151317_clean_virtual_column_from_procedure_presentation.rake_spec.rb delete mode 100644 spec/lib/tasks/deployment/20240920130741_migrate_procedure_presentation_to_columns.rake_spec.rb delete mode 100644 spec/tasks/maintenance/clean_invalid_procedure_presentation_task_spec.rb delete mode 100644 spec/tasks/maintenance/hotfix_former_procedure_presentation_naming_task_spec.rb diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 2df4db930..45e4e2434 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class ProcedurePresentation < ApplicationRecord + self.ignored_columns += ["displayed_fields", "filters", "sort"] + belongs_to :assign_to, optional: false has_many :exports, dependent: :destroy diff --git a/spec/factories/procedure_presentation.rb b/spec/factories/procedure_presentation.rb index 159678a28..cd0e3c33a 100644 --- a/spec/factories/procedure_presentation.rb +++ b/spec/factories/procedure_presentation.rb @@ -7,6 +7,5 @@ FactoryBot.define do end assign_to { association :assign_to, procedure: procedure, instructeur: procedure.instructeurs.first } - sort { { "table" => "user", "column" => "email", "order" => "asc" } } end end diff --git a/spec/lib/tasks/deployment/20201001161931_migrate_filters_to_use_stable_id_spec.rb b/spec/lib/tasks/deployment/20201001161931_migrate_filters_to_use_stable_id_spec.rb deleted file mode 100644 index 3c2aa7080..000000000 --- a/spec/lib/tasks/deployment/20201001161931_migrate_filters_to_use_stable_id_spec.rb +++ /dev/null @@ -1,62 +0,0 @@ -# frozen_string_literal: true - -describe '20201001161931_migrate_filters_to_use_stable_id' do - let(:rake_task) { Rake::Task['after_party:migrate_filters_to_use_stable_id'] } - - let(:procedure) { create(:procedure, :with_instructeur, :with_type_de_champ) } - let(:type_de_champ) { procedure.active_revision.types_de_champ_public.first } - let(:sort) do - { - "table" => "type_de_champ", - "column" => type_de_champ.id.to_s, - "order" => "asc" - } - end - let(:filters) do - { - 'tous' => [ - { - "label" => "test", - "table" => "type_de_champ", - "column" => type_de_champ.id.to_s, - "value" => "test" - } - ], - 'suivis' => [], - 'traites' => [], - 'a-suivre' => [], - 'archives' => [] - } - end - let(:displayed_fields) do - [ - { - "label" => "test", - "table" => "type_de_champ", - "column" => type_de_champ.id.to_s - } - ] - end - let!(:procedure_presentation) do - type_de_champ.update_column(:stable_id, 13) - procedure_presentation = create(:procedure_presentation, procedure: procedure, assign_to: procedure.groupe_instructeurs.first.assign_tos.first) - procedure_presentation.update_columns(sort: sort, filters: filters, displayed_fields: displayed_fields) - procedure_presentation - end - - before do - rake_task.invoke - procedure_presentation.reload - end - - after { rake_task.reenable } - - context "should migrate procedure_presentation" do - it "columns are updated" do - expect(procedure_presentation.sort['column']).to eq(type_de_champ.stable_id.to_s) - expect(procedure_presentation.filters['tous'][0]['column']).to eq(type_de_champ.stable_id.to_s) - expect(procedure_presentation.displayed_fields[0]['column']).to eq(type_de_champ.stable_id.to_s) - expect(procedure_presentation.filters['migrated']).to eq(true) - end - end -end diff --git a/spec/lib/tasks/deployment/20210720133539_remove_migration_status_on_filters_spec.rb b/spec/lib/tasks/deployment/20210720133539_remove_migration_status_on_filters_spec.rb deleted file mode 100644 index 1eb4e20d5..000000000 --- a/spec/lib/tasks/deployment/20210720133539_remove_migration_status_on_filters_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -# frozen_string_literal: true - -describe '20201001161931_migrate_filters_to_use_stable_id' do - let(:rake_task) { Rake::Task['after_party:remove_migration_status_on_filters'] } - - let(:procedure) { create(:simple_procedure) } - let(:instructeur_1) { create(:instructeur) } - let(:instructeur_2) { create(:instructeur) } - - let(:assign_to_1) { create(:assign_to, procedure: procedure, instructeur: instructeur_1) } - let(:assign_to_2) { create(:assign_to, procedure: procedure, instructeur: instructeur_2) } - - let(:procedure_presentation_with_migration) { create(:procedure_presentation, assign_to: assign_to_1, filters: filters.merge('migrated': true)) } - let(:procedure_presentation_without_migration) { create(:procedure_presentation, assign_to: assign_to_2, filters: filters) } - - let(:filters) do - { "suivis" => [{ "table" => "user", "column" => "email", "value" => "test@example.com" }] } - end - - subject(:run_task) do - procedure_presentation_with_migration - procedure_presentation_without_migration - - rake_task.invoke - - procedure_presentation_with_migration.reload - procedure_presentation_without_migration.reload - end - - after { rake_task.reenable } - - context 'when the procedure presentation has a "migrated" key' do - it 'removes the "migrated" key' do - run_task - expect(procedure_presentation_with_migration.filters).not_to have_key('migrated') - end - - it 'leaves other keys unchanged' do - run_task - expect(procedure_presentation_with_migration.filters['suivis']).to be_present - end - end - - context 'when the procedure presentation doesn’t have a "migrated" key' do - it 'leaves keys unchanged' do - run_task - expect(procedure_presentation_without_migration.filters['suivis']).to be_present - end - end -end diff --git a/spec/lib/tasks/deployment/20240912151317_clean_virtual_column_from_procedure_presentation.rake_spec.rb b/spec/lib/tasks/deployment/20240912151317_clean_virtual_column_from_procedure_presentation.rake_spec.rb deleted file mode 100644 index 803bb7fd4..000000000 --- a/spec/lib/tasks/deployment/20240912151317_clean_virtual_column_from_procedure_presentation.rake_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -describe '20240912151317_clean_virtual_column_from_procedure_presentation.rake' do - let(:rake_task) { Rake::Task['after_party:clean_virtual_column_from_procedure_presentation'] } - - let(:procedure) { create(:procedure) } - let(:instructeur) { create(:instructeur) } - let(:assign_to) { create(:assign_to, procedure:, instructeur:) } - - let!(:procedure_presentation) do - displayed_fields = [{ label: "test1", table: "user", column: "email", virtual: true }] - - create(:procedure_presentation, assign_to:, displayed_fields:) - end - - before do - rake_task.invoke - - procedure_presentation.reload - end - - after { rake_task.reenable } - - it 'removes the virtual field' do - expect(procedure_presentation.displayed_fields).to eq([{ "column" => "email", "label" => "test1", "table" => "user" }]) - end -end diff --git a/spec/lib/tasks/deployment/20240920130741_migrate_procedure_presentation_to_columns.rake_spec.rb b/spec/lib/tasks/deployment/20240920130741_migrate_procedure_presentation_to_columns.rake_spec.rb deleted file mode 100644 index 1e2dfcc10..000000000 --- a/spec/lib/tasks/deployment/20240920130741_migrate_procedure_presentation_to_columns.rake_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -# frozen_string_literal: true - -describe '20240920130741_migrate_procedure_presentation_to_columns.rake' do - let(:rake_task) { Rake::Task['after_party:migrate_procedure_presentation_to_columns'] } - - let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :text }]) } - let(:instructeur) { create(:instructeur) } - let(:assign_to) { create(:assign_to, procedure: procedure, instructeur: instructeur) } - let(:stable_id) { procedure.active_revision.types_de_champ.first.stable_id } - let!(:procedure_presentation) do - displayed_fields = [ - { "table" => "etablissement", "column" => "entreprise_raison_sociale" }, - { "table" => "type_de_champ", "column" => stable_id.to_s } - ] - - sort = { "order" => "desc", "table" => "self", "column" => "en_construction_at" } - - filters = { - "tous" => [], - "suivis" => [], - "traites" => [{ "label" => "Libellé NAF", "table" => "etablissement", "value" => "Administration publique générale", "column" => "libelle_naf", "value_column" => "value" }], - "a-suivre" => [], - "archives" => [], - "expirant" => [], - "supprimes" => [], - "supprimes_recemment" => [] - } - - create(:procedure_presentation, assign_to:, displayed_fields:, filters:, sort:) - end - - before do - rake_task.invoke - - procedure_presentation.reload - end - - it 'populates the columns' do - procedure_id = procedure.id - - expect(procedure_presentation.displayed_columns.map(&:label)).to eq(["Entreprise raison sociale", procedure.active_revision.types_de_champ.first.libelle]) - - order, column_id = procedure_presentation - .sorted_column - .then { |sorted| [sorted.order, sorted.column.h_id] } - - expect(order).to eq('desc') - expect(column_id).to eq(procedure_id: procedure_id, column_id: "self/en_construction_at") - - expect(procedure_presentation.tous_filters).to eq([]) - - traites = procedure_presentation.traites_filters.map { [_1.label, _1.filter] } - - expect(traites).to eq([["Libellé NAF", "Administration publique générale"]]) - end -end diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index 36c4197d3..aff99a030 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -25,18 +25,6 @@ describe ProcedurePresentation do def to_filter((label, filter)) = FilteredColumn.new(column: procedure.find_column(label: label), filter: filter) - describe "#displayed_fields" do - it { expect(procedure_presentation.displayed_fields).to eq([{ "label" => "test1", "table" => "user", "column" => "email" }, { "label" => "test2", "table" => "type_de_champ", "column" => first_type_de_champ_id }]) } - end - - describe "#sort" do - it { expect(procedure_presentation.sort).to eq({ "table" => "user", "column" => "email", "order" => "asc" }) } - end - - describe "#filters" do - it { expect(procedure_presentation.filters).to eq({ "a-suivre" => [], "suivis" => [{ "label" => "label1", "table" => "self", "column" => "created_at" }] }) } - end - describe 'validation' do it { expect(build(:procedure_presentation)).to be_valid } diff --git a/spec/tasks/maintenance/clean_invalid_procedure_presentation_task_spec.rb b/spec/tasks/maintenance/clean_invalid_procedure_presentation_task_spec.rb deleted file mode 100644 index ba0915b52..000000000 --- a/spec/tasks/maintenance/clean_invalid_procedure_presentation_task_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" - -module Maintenance - RSpec.describe CleanInvalidProcedurePresentationTask do - describe "#process" do - subject(:process) { described_class.process(element) } - let(:procedure) { create(:procedure) } - let(:groupe_instructeur) { create(:groupe_instructeur, procedure:, instructeurs: [build(:instructeur)]) } - let(:assign_to) { create(:assign_to, procedure:, instructeur: groupe_instructeur.instructeurs.first) } - let(:element) { create(:procedure_presentation, procedure:, assign_to:) } - - before { element.update_column(:filters, filters) } - - context 'when filter is valid' do - let(:filters) { { "suivis" => [{ 'table' => "self", 'column' => "id", "value" => (FilteredColumn::PG_INTEGER_MAX_VALUE - 1).to_s }] } } - it 'keeps it filters' do - expect { subject }.not_to change { element.reload.filters } - end - end - - context 'when filter is invalid, drop it' do - let(:filters) { { "suivis" => [{ 'table' => "self", 'column' => "id", "value" => (FilteredColumn::PG_INTEGER_MAX_VALUE).to_s }] } } - it 'drop invalid filters' do - expect { subject }.to change { element.reload.filters }.to({ "suivis" => [] }) - end - end - end - end -end diff --git a/spec/tasks/maintenance/hotfix_former_procedure_presentation_naming_task_spec.rb b/spec/tasks/maintenance/hotfix_former_procedure_presentation_naming_task_spec.rb deleted file mode 100644 index 4fe8dd3ec..000000000 --- a/spec/tasks/maintenance/hotfix_former_procedure_presentation_naming_task_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" - -# this commit : https://github.com/demarches-simplifiees/demarches-simplifiees.fr/pull/10625/commits/305b8c13c75a711a85521d0b19659293d8d92805 -# it brokes a naming convention on ProcedurePresentation.filters|displayed_fields|sort -# we adjust live data to fit new convention -module Maintenance - RSpec.describe HotfixFormerProcedurePresentationNamingTask do - let(:procedure) { create(:procedure, types_de_champ_private: [{ type: :text }]) } - let(:groupe_instructeur) { create(:groupe_instructeur, procedure: procedure, instructeurs: [build(:instructeur)]) } - let(:assign_to) { create(:assign_to, procedure: procedure, instructeur: groupe_instructeur.instructeurs.first) } - let(:procedure_presentation) { create(:procedure_presentation, procedure: procedure, assign_to: assign_to) } - - describe "#process" do - subject(:process) { described_class.process(procedure_presentation) } - - it "fix table naming" do - stable_id = procedure.draft_revision.types_de_champ.first.stable_id.to_s - procedure_presentation.update_column(:displayed_fields, [{ table: 'type_de_champ_private', column: stable_id }]) - procedure_presentation.update_column(:filters, "a-suivre" => [{ table: 'type_de_champ_private', column: stable_id }]) - procedure_presentation.update_column(:sort, table: 'type_de_champ_private', column: stable_id, order: 'asc') - subject - procedure_presentation.reload - expect(procedure_presentation.displayed_fields.map { _1['table'] }).to eq(['type_de_champ']) - expect(procedure_presentation.filters.flat_map { |_, filters| filters.map { _1['table'] } }).to eq(['type_de_champ']) - expect(procedure_presentation.sort['table']).to eq('type_de_champ') - end - end - end -end