From c7907f575d9f1ed0dafb08de4d2b810245e2e0d8 Mon Sep 17 00:00:00 2001 From: Taico Aerts Date: Wed, 30 Aug 2023 14:33:18 +0200 Subject: [PATCH 1/2] Skip min title validation for help/policy posts --- app/models/concerns/post_validations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/post_validations.rb b/app/models/concerns/post_validations.rb index 687fa85f7..4b6afe142 100644 --- a/app/models/concerns/post_validations.rb +++ b/app/models/concerns/post_validations.rb @@ -8,7 +8,7 @@ module PostValidations validate :maximum_tag_length, if: -> { post_type.has_tags } validate :no_spaces_in_tags, if: -> { post_type.has_tags } validate :stripped_minimum_body, if: -> { !body_markdown.nil? } - validate :stripped_minimum_title, if: -> { !title.nil? } + validate :stripped_minimum_title, if: -> { !title.nil? && !['HelpDoc', 'PolicyDoc'].include?(post_type.name) } validate :maximum_title_length, if: -> { !title.nil? } validate :required_tags?, if: -> { post_type.has_tags && post_type.has_category } end From 5d7b005ce01d0537f98b8a62bc9fa97b5bdd910b Mon Sep 17 00:00:00 2001 From: Taico Aerts Date: Sat, 11 Nov 2023 15:40:46 +0100 Subject: [PATCH 2/2] Improve implementations with suggestions --- app/models/concerns/post_validations.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/post_validations.rb b/app/models/concerns/post_validations.rb index 4b6afe142..a0986b345 100644 --- a/app/models/concerns/post_validations.rb +++ b/app/models/concerns/post_validations.rb @@ -8,7 +8,7 @@ module PostValidations validate :maximum_tag_length, if: -> { post_type.has_tags } validate :no_spaces_in_tags, if: -> { post_type.has_tags } validate :stripped_minimum_body, if: -> { !body_markdown.nil? } - validate :stripped_minimum_title, if: -> { !title.nil? && !['HelpDoc', 'PolicyDoc'].include?(post_type.name) } + validate :stripped_minimum_title, if: -> { !title.nil? } validate :maximum_title_length, if: -> { !title.nil? } validate :required_tags?, if: -> { post_type.has_tags && post_type.has_category } end @@ -46,7 +46,14 @@ def stripped_minimum_body end def stripped_minimum_title - min_title = category.nil? ? 15 : category.min_title_length + min_title = if ['HelpDoc', 'PolicyDoc'].include?(post_type.name) + 1 + elsif category.nil? + 15 + else + category.min_title_length + end + if (title&.gsub(/(?:^[\s\t\u2000-\u200F]+|[\s\t\u2000-\u200F]+$)/, '')&.length || 0) < min_title errors.add(:title, "must be more than #{min_title} non-whitespace characters long") end