mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-17 19:12:37 -05:00
FIX: Admins should be able to post short titles. This is especially important for when syndicating
a blog via the wordpress plugin into Discourse.
This commit is contained in:
parent
e076661759
commit
023d18cab2
3 changed files with 32 additions and 9 deletions
|
@ -1,12 +1,21 @@
|
|||
class TopicTitleLengthValidator < ActiveModel::EachValidator
|
||||
|
||||
def validate_each(record, attribute, value)
|
||||
if record.private_message?
|
||||
private_message_title_validator = ActiveModel::Validations::LengthValidator.new({attributes: :title, in: SiteSetting.private_message_title_length, allow_blank: true})
|
||||
private_message_title_validator.validate_each(record, attribute, value)
|
||||
title_validator(record).validate_each(record, attribute, value)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
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
|
||||
topic_title_validator = ActiveModel::Validations::LengthValidator.new({attributes: :title, in: SiteSetting.topic_title_length, allow_blank: true})
|
||||
topic_title_validator.validate_each(record, attribute, value)
|
||||
SiteSetting.topic_title_length
|
||||
end
|
||||
|
||||
ActiveModel::Validations::LengthValidator.new({attributes: :title, in: length_range, allow_blank: true})
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -69,6 +69,20 @@ describe Topic do
|
|||
end
|
||||
end
|
||||
|
||||
context 'admin topic title' do
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
it 'allows really short titles' do
|
||||
pm = Fabricate.build(:private_message_topic, user: admin, title: 'a')
|
||||
expect(pm).to be_valid
|
||||
end
|
||||
|
||||
it 'but not blank' do
|
||||
pm = Fabricate.build(:private_message_topic, title: '')
|
||||
expect(pm).to_not be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context 'topic title uniqueness' do
|
||||
|
||||
let!(:topic) { Fabricate(:topic) }
|
||||
|
|
Loading…
Reference in a new issue