discourse/lib/validators/topic_title_length_validato...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

25 lines
618 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class TopicTitleLengthValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
title_validator(record).validate_each(record, attribute, value)
end
private
2018-06-07 01:28:18 -04:00
def title_validator(record)
length_range =
if record.user.try(:admin?)
1..SiteSetting.max_topic_title_length
elsif record.private_message?
SiteSetting.private_message_title_length
else
SiteSetting.topic_title_length
end
2018-06-07 01:28:18 -04:00
ActiveModel::Validations::LengthValidator.new(attributes: :title, in: length_range, allow_blank: true)
end
end