create generic labels for old and new procedure
This commit is contained in:
parent
9dd224c3c7
commit
96cfb6cc43
4 changed files with 43 additions and 0 deletions
|
@ -295,6 +295,7 @@ class Procedure < ApplicationRecord
|
|||
after_initialize :ensure_path_exists
|
||||
before_save :ensure_path_exists
|
||||
after_create :ensure_defaut_groupe_instructeur
|
||||
after_create :create_generic_procedure_labels
|
||||
|
||||
include AASM
|
||||
|
||||
|
@ -936,6 +937,12 @@ class Procedure < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def create_generic_procedure_labels
|
||||
ProcedureLabel::GENERIC_LABELS.each do |label|
|
||||
ProcedureLabel.create(name: label[:name], color: label[:color], procedure_id: self.id)
|
||||
end
|
||||
end
|
||||
|
||||
def stable_ids_used_by_routing_rules
|
||||
@stable_ids_used_by_routing_rules ||= groupe_instructeurs.flat_map { _1.routing_rule&.sources }.compact
|
||||
end
|
||||
|
|
|
@ -3,5 +3,11 @@
|
|||
class ProcedureLabel < ApplicationRecord
|
||||
belongs_to :procedure
|
||||
|
||||
GENERIC_LABELS = [
|
||||
{ name: 'à relancer', color: 'brown-caramel' },
|
||||
{ name: 'complet', color: 'green-bourgeon' },
|
||||
{ name: 'prêt pour validation', color: 'green-archipel' }
|
||||
]
|
||||
|
||||
validates :name, :color, presence: true
|
||||
end
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Maintenance
|
||||
class BackfillProcedureLabelsForProceduresTask < MaintenanceTasks::Task
|
||||
# Cette tâche permet de créer un jeu de labels génériques pour les anciennes procédures
|
||||
# Plus d'informations sur l'implémentation des labels ici : https://github.com/demarches-simplifiees/demarches-simplifiees.fr/issues/9787
|
||||
# 2024-10-15
|
||||
|
||||
include RunnableOnDeployConcern
|
||||
|
||||
run_on_first_deploy
|
||||
|
||||
def collection
|
||||
Procedure
|
||||
.includes(:procedure_labels)
|
||||
.where(procedure_labels: { id: nil })
|
||||
end
|
||||
|
||||
def process(procedure)
|
||||
ProcedureLabel::GENERIC_LABELS.each do |label|
|
||||
ProcedureLabel.create(name: label[:name], color: label[:color], procedure_id: procedure.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -513,6 +513,11 @@ describe Administrateurs::ProceduresController, type: :controller do
|
|||
expect(response).to redirect_to(champs_admin_procedure_path(Procedure.last))
|
||||
expect(flash[:notice]).to be_present
|
||||
end
|
||||
|
||||
it "create generic labels" do
|
||||
expect(subject.procedure_labels.size).to eq(3)
|
||||
expect(subject.procedure_labels.first.name).to eq('à relancer')
|
||||
end
|
||||
end
|
||||
|
||||
describe "procedure is saved with custom retention period" do
|
||||
|
|
Loading…
Reference in a new issue