Merge pull request #2583 from tchak/add-path-to-procedure
Add path to procedure
This commit is contained in:
commit
36994ab697
7 changed files with 37 additions and 9 deletions
|
@ -194,7 +194,7 @@ class Admin::ProceduresController < AdminController
|
||||||
def path_list
|
def path_list
|
||||||
json_path_list = ProcedurePath
|
json_path_list = ProcedurePath
|
||||||
.find_with_path(params[:request])
|
.find_with_path(params[:request])
|
||||||
.pluck(:path, :administrateur_id)
|
.pluck('procedure_paths.path', :administrateur_id)
|
||||||
.map do |path, administrateur_id|
|
.map do |path, administrateur_id|
|
||||||
{
|
{
|
||||||
label: path,
|
label: path,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module ProcedureHelper
|
module ProcedureHelper
|
||||||
def procedure_lien(procedure)
|
def procedure_lien(procedure)
|
||||||
if procedure.procedure_path.present?
|
if procedure.path.present?
|
||||||
if procedure.brouillon_avec_lien?
|
if procedure.brouillon_avec_lien?
|
||||||
commencer_test_url(procedure_path: procedure.path)
|
commencer_test_url(procedure_path: procedure.path)
|
||||||
else
|
else
|
||||||
|
|
|
@ -51,6 +51,7 @@ class Procedure < ApplicationRecord
|
||||||
validates :libelle, presence: true, allow_blank: false, allow_nil: false
|
validates :libelle, presence: true, allow_blank: false, allow_nil: false
|
||||||
validates :description, presence: true, allow_blank: false, allow_nil: false
|
validates :description, presence: true, allow_blank: false, allow_nil: false
|
||||||
validate :check_juridique
|
validate :check_juridique
|
||||||
|
validates :path, format: { with: /\A[a-z0-9_\-]{3,50}\z/ }, uniqueness: true, presence: true, allow_blank: false, allow_nil: true
|
||||||
# FIXME: remove duree_conservation_required flag once all procedures are converted to the new style
|
# FIXME: remove duree_conservation_required flag once all procedures are converted to the new style
|
||||||
validates :duree_conservation_dossiers_dans_ds, allow_nil: false, numericality: { only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: MAX_DUREE_CONSERVATION }, if: :durees_conservation_required
|
validates :duree_conservation_dossiers_dans_ds, allow_nil: false, numericality: { only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: MAX_DUREE_CONSERVATION }, if: :durees_conservation_required
|
||||||
validates :duree_conservation_dossiers_hors_ds, allow_nil: false, numericality: { only_integer: true, greater_than_or_equal_to: 0 }, if: :durees_conservation_required
|
validates :duree_conservation_dossiers_hors_ds, allow_nil: false, numericality: { only_integer: true, greater_than_or_equal_to: 0 }, if: :durees_conservation_required
|
||||||
|
@ -106,6 +107,7 @@ class Procedure < ApplicationRecord
|
||||||
else
|
else
|
||||||
create_procedure_path!(administrateur: administrateur, path: path)
|
create_procedure_path!(administrateur: administrateur, path: path)
|
||||||
end
|
end
|
||||||
|
update!(path: path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset!
|
def reset!
|
||||||
|
@ -130,7 +132,7 @@ class Procedure < ApplicationRecord
|
||||||
|
|
||||||
# This method is needed for transition. Eventually this will be the same as brouillon?.
|
# This method is needed for transition. Eventually this will be the same as brouillon?.
|
||||||
def brouillon_avec_lien?
|
def brouillon_avec_lien?
|
||||||
Flipflop.publish_draft? && brouillon? && procedure_path.present?
|
Flipflop.publish_draft? && brouillon? && path.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def publiee_ou_archivee?
|
def publiee_ou_archivee?
|
||||||
|
@ -152,7 +154,7 @@ class Procedure < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def path
|
def path
|
||||||
procedure_path.path if procedure_path.present?
|
read_attribute(:path) || procedure_path&.path
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_path
|
def default_path
|
||||||
|
@ -249,7 +251,7 @@ class Procedure < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def export_filename
|
def export_filename
|
||||||
procedure_identifier = procedure_path&.path || "procedure-#{id}"
|
procedure_identifier = path || "procedure-#{id}"
|
||||||
"dossiers_#{procedure_identifier}_#{Time.now.strftime('%Y-%m-%d_%H-%M')}"
|
"dossiers_#{procedure_identifier}_#{Time.now.strftime('%Y-%m-%d_%H-%M')}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -384,12 +386,12 @@ class Procedure < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_archive
|
def after_archive
|
||||||
update!(archived_at: Time.now)
|
update!(archived_at: Time.now, path: nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_hide
|
def after_hide
|
||||||
now = Time.now
|
now = Time.now
|
||||||
update!(hidden_at: now)
|
update!(hidden_at: now, path: nil)
|
||||||
procedure_path&.hide!
|
procedure_path&.hide!
|
||||||
dossiers.update_all(hidden_at: now)
|
dossiers.update_all(hidden_at: now)
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,7 +19,7 @@ class ProcedurePath < ApplicationRecord
|
||||||
def self.find_with_path(path)
|
def self.find_with_path(path)
|
||||||
joins(:procedure)
|
joins(:procedure)
|
||||||
.where.not(procedures: { aasm_state: :archivee })
|
.where.not(procedures: { aasm_state: :archivee })
|
||||||
.where("path LIKE ?", "%#{path}%")
|
.where("procedure_paths.path LIKE ?", "%#{path}%")
|
||||||
.order(:id)
|
.order(:id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
5
db/migrate/20180913160415_add_path_to_procedures.rb
Normal file
5
db/migrate/20180913160415_add_path_to_procedures.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddPathToProcedures < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :procedures, :path, :string, index: true
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2018_08_27_111451) do
|
ActiveRecord::Schema.define(version: 2018_09_13_160415) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -486,6 +486,7 @@ ActiveRecord::Schema.define(version: 2018_08_27_111451) do
|
||||||
t.string "cadre_juridique"
|
t.string "cadre_juridique"
|
||||||
t.boolean "juridique_required", default: true
|
t.boolean "juridique_required", default: true
|
||||||
t.boolean "durees_conservation_required", default: true
|
t.boolean "durees_conservation_required", default: true
|
||||||
|
t.string "path"
|
||||||
t.index ["hidden_at"], name: "index_procedures_on_hidden_at"
|
t.index ["hidden_at"], name: "index_procedures_on_hidden_at"
|
||||||
t.index ["parent_procedure_id"], name: "index_procedures_on_parent_procedure_id"
|
t.index ["parent_procedure_id"], name: "index_procedures_on_parent_procedure_id"
|
||||||
t.index ["service_id"], name: "index_procedures_on_service_id"
|
t.index ["service_id"], name: "index_procedures_on_service_id"
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
namespace :after_party do
|
||||||
|
desc 'Deployment task: add_path_to_procedures'
|
||||||
|
task add_path_to_procedures: :environment do
|
||||||
|
puts "Running deploy task 'add_path_to_procedures'"
|
||||||
|
|
||||||
|
Procedure.publiees.where(path: nil).find_each do |procedure|
|
||||||
|
procedure.path = procedure.path
|
||||||
|
procedure.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
Procedure.archivees.where(path: nil).find_each do |procedure|
|
||||||
|
procedure.path = procedure.path
|
||||||
|
procedure.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
# Update task as completed. If you remove the line below, the task will
|
||||||
|
# run with every deploy (or every time you call after_party:run).
|
||||||
|
AfterParty::TaskRecord.create version: '20180913161001'
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue