A platform for community discussion. Free, open, simple.
DEV: add maxlength to additional chat text columns (#23505)
David Battersby6e672557faa9
diff --git a/plugins/chat/app/models/chat/channel.rb b/plugins/chat/app/models/chat/channel.rbindex e9d6f1a300f..55e7f7dd0a7 100644--- a/plugins/chat/app/models/chat/channel.rb+++ b/plugins/chat/app/models/chat/channel.rb@@ -37,6 +37,8 @@ module Chatpresence: true,allow_nil: truevalidates :description, length: { maximum: 500 }+ validates :chatable_type, length: { maximum: 100 }+ validates :type, length: { maximum: 100 }validates :slug, length: { maximum: 100 }validate :ensure_slug_ok, if: :slug_changed?before_validation :generate_auto_slugdiff --git a/plugins/chat/app/models/chat/channel_archive.rb b/plugins/chat/app/models/chat/channel_archive.rbindex e8c88b4b932..c2ca472c824 100644--- a/plugins/chat/app/models/chat/channel_archive.rb+++ b/plugins/chat/app/models/chat/channel_archive.rb@@ -6,6 +6,9 @@ module Chatbelongs_to :archived_by, class_name: "User"belongs_to :destination_topic, class_name: "Topic"+ validates :archive_error, length: { maximum: 1000 }+ validates :destination_topic_title, length: { maximum: 1000 }+self.table_name = "chat_channel_archives"def complete?diff --git a/plugins/chat/app/models/chat/incoming_webhook.rb b/plugins/chat/app/models/chat/incoming_webhook.rbindex a7f447fbd68..34a62c90a22 100644--- a/plugins/chat/app/models/chat/incoming_webhook.rb+++ b/plugins/chat/app/models/chat/incoming_webhook.rb@@ -12,6 +12,12 @@ module Chatbefore_create { self.key = SecureRandom.hex(12) }+ validates :name, presence: true, length: { maximum: 100 }+ validates :key, length: { maximum: 100 }+ validates :username, length: { maximum: 100 }+ validates :description, length: { maximum: 500 }+ validates :emoji, length: { maximum: 100 }+def url"#{Discourse.base_url}/chat/hooks/#{key}.json"enddiff --git a/plugins/chat/app/models/chat/message_reaction.rb b/plugins/chat/app/models/chat/message_reaction.rbindex 3b378dd0481..cb1e69cdd9d 100644--- a/plugins/chat/app/models/chat/message_reaction.rb+++ b/plugins/chat/app/models/chat/message_reaction.rb@@ -6,6 +6,8 @@ module Chatbelongs_to :chat_message, class_name: "Chat::Message"belongs_to :user++ validates :emoji, length: { maximum: 100 }endenddiff --git a/plugins/chat/app/models/chat/reviewable_message.rb b/plugins/chat/app/models/chat/reviewable_message.rbindex 3110f1de73b..942e74c4aea 100644--- a/plugins/chat/app/models/chat/reviewable_message.rb+++ b/plugins/chat/app/models/chat/reviewable_message.rb@@ -2,6 +2,9 @@module Chatclass ReviewableMessage < Reviewable+ validates :type, length: { maximum: 100 }+ validates :target_type, length: { maximum: 100 }+def serializerChat::ReviewableMessageSerializerenddiff --git a/plugins/chat/spec/models/chat/category_channel_spec.rb b/plugins/chat/spec/models/chat/category_channel_spec.rbindex 5e275db5096..b527bae77da 100644--- a/plugins/chat/spec/models/chat/category_channel_spec.rb+++ b/plugins/chat/spec/models/chat/category_channel_spec.rb@@ -9,6 +9,8 @@ RSpec.describe Chat::CategoryChannel doit { is_expected.to delegate_method(:url).to(:chatable).with_prefix }it { is_expected.to validate_length_of(:description).is_at_most(500) }it { is_expected.to validate_length_of(:slug).is_at_most(100) }+ it { is_expected.to validate_length_of(:chatable_type).is_at_most(100) }+ it { is_expected.to validate_length_of(:type).is_at_most(100) }describe "#category_channel?" doit "always returns true" dodiff --git a/plugins/chat/spec/models/chat/channel_archive_spec.rb b/plugins/chat/spec/models/chat/channel_archive_spec.rbnew file mode 100644index 00000000000..9d99abc1715--- /dev/null+++ b/plugins/chat/spec/models/chat/channel_archive_spec.rb@@ -0,0 +1,6 @@+# frozen_string_literal: true++RSpec.describe Chat::ChannelArchive do+ it { is_expected.to validate_length_of(:archive_error).is_at_most(1000) }+ it { is_expected.to validate_length_of(:destination_topic_title).is_at_most(1000) }+enddiff --git a/plugins/chat/spec/models/chat/channel_spec.rb b/plugins/chat/spec/models/chat/channel_spec.rbindex 9f4da9ce9f8..a596f84d417 100644--- a/plugins/chat/spec/models/chat/channel_spec.rb+++ b/plugins/chat/spec/models/chat/channel_spec.rb@@ -8,6 +8,8 @@ RSpec.describe Chat::Channel doit { is_expected.to validate_length_of(:description).is_at_most(500) }it { is_expected.to validate_length_of(:slug).is_at_most(100) }+ it { is_expected.to validate_length_of(:chatable_type).is_at_most(100) }+ it { is_expected.to validate_length_of(:type).is_at_most(100) }describe ".find_by_id_or_slug" dosubject(:find_channel) { described_class.find_by_id_or_slug(channel_id) }diff --git a/plugins/chat/spec/models/chat/direct_message_channel_spec.rb b/plugins/chat/spec/models/chat/direct_message_channel_spec.rbindex f3674bcd580..83a9642a1e2 100644--- a/plugins/chat/spec/models/chat/direct_message_channel_spec.rb+++ b/plugins/chat/spec/models/chat/direct_message_channel_spec.rb@@ -7,6 +7,8 @@ RSpec.describe Chat::DirectMessageChannel doit { is_expected.to delegate_method(:allowed_user_ids).to(:direct_message).as(:user_ids) }it { is_expected.to validate_length_of(:description).is_at_most(500) }+ it { is_expected.to validate_length_of(:chatable_type).is_at_most(100) }+ it { is_expected.to validate_length_of(:type).is_at_most(100) }describe "#category_channel?" doit "always returns false" dodiff --git a/plugins/chat/spec/models/chat/incoming_webhook_spec.rb b/plugins/chat/spec/models/chat/incoming_webhook_spec.rbindex 197d0b1ccd6..37c82e07d57 100644--- a/plugins/chat/spec/models/chat/incoming_webhook_spec.rb+++ b/plugins/chat/spec/models/chat/incoming_webhook_spec.rb@@ -7,4 +7,10 @@ RSpec.describe Chat::IncomingWebhook do.class_name("Chat::WebhookEvent").dependent(:delete_all)end++ it { is_expected.to validate_length_of(:name).is_at_most(100) }+ it { is_expected.to validate_length_of(:key).is_at_most(100) }+ it { is_expected.to validate_length_of(:username).is_at_most(100) }+ it { is_expected.to validate_length_of(:description).is_at_most(500) }+ it { is_expected.to validate_length_of(:emoji).is_at_most(100) }enddiff --git a/plugins/chat/spec/models/chat/message_reaction_spec.rb b/plugins/chat/spec/models/chat/message_reaction_spec.rbnew file mode 100644index 00000000000..49801e8ad16--- /dev/null+++ b/plugins/chat/spec/models/chat/message_reaction_spec.rb@@ -0,0 +1,5 @@+# frozen_string_literal: true++RSpec.describe Chat::MessageReaction do+ it { is_expected.to validate_length_of(:emoji).is_at_most(100) }+enddiff --git a/plugins/chat/spec/models/chat/reviewable_chat_message_spec.rb b/plugins/chat/spec/models/chat/reviewable_chat_message_spec.rbindex d7f6a951018..a8f5607a9ed 100644--- a/plugins/chat/spec/models/chat/reviewable_chat_message_spec.rb+++ b/plugins/chat/spec/models/chat/reviewable_chat_message_spec.rb@@ -11,6 +11,9 @@ RSpec.describe Chat::ReviewableMessage, type: :model doFabricate(:chat_reviewable_message, target: chat_message, created_by: moderator)end+ it { is_expected.to validate_length_of(:type).is_at_most(100) }+ it { is_expected.to validate_length_of(:target_type).is_at_most(100) }+it "agree_and_keep agrees with the flag and doesn't delete the message" doreviewable.perform(moderator, :agree_and_keep_message)