mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 21:10:17 +08:00
17 lines
681 B
Ruby
17 lines
681 B
Ruby
class TopicTitleLengthValidator < ActiveModel::EachValidator
|
|
|
|
def initialize(options)
|
|
@topic_title_validator = ActiveModel::Validations::LengthValidator.new({attributes: :title, in: SiteSetting.topic_title_length, allow_blank: true})
|
|
@private_message_title_validator = ActiveModel::Validations::LengthValidator.new({attributes: :title, in: SiteSetting.private_message_title_length, allow_blank: true})
|
|
super
|
|
end
|
|
|
|
def validate_each(record, attribute, value)
|
|
if record.private_message?
|
|
@private_message_title_validator.validate_each(record, attribute, value)
|
|
else
|
|
@topic_title_validator.validate_each(record, attribute, value)
|
|
end
|
|
end
|
|
end
|