commit
c5990bbb13
3 changed files with 66 additions and 49 deletions
|
@ -94,24 +94,12 @@ class Admin::ProceduresController < AdminController
|
||||||
def publish
|
def publish
|
||||||
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
||||||
|
|
||||||
new_procedure_path = ProcedurePath.new(
|
if !ProcedurePath.valid?(procedure, params[:procedure_path])
|
||||||
{
|
|
||||||
path: params[:procedure_path],
|
|
||||||
procedure: procedure,
|
|
||||||
administrateur: procedure.administrateur
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
if new_procedure_path.validate
|
|
||||||
new_procedure_path.delete
|
|
||||||
else
|
|
||||||
flash.alert = 'Lien de la démarche invalide'
|
flash.alert = 'Lien de la démarche invalide'
|
||||||
return redirect_to admin_procedures_path
|
return redirect_to admin_procedures_path
|
||||||
end
|
end
|
||||||
|
|
||||||
if procedure.may_publish?(params[:procedure_path])
|
if procedure.publish_or_reopen!(params[:procedure_path])
|
||||||
procedure.publish!(params[:procedure_path])
|
|
||||||
|
|
||||||
flash.notice = "Démarche publiée"
|
flash.notice = "Démarche publiée"
|
||||||
redirect_to admin_procedures_path
|
redirect_to admin_procedures_path
|
||||||
else
|
else
|
||||||
|
@ -205,10 +193,7 @@ class Admin::ProceduresController < AdminController
|
||||||
|
|
||||||
def path_list
|
def path_list
|
||||||
json_path_list = ProcedurePath
|
json_path_list = ProcedurePath
|
||||||
.joins(:procedure)
|
.find_with_path(params[:request])
|
||||||
.where(procedures: { archived_at: nil })
|
|
||||||
.where("path LIKE ?", "%#{params[:request]}%")
|
|
||||||
.order(:id)
|
|
||||||
.pluck(:path, :administrateur_id)
|
.pluck(:path, :administrateur_id)
|
||||||
.map do |path, administrateur_id|
|
.map do |path, administrateur_id|
|
||||||
{
|
{
|
||||||
|
|
|
@ -70,6 +70,9 @@ class Procedure < ApplicationRecord
|
||||||
|
|
||||||
event :publish, after: :after_publish, guard: :can_publish? do
|
event :publish, after: :after_publish, guard: :can_publish? do
|
||||||
transitions from: :brouillon, to: :publiee
|
transitions from: :brouillon, to: :publiee
|
||||||
|
end
|
||||||
|
|
||||||
|
event :reopen, after: :after_reopen, guard: :can_publish? do
|
||||||
transitions from: :archivee, to: :publiee
|
transitions from: :archivee, to: :publiee
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -84,33 +87,27 @@ class Procedure < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_publish(path)
|
def publish_or_reopen!(path)
|
||||||
now = Time.now
|
if archivee? && may_reopen?(path)
|
||||||
update(
|
reopen!(path)
|
||||||
test_started_at: now,
|
elsif may_publish?(path)
|
||||||
archived_at: nil,
|
reset!
|
||||||
published_at: now
|
publish!(path)
|
||||||
)
|
end
|
||||||
procedure_path = ProcedurePath.find_by(path: path)
|
end
|
||||||
|
|
||||||
|
def publish_with_path!(path)
|
||||||
|
procedure_path = ProcedurePath
|
||||||
|
.where(administrateur: administrateur)
|
||||||
|
.find_by(path: path)
|
||||||
|
|
||||||
if procedure_path.present?
|
if procedure_path.present?
|
||||||
procedure_path.publish!(self)
|
procedure_path.publish!(self)
|
||||||
else
|
else
|
||||||
ProcedurePath.create(procedure: self, administrateur: administrateur, path: path)
|
create_procedure_path!(administrateur: administrateur, path: path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_archive
|
|
||||||
update(archived_at: Time.now)
|
|
||||||
end
|
|
||||||
|
|
||||||
def after_hide
|
|
||||||
now = Time.now
|
|
||||||
update(hidden_at: now)
|
|
||||||
procedure_path&.hide!
|
|
||||||
dossiers.update_all(hidden_at: now)
|
|
||||||
end
|
|
||||||
|
|
||||||
def reset!
|
def reset!
|
||||||
if locked?
|
if locked?
|
||||||
raise "Can not reset a locked procedure."
|
raise "Can not reset a locked procedure."
|
||||||
|
@ -132,15 +129,6 @@ class Procedure < ApplicationRecord
|
||||||
publiee? || archivee?
|
publiee? || archivee?
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_publish?(path)
|
|
||||||
procedure_path = ProcedurePath.find_by(path: path)
|
|
||||||
if procedure_path.present?
|
|
||||||
administrateur.owns?(procedure_path)
|
|
||||||
else
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Warning: dossier after_save build_default_champs must be removed
|
# Warning: dossier after_save build_default_champs must be removed
|
||||||
# to save a dossier created from this method
|
# to save a dossier created from this method
|
||||||
def new_dossier
|
def new_dossier
|
||||||
|
@ -372,6 +360,38 @@ class Procedure < ApplicationRecord
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def can_publish?(path)
|
||||||
|
procedure_path = ProcedurePath.find_by(path: path)
|
||||||
|
if procedure_path.present?
|
||||||
|
administrateur.owns?(procedure_path)
|
||||||
|
else
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_publish(path)
|
||||||
|
update!(published_at: Time.now)
|
||||||
|
|
||||||
|
publish_with_path!(path)
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_archive
|
||||||
|
update!(archived_at: Time.now)
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_hide
|
||||||
|
now = Time.now
|
||||||
|
update!(hidden_at: now)
|
||||||
|
procedure_path&.hide!
|
||||||
|
dossiers.update_all(hidden_at: now)
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_reopen(path)
|
||||||
|
update!(published_at: Time.now, archived_at: nil)
|
||||||
|
|
||||||
|
publish_with_path!(path)
|
||||||
|
end
|
||||||
|
|
||||||
def update_juridique_required
|
def update_juridique_required
|
||||||
self.juridique_required ||= (cadre_juridique.present? || deliberation.attached?)
|
self.juridique_required ||= (cadre_juridique.present? || deliberation.attached?)
|
||||||
true
|
true
|
||||||
|
|
|
@ -1,17 +1,29 @@
|
||||||
class ProcedurePath < ApplicationRecord
|
class ProcedurePath < ApplicationRecord
|
||||||
validates :path, format: { with: /\A[a-z0-9_\-]{3,50}\z/ }, presence: true, allow_blank: false, allow_nil: false
|
validates :path, format: { with: /\A[a-z0-9_\-]{3,50}\z/ }, uniqueness: true, presence: true, allow_blank: false, allow_nil: false
|
||||||
validates :administrateur_id, presence: true, allow_blank: false, allow_nil: false
|
validates :administrateur_id, presence: true, allow_blank: false, allow_nil: false
|
||||||
validates :procedure_id, presence: true, allow_blank: false, allow_nil: false
|
validates :procedure_id, presence: true, allow_blank: false, allow_nil: false
|
||||||
|
|
||||||
belongs_to :procedure
|
belongs_to :procedure
|
||||||
belongs_to :administrateur
|
belongs_to :administrateur
|
||||||
|
|
||||||
|
def self.valid?(procedure, path)
|
||||||
|
create_with(procedure: procedure, administrateur: procedure.administrateur)
|
||||||
|
.find_or_initialize_by(path: path).validate
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.find_with_path(path)
|
||||||
|
joins(:procedure)
|
||||||
|
.where.not(procedures: { aasm_state: :archivee })
|
||||||
|
.where("path LIKE ?", "%#{path}%")
|
||||||
|
.order(:id)
|
||||||
|
end
|
||||||
|
|
||||||
def hide!
|
def hide!
|
||||||
destroy!
|
destroy!
|
||||||
end
|
end
|
||||||
|
|
||||||
def publish!(new_procedure)
|
def publish!(new_procedure)
|
||||||
if procedure&.publiee?
|
if procedure&.publiee? && procedure != new_procedure
|
||||||
procedure.archive!
|
procedure.archive!
|
||||||
end
|
end
|
||||||
update!(procedure: new_procedure)
|
update!(procedure: new_procedure)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue