From c75bebdea2492cc9fae9ca606e3db3e2119711f2 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Tue, 20 Dec 2016 15:55:30 -0500 Subject: [PATCH] FIX: uncategorized setting to control whether topic featured links are allowed --- .../javascripts/discourse/models/composer.js.es6 | 1 + lib/guardian/topic_guardian.rb | 3 +-- spec/components/guardian_spec.rb | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/models/composer.js.es6 b/app/assets/javascripts/discourse/models/composer.js.es6 index 111a21e7bc3..6863433cfe5 100644 --- a/app/assets/javascripts/discourse/models/composer.js.es6 +++ b/app/assets/javascripts/discourse/models/composer.js.es6 @@ -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; }, diff --git a/lib/guardian/topic_guardian.rb b/lib/guardian/topic_guardian.rb index df65db4fe0c..f61a6139f8b 100644 --- a/lib/guardian/topic_guardian.rb +++ b/lib/guardian/topic_guardian.rb @@ -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 diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb index 5461c599822..b617e3d61d2 100644 --- a/spec/components/guardian_spec.rb +++ b/spec/components/guardian_spec.rb @@ -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