FIX: Skip quality title validations for static topics when edited by admin (#18468)

Static topics are the seeded topics that are automatically created for every Discourse instance to hold the content for the FAQ, ToS and Privacy pages. These topics are allowed to bypass the minimum title length checks when they're edited by admins:

ba27ee1637/app/assets/javascripts/discourse/app/models/composer.js (L487-L496)

However, on the server-side, the "quality title" validations aren't skipped for static topics and that can cause confusion for admins when they change the title of a static topic to something that's short enough to fail the quality title validations. This commit ignores all quality title validations on static topics when they're edited by admins.

Internal topic: t/75745.
This commit is contained in:
Osama Sayegh
2022-10-04 21:55:21 +03:00
committed by GitHub
parent cf646b2061
commit 2d391565e4
2 changed files with 34 additions and 22 deletions

View File

@ -5,6 +5,8 @@ require 'text_cleaner'
class QualityTitleValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if Discourse.static_doc_topic_ids.include?(record.id) && record.acting_user&.admin?
sentinel = TextSentinel.title_sentinel(value)
if !sentinel.valid?