mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-28 01:56:01 -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
|