mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-18 11:32:24 -05:00
16 lines
681 B
Ruby
16 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
|