From 1cd64f68f1eff68bfb8c7d7f45a808916ac978b2 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 28 Feb 2019 15:51:13 +0100 Subject: [PATCH] =?UTF-8?q?FIX:=20staff/admin=20shouldn=E2=80=99t=20be=20a?= =?UTF-8?q?ble=20to=20create=20uncategorized=20topics=20(#7077)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../discourse/models/composer.js.es6 | 3 +- app/models/topic.rb | 3 +- spec/requests/posts_controller_spec.rb | 28 +++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/models/composer.js.es6 b/app/assets/javascripts/discourse/models/composer.js.es6 index e67e10515ff..6d7df62c725 100644 --- a/app/assets/javascripts/discourse/models/composer.js.es6 +++ b/app/assets/javascripts/discourse/models/composer.js.es6 @@ -369,8 +369,7 @@ const Composer = RestModel.extend({ return ( canCategorize && !categoryId && - !this.siteSettings.allow_uncategorized_topics && - !this.user.get("admin") + !this.siteSettings.allow_uncategorized_topics ); }, diff --git a/app/models/topic.rb b/app/models/topic.rb index 71ce6e1be7b..419a06357ee 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -95,8 +95,7 @@ class Topic < ActiveRecord::Base if: Proc.new { |t| (t.new_record? || t.category_id_changed?) && !SiteSetting.allow_uncategorized_topics && - (t.archetype.nil? || t.regular?) && - (!t.user_id || !t.user.staff?) + (t.archetype.nil? || t.regular?) } validates :featured_link, allow_nil: true, url: true diff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rb index 63f9ba875f5..cbd62f5f386 100644 --- a/spec/requests/posts_controller_spec.rb +++ b/spec/requests/posts_controller_spec.rb @@ -999,6 +999,34 @@ describe PostsController do expect(JSON.parse(response.body)["errors"]).to include(I18n.t(:spamming_host)) end + + context "allow_uncategorized_topics is false" do + before do + SiteSetting.allow_uncategorized_topics = false + end + + it "cant create an uncategorized post" do + post "/posts.json", params: { + raw: "a new post with no category", + title: "a new post with no category" + } + expect(response).not_to be_successful + end + + context "as staff" do + before do + sign_in(Fabricate(:admin)) + end + + it "cant create an uncategorized post" do + post "/posts.json", params: { + raw: "a new post with no category", + title: "a new post with no category" + } + expect(response).not_to be_successful + end + end + end end end