Merge pull request #11037 from demarches-simplifiees/remove_old_procedure_presentation_methods
Tech: supprime les méthodes de relative aux procedure_presentations du controller instructeur. Attention, casse des migrations
This commit is contained in:
commit
38ca9aaa92
12 changed files with 2 additions and 368 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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 }
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in a new issue