#2250 fix validations not allowing empty topic id
This commit is contained in:
@@ -7,9 +7,9 @@ class BulkUpdateRequest < ActiveRecord::Base
|
|||||||
validates_presence_of :user
|
validates_presence_of :user
|
||||||
validates_presence_of :script
|
validates_presence_of :script
|
||||||
validates_presence_of :title
|
validates_presence_of :title
|
||||||
validates_presence_of :forum_topic, :message => "is invalid"
|
|
||||||
validates_inclusion_of :status, :in => %w(pending approved rejected)
|
validates_inclusion_of :status, :in => %w(pending approved rejected)
|
||||||
validate :script_formatted_correctly
|
validate :script_formatted_correctly
|
||||||
|
validate :forum_topic_id_not_invalid
|
||||||
attr_accessible :user_id, :forum_topic_id, :script, :title, :reason
|
attr_accessible :user_id, :forum_topic_id, :script, :title, :reason
|
||||||
attr_accessible :status, :as => [:admin]
|
attr_accessible :status, :as => [:admin]
|
||||||
before_validation :initialize_attributes, :on => :create
|
before_validation :initialize_attributes, :on => :create
|
||||||
@@ -85,4 +85,10 @@ class BulkUpdateRequest < ActiveRecord::Base
|
|||||||
errors.add(:base, e.message)
|
errors.add(:base, e.message)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def forum_topic_id_not_invalid
|
||||||
|
if forum_topic_id && !forum_topic
|
||||||
|
errors.add(:base, "Forum topic ID is invalid")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ class ForumPost < ActiveRecord::Base
|
|||||||
after_create :update_topic_updated_at_on_create
|
after_create :update_topic_updated_at_on_create
|
||||||
after_update :update_topic_updated_at_on_update_for_original_posts
|
after_update :update_topic_updated_at_on_update_for_original_posts
|
||||||
after_destroy :update_topic_updated_at_on_destroy
|
after_destroy :update_topic_updated_at_on_destroy
|
||||||
validates_presence_of :body, :creator_id, :topic
|
validates_presence_of :body, :creator_id
|
||||||
validate :validate_topic_is_unlocked
|
validate :validate_topic_is_unlocked
|
||||||
|
validate :topic_id_not_invalid
|
||||||
before_destroy :validate_topic_is_unlocked
|
before_destroy :validate_topic_is_unlocked
|
||||||
after_save :delete_topic_if_original_post
|
after_save :delete_topic_if_original_post
|
||||||
after_save :update_email_notifications
|
after_save :update_email_notifications
|
||||||
@@ -104,6 +105,12 @@ class ForumPost < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def topic_id_not_invalid
|
||||||
|
if topic_id && !topic
|
||||||
|
errors.add(:base, "Topic ID is invalid")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def editable_by?(user)
|
def editable_by?(user)
|
||||||
creator_id == user.id || user.is_janitor?
|
creator_id == user.id || user.is_janitor?
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user