FIX: staff/admin shouldn’t be able to create uncategorized topics (#7077)
This commit is contained in:
parent
3517103398
commit
1cd64f68f1
|
@ -369,8 +369,7 @@ const Composer = RestModel.extend({
|
||||||
return (
|
return (
|
||||||
canCategorize &&
|
canCategorize &&
|
||||||
!categoryId &&
|
!categoryId &&
|
||||||
!this.siteSettings.allow_uncategorized_topics &&
|
!this.siteSettings.allow_uncategorized_topics
|
||||||
!this.user.get("admin")
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -95,8 +95,7 @@ class Topic < ActiveRecord::Base
|
||||||
if: Proc.new { |t|
|
if: Proc.new { |t|
|
||||||
(t.new_record? || t.category_id_changed?) &&
|
(t.new_record? || t.category_id_changed?) &&
|
||||||
!SiteSetting.allow_uncategorized_topics &&
|
!SiteSetting.allow_uncategorized_topics &&
|
||||||
(t.archetype.nil? || t.regular?) &&
|
(t.archetype.nil? || t.regular?)
|
||||||
(!t.user_id || !t.user.staff?)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
validates :featured_link, allow_nil: true, url: true
|
validates :featured_link, allow_nil: true, url: true
|
||||||
|
|
|
@ -999,6 +999,34 @@ describe PostsController do
|
||||||
|
|
||||||
expect(JSON.parse(response.body)["errors"]).to include(I18n.t(:spamming_host))
|
expect(JSON.parse(response.body)["errors"]).to include(I18n.t(:spamming_host))
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue