diff --git a/app/models/comment.rb b/app/models/comment.rb index f9cd4dfc7..987516eeb 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -6,7 +6,7 @@ class Comment < ApplicationRecord has_many :moderation_reports, as: :model has_many :votes, :class_name => "CommentVote", :dependent => :destroy - validates :body, presence: true + validates :body, presence: true, length: { maximum: 15_000 }, if: :body_changed? before_create :autoreport_spam after_create :update_last_commented_at_on_create diff --git a/app/models/dmail.rb b/app/models/dmail.rb index 8a1eb81d6..fb5c8f40f 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -2,7 +2,8 @@ require 'digest/sha1' class Dmail < ApplicationRecord validate :validate_sender_is_not_limited, on: :create - validates_presence_of :title, :body, on: :create + validates :title, presence: true, length: { maximum: 200 }, if: :title_changed? + validates :body, presence: true, length: { maximum: 50_000 }, if: :body_changed? belongs_to :owner, :class_name => "User" belongs_to :to, :class_name => "User" diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index 79ffd795a..d195ad40b 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -1,8 +1,10 @@ class ForumPost < ApplicationRecord attr_readonly :topic_id + belongs_to :creator, class_name: "User" belongs_to_updater belongs_to :topic, class_name: "ForumTopic", inverse_of: :forum_posts + has_many :dtext_links, as: :model, dependent: :destroy has_many :moderation_reports, as: :model has_many :votes, class_name: "ForumPostVote" @@ -10,12 +12,13 @@ class ForumPost < ApplicationRecord has_one :tag_implication has_one :bulk_update_request + validates :body, presence: true, length: { maximum: 200_000 }, if: :body_changed? + before_save :update_dtext_links, if: :dtext_links_changed? before_create :autoreport_spam after_create :update_topic_updated_at_on_create after_update :update_topic_updated_at_on_update_for_original_posts after_destroy :update_topic_updated_at_on_destroy - validates_presence_of :body after_save :delete_topic_if_original_post after_update(:if => ->(rec) {rec.updater_id != rec.creator_id}) do |rec| ModAction.log("#{CurrentUser.user.name} updated forum ##{rec.id}", :forum_post_update) diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index 8edbcee0d..35d3d4f6c 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -21,11 +21,11 @@ class ForumTopic < ApplicationRecord has_many :tag_aliases, :foreign_key => "forum_topic_id" has_many :tag_implications, :foreign_key => "forum_topic_id" - validates_presence_of :title + validates :title, presence: true, length: { maximum: 200 }, if: :title_changed? validates_associated :original_post validates_inclusion_of :category_id, :in => CATEGORIES.keys validates_inclusion_of :min_level, :in => MIN_LEVELS.values - validates :title, :length => {:maximum => 255} + accepts_nested_attributes_for :original_post after_update :update_orignal_post after_save(:if => ->(rec) {rec.is_locked? && rec.saved_change_to_is_locked?}) do |rec|