FIX: uncategorized setting to control whether topic featured links are allowed

This commit is contained in:
Neil Lalonde 2016-12-20 15:55:30 -05:00
parent 1cbe355c5b
commit c75bebdea2
3 changed files with 9 additions and 5 deletions

View File

@ -143,6 +143,7 @@ const Composer = RestModel.extend({
if (!this.siteSettings.topic_featured_link_enabled || !canEditTitle || creatingPrivateMessage) { return false; }
const categoryIds = this.site.get('topic_featured_link_allowed_category_ids');
if (!categoryId && categoryIds && categoryIds.indexOf(this.site.get('uncategorized_category_id')) !== -1) { return true; }
return categoryIds === undefined || !categoryIds.length || categoryIds.indexOf(categoryId) !== -1;
},

View File

@ -107,7 +107,6 @@ module TopicGuardian
def can_edit_featured_link?(category_id)
return false unless SiteSetting.topic_featured_link_enabled
return !Category.where(topic_featured_link_allowed: false).exists? unless category_id # uncategorized
Category.where(id: category_id, topic_featured_link_allowed: true).exists?
Category.where(id: category_id||SiteSetting.uncategorized_category_id, topic_featured_link_allowed: true).exists?
end
end

View File

@ -2284,16 +2284,20 @@ describe Guardian do
context 'topic featured link category restriction' do
before { SiteSetting.topic_featured_link_enabled = true }
let(:guardian) { Guardian.new }
let(:uncategorized) { Category.find(SiteSetting.uncategorized_category_id) }
context "uncategorized" do
let!(:link_category) { Fabricate(:link_category) }
it "allows featured links if no categories forbid it" do
it "allows featured links if uncategorized allows it" do
uncategorized.topic_featured_link_allowed = true
uncategorized.save!
expect(guardian.can_edit_featured_link?(nil)).to eq(true)
end
it "forbids featured links if a category forbids it" do
Fabricate(:category, topic_featured_link_allowed: false)
it "forbids featured links if uncategorized forbids it" do
uncategorized.topic_featured_link_allowed = false
uncategorized.save!
expect(guardian.can_edit_featured_link?(nil)).to eq(false)
end
end