A platform for community discussion. Free, open, simple.
FIX: min_personal_message_post_length not applying to first post (#23531)
Sam267e8ebaa64c
diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex c934b49568f..abbdc770e53 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -1510,9 +1510,9 @@ en:allow_user_locale: "Allow users to choose their own language interface preference"set_locale_from_accept_language_header: "set interface language for anonymous users from their web browser's language headers"support_mixed_text_direction: "Support mixed left-to-right and right-to-left text directions."- min_post_length: "Minimum allowed post length in characters"- min_first_post_length: "Minimum allowed first post (topic body) length in characters"- min_personal_message_post_length: "Minimum allowed post length in characters for messages"+ min_post_length: "Minimum allowed post length in characters (excluding personal messages)"+ min_first_post_length: "Minimum allowed first post (topic body) length (excluding personal messages)"+ min_personal_message_post_length: "Minimum allowed post length in characters for messages (both first post and replies)"max_post_length: "Maximum allowed post length in characters"topic_featured_link_enabled: "Enable posting a link with topics."show_topic_featured_link_in_digest: "Show the topic featured link in the digest email."diff --git a/lib/post_creator.rb b/lib/post_creator.rbindex f1afa7aac72..787787b2edc 100644--- a/lib/post_creator.rb+++ b/lib/post_creator.rb@@ -167,7 +167,11 @@ class PostCreatorDiscourseEvent.trigger :before_create_post, @post, @optsDiscourseEvent.trigger :validate_post, @post- post_validator = PostValidator.new(skip_topic: true)+ post_validator =+ PostValidator.new(+ skip_topic: true,+ private_message: @opts[:archetype] == Archetype.private_message,+ )post_validator.validate(@post)valid = @post.errors.blank?diff --git a/lib/validators/post_validator.rb b/lib/validators/post_validator.rbindex 737c37c1dbf..766424d13bd 100644--- a/lib/validators/post_validator.rb+++ b/lib/validators/post_validator.rb@@ -212,7 +212,7 @@ class PostValidator < ActiveModel::Validatorenddef private_message?(post)- post.topic.try(:private_message?)+ post.topic.try(:private_message?) || options[:private_message]enddef add_error_if_count_exceeded(diff --git a/spec/lib/post_creator_spec.rb b/spec/lib/post_creator_spec.rbindex 4dc8bdde0d1..b2209df8e2d 100644--- a/spec/lib/post_creator_spec.rb+++ b/spec/lib/post_creator_spec.rb@@ -208,7 +208,6 @@ RSpec.describe PostCreator docat.savecreated_post = nil- other_user_tracking_topic = nilmessages =MessageBus.track_publish do@@ -1099,6 +1098,26 @@ RSpec.describe PostCreator do)end+ it "respects min_personal_message_post_length" do+ SiteSetting.min_personal_message_post_length = 5+ SiteSetting.min_first_post_length = 20+ SiteSetting.min_post_length = 25+ SiteSetting.body_min_entropy = 20+ user.update!(trust_level: 3)+ Group.refresh_automatic_groups!++ expect {+ PostCreator.create!(+ user,+ title: "hi there welcome to my PM",+ raw: "sorry",+ archetype: Archetype.private_message,+ target_usernames: [target_user1.username, target_user2.username].join(","),+ category: 1,+ )+ }.not_to raise_error+ end+it "acts correctly" dofreeze_time