Remove ProcedurePath

This commit is contained in:
Paul Chavard 2018-10-25 17:40:23 +02:00
parent 46e5e0a4fd
commit 78dc582588
13 changed files with 13 additions and 144 deletions

View file

@ -9,7 +9,6 @@ class Procedure < ApplicationRecord
has_one :module_api_carto, dependent: :destroy
has_one :attestation_template, dependent: :destroy
has_one :procedure_path, dependent: :destroy
belongs_to :administrateur
belongs_to :parent_procedure, class_name: 'Procedure'

View file

@ -1,36 +0,0 @@
class ProcedurePath < ApplicationRecord
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 :procedure_id, presence: true, allow_blank: false, allow_nil: false
belongs_to :procedure
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.mine?(administrateur, path)
procedure_path = find_by(path: path)
procedure_path && administrateur.owns?(procedure_path)
end
def self.find_with_path(path)
joins(:procedure)
.where.not(procedures: { aasm_state: :archivee })
.where("procedure_paths.path LIKE ?", "%#{path}%")
.order(:id)
end
def hide!
destroy!
end
def publish!(new_procedure)
if procedure&.publiee? && procedure != new_procedure
procedure.archive!
end
update!(procedure: new_procedure)
end
end

View file

@ -1,15 +0,0 @@
class ProcedurePathFormatValidator < ActiveModel::Validator
def path_regex
/^[a-z0-9_]{3,30}$/
end
def validate(record)
if record.path.blank?
return false
end
if !path_regex.match(record.path)
record.errors[:path] << "Path invalide"
end
end
end