Add max lengths to comments, dmails, and forum posts.

* Max comment length: 15,000 characters.
* Max forum post length: 200,000 characters.
* Max forum topic title length: 200 characters.
* Max dmail length: 50,000 characters.
* Max dmail title length: 200 characters.
This commit is contained in:
evazion
2021-03-08 18:46:49 -06:00
parent 0249c290fd
commit 5623cfb145
4 changed files with 9 additions and 5 deletions

View File

@@ -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

View File

@@ -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"

View File

@@ -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)

View File

@@ -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|