Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Etq admin je peux relancer le routage sur tous les dossiers #11312

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/controllers/administrateurs/groupe_instructeurs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
defaut.destroy!
end

procedure.update!(routing_alert: true) if procedure.dossiers.state_en_construction_ou_instruction.any?

flash[:routing_mode] = 'simple'

redirect_to admin_procedure_groupe_instructeurs_path(@procedure)
Expand All @@ -109,6 +111,8 @@

procedure.toggle_routing

procedure.update!(routing_alert: true) if procedure.dossiers.state_en_construction_ou_instruction.any?

flash[:routing_mode] = 'custom'

redirect_to admin_procedure_groupe_instructeurs_path(procedure)
Expand Down Expand Up @@ -393,6 +397,23 @@
end
end

def bulk_route
dossiers = procedure.dossiers.includes(:procedure, :groupe_instructeur, :champs, revision: [:types_de_champ]).state_not_termine

Check warning on line 401 in app/controllers/administrateurs/groupe_instructeurs_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/administrateurs/groupe_instructeurs_controller.rb#L401

Added line #L401 was not covered by tests

dossiers.update_all(forced_groupe_instructeur: false)

Check warning on line 403 in app/controllers/administrateurs/groupe_instructeurs_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/administrateurs/groupe_instructeurs_controller.rb#L403

Added line #L403 was not covered by tests

dossiers.in_batches do |relation|
relation.each do |dossier|
RoutingEngine.compute(dossier, assignment_mode: DossierAssignment.modes.fetch(:bulk_routing))

Check warning on line 407 in app/controllers/administrateurs/groupe_instructeurs_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/administrateurs/groupe_instructeurs_controller.rb#L405-L407

Added lines #L405 - L407 were not covered by tests
end
end
procedure.update!(routing_alert: false)

Check warning on line 410 in app/controllers/administrateurs/groupe_instructeurs_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/administrateurs/groupe_instructeurs_controller.rb#L410

Added line #L410 was not covered by tests

flash[:notice] = "Les dossiers ont étés routés vers les groupes d’instructeurs"

Check warning on line 412 in app/controllers/administrateurs/groupe_instructeurs_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/administrateurs/groupe_instructeurs_controller.rb#L412

Added line #L412 was not covered by tests

redirect_to admin_procedure_groupe_instructeurs_path(procedure)

Check warning on line 414 in app/controllers/administrateurs/groupe_instructeurs_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/administrateurs/groupe_instructeurs_controller.rb#L414

Added line #L414 was not covered by tests
end

private

def closed_params?
Expand Down
2 changes: 1 addition & 1 deletion app/models/dossier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ def show_procedure_state_warning?

def assign_to_groupe_instructeur(groupe_instructeur, mode, author = nil)
return if groupe_instructeur.present? && groupe_instructeur.procedure != procedure
return if self.groupe_instructeur == groupe_instructeur
return if self.groupe_instructeur == groupe_instructeur && mode == self.dossier_assignment&.mode

previous_groupe_instructeur = self.groupe_instructeur

Expand Down
3 changes: 2 additions & 1 deletion app/models/dossier_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class DossierAssignment < ApplicationRecord
enum :mode, {
auto: 'auto',
manual: 'manual',
tech: 'tech'
tech: 'tech',
bulk_routing: 'bulk_routing'
}

scope :manual, -> { where(mode: :manual) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.sticky-header.sticky-header-warning
.fr-container
.flex.justify-between.align-center.fr-text-default--warning
%span
= dsfr_icon("fr-icon-warning-fill fr-mr-1v")
- if @procedure.groupe_instructeurs.any?(&:invalid_rule?)
= t('.routing_alert_with_invalid_rules_html', count: @procedure.dossiers.state_en_construction_ou_instruction.count)
- else
= t('.routing_alert_html', count: @procedure.dossiers.state_en_construction_ou_instruction.count)
= button_to t('.bulk_route'), bulk_route_admin_procedure_groupe_instructeurs_path(@procedure), class: 'fr-btn no-wrap', disabled: @procedure.groupe_instructeurs.any?(&:invalid_rule?), data: { disable_with: "Routage en cours…", confirm: t('.bulk_routing_confirm') }
4 changes: 4 additions & 0 deletions app/views/administrateurs/groupe_instructeurs/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
- if @procedure.routing_alert
- content_for(:sticky_header) do
= render partial: 'administrateurs/groupe_instructeurs/routing_alert_sticky_header', locals: { procedure: @procedure }

= render partial: 'administrateurs/breadcrumbs',
locals: { steps: [[t('.procedures'), admin_procedures_path],
[@procedure.libelle.truncate_words(10), admin_procedure_path(@procedure)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ en:
existing_groupe:
one: "%{count} group exist"
other: "%{count} groups exist"
routing_alert_sticky_header:
routing_alert_html: "<strong>%{count} files</strong> have been deposited and are waiting to be processed on this procedure. These files have <strong>not been routed according to the configured routing</strong>. You must launch the routing to distribute them to the different groups."
routing_alert_with_invalid_rules_html: "<strong>%{count} files</strong> have been deposited and are waiting to be processed on this procedure. These files have <strong>not yet been routed</strong>. Once you have configured your routing rules, you will need to launch the routing to distribute them to the different groups."
bulk_route: Launch routing
bulk_routing_confirm: "Are you sure you want to launch the routing for the deposited files waiting to be processed ?"
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ fr:
procedures: Démarches
simple_routing:
procedures: Démarches
routing_alert_sticky_header:
routing_alert_html: "Il y a <strong>%{count} dossiers</strong> déposés et en attente de traitement sur cette démarche. Ces dossiers n’ont <strong>pas été routés selon le routage configuré</strong>. Vous devez lancer le routage pour les répartir dans les différents groupes."
routing_alert_with_invalid_rules_html: "Il y a <strong>%{count} dossiers</strong> déposés et en attente de traitement sur cette démarche. Ces dossiers n’ont <strong>pas encore été routés</strong>. Une fois que vous aurez configuré vos règles de routage, vous devrez lancer le routage pour les répartir dans les différents groupes."
bulk_route: Lancer le routage
bulk_routing_confirm: "Êtes-vous sûr de vouloir lancer le routage pour les dossiers déposés et en attente de traitement ?"
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@
patch 'update_instructeurs_self_management_enabled'
post 'import'
get 'export_groupe_instructeurs'
post 'bulk_route'
end
end

Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20250212084747_add_routing_alert_to_procedures.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddRoutingAlertToProcedures < ActiveRecord::Migration[7.0]
def change
add_column :procedures, :routing_alert, :boolean, default: false, null: false
end
end
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@
t.datetime "published_at", precision: nil
t.bigint "published_revision_id"
t.bigint "replaced_by_procedure_id"
t.boolean "routing_alert", default: false, null: false
t.boolean "routing_enabled"
t.bigint "service_id"
t.jsonb "sva_svr", default: {}, null: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,7 @@ def remove_instructeur(instructeur)
end

let!(:drop_down_tdc) { procedure3.draft_revision.types_de_champ.first }
let!(:dossier) { create(:dossier, procedure: procedure3, state: :en_construction) }

before { post :create_simple_routing, params: { procedure_id: procedure3.id, create_simple_routing: { stable_id: drop_down_tdc.stable_id } } }

Expand All @@ -922,6 +923,7 @@ def remove_instructeur(instructeur)
expect(procedure3.groupe_instructeurs.pluck(:label)).to match_array(['Paris', 'Lyon', 'Marseille'])
expect(procedure3.reload.defaut_groupe_instructeur.routing_rule).to eq(ds_eq(champ_value(drop_down_tdc.stable_id), constant('Lyon')))
expect(procedure3.routing_enabled).to be_truthy
expect(procedure3.routing_alert).to be_truthy
end
end

Expand All @@ -942,6 +944,7 @@ def remove_instructeur(instructeur)
expect(procedure3.groupe_instructeurs.pluck(:label)).to include("01 – Ain")
expect(procedure3.reload.defaut_groupe_instructeur.routing_rule).to eq(ds_eq(champ_value(departements_tdc.stable_id), constant('01')))
expect(procedure3.routing_enabled).to be_truthy
expect(procedure3.routing_alert).to be_falsey
end
end

Expand Down Expand Up @@ -1086,4 +1089,43 @@ def remove_instructeur(instructeur)
expect(gi_1_1.signature).to be_attached
end
end

describe '#bulk_route' do
let!(:procedure) do
create(:procedure,
types_de_champ_public: [
{ type: :drop_down_list, libelle: 'Votre ville', options: ['Paris', 'Lyon', 'Marseille'] },
{ type: :text, libelle: 'Un champ texte' }
],
administrateurs: [admin])
end

let!(:drop_down_tdc) { procedure.draft_revision.types_de_champ.first }
let!(:dossier1) { create(:dossier, :with_populated_champs, procedure: procedure, state: :en_construction) }
let!(:dossier2) { create(:dossier, :with_populated_champs, procedure: procedure, state: :en_construction) }
let!(:dossier3) { create(:dossier, :with_populated_champs, procedure: procedure, state: :accepte) }

before do
dossier1.champs.first.update(value: 'Paris')
dossier2.champs.first.update(value: 'Lyon')
dossier3.champs.first.update(value: 'Marseille')
post :create_simple_routing, params: { procedure_id: procedure.id, create_simple_routing: { stable_id: drop_down_tdc.stable_id } }
end

it 'routes only dossiers en construction or en instruction' do
query_count = 0
ActiveSupport::Notifications.subscribed(lambda { |*_args| query_count += 1 }, "sql.active_record") do
post :bulk_route, params: { procedure_id: procedure.id }
end
expect(query_count).to be_between(60, 90)
expect(dossier1.reload.groupe_instructeur.label).to eq 'Paris'
expect(dossier1.reload.dossier_assignment.mode).to eq 'bulk_routing'
expect(dossier2.reload.groupe_instructeur.label).to eq 'Lyon'
expect(dossier2.reload.dossier_assignment.mode).to eq 'bulk_routing'
expect(dossier3.reload.groupe_instructeur.label).to eq 'Lyon'
expect(dossier3.reload.dossier_assignment.mode).to eq 'auto'
# Lyon is default group
expect(procedure.reload.routing_alert).to be_falsey
end
end
end
Loading