From 789dede893b0a00381037933f988ee16bdd9e0c5 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 11 Oct 2016 08:01:18 +0000 Subject: [PATCH] Tag aliases/implications: validate status and forum_topic_id. * Validates that status is active/pending/deleted/etc. Not strictly necessary, the controller prevents users from setting the status, but it doesn't hurt. * Validates that forum_topic_id is a valid topic if it's present. * Validates that approver_id and creator_id are valid users (not strictly necessary either, users can't set these values). --- app/models/tag_alias.rb | 4 ++++ app/models/tag_implication.rb | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index ebbe6d148..fe869a97a 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -6,7 +6,11 @@ class TagAlias < ActiveRecord::Base after_destroy :clear_all_cache before_validation :initialize_creator, :on => :create before_validation :normalize_names + validates_format_of :status, :with => /\A(active|deleted|pending|processing|queued|error: .*)\Z/ validates_presence_of :creator_id, :antecedent_name, :consequent_name + validates :creator, presence: { message: "must exist" }, if: lambda { creator_id.present? } + validates :approver, presence: { message: "must exist" }, if: lambda { approver_id.present? } + validates :forum_topic, presence: { message: "must exist" }, if: lambda { forum_topic_id.present? } validates_uniqueness_of :antecedent_name validate :absence_of_transitive_relation validate :antecedent_and_consequent_are_different diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index 58aa90aff..82a0a2210 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -9,7 +9,11 @@ class TagImplication < ActiveRecord::Base belongs_to :forum_topic before_validation :initialize_creator, :on => :create before_validation :normalize_names + validates_format_of :status, :with => /\A(active|deleted|pending|processing|queued|error: .*)\Z/ validates_presence_of :creator_id, :antecedent_name, :consequent_name + validates :creator, presence: { message: "must exist" }, if: lambda { creator_id.present? } + validates :approver, presence: { message: "must exist" }, if: lambda { approver_id.present? } + validates :forum_topic, presence: { message: "must exist" }, if: lambda { forum_topic_id.present? } validates_uniqueness_of :antecedent_name, :scope => :consequent_name validate :absence_of_circular_relation validate :antecedent_is_not_aliased