FEATURE: per-category approval settings (#5778)

- disallow moving topics to a category that requires topic approval
This commit is contained in:
Kyle Zhao
2018-07-12 22:51:08 -04:00
committed by Sam
parent db67c87916
commit 2901691e87
15 changed files with 187 additions and 7 deletions

View File

@@ -281,4 +281,51 @@ describe NewPostManager do
end
end
context 'when posting in the category requires approval' do
let(:user) { Fabricate(:user) }
let(:category) { Fabricate(:category) }
context 'when new topics require approval' do
before do
category.custom_fields[Category::REQUIRE_TOPIC_APPROVAL] = true
category.save
end
it 'enqueues new topics' do
manager = NewPostManager.new(
user,
raw: 'this is a new topic',
title: "Let's start a new topic!",
category: category.id
)
expect(manager.perform.action).to eq(:enqueued)
end
end
context 'when new posts require approval' do
let(:topic) { Fabricate(:topic, category: category) }
before do
category.custom_fields[Category::REQUIRE_REPLY_APPROVAL] = true
category.save
end
it 'enqueues new posts' do
manager = NewPostManager.new(user, raw: 'this is a new post', topic_id: topic.id)
expect(manager.perform.action).to eq(:enqueued)
end
it "doesn't blow up with invalid topic_id" do
expect do
manager = NewPostManager.new(
user,
raw: 'this is a new topic',
topic_id: 97546
)
expect(manager.perform.action).to eq(:create_post)
end.not_to raise_error
end
end
end
end

View File

@@ -62,6 +62,23 @@ describe PostRevisor do
expect(post.topic.category_id).to eq(category.id)
end
it 'does not revise category when the destination category requires topic approval' do
new_category = Fabricate(:category)
new_category.custom_fields[Category::REQUIRE_TOPIC_APPROVAL] = true
new_category.save!
post = create_post
old_category_id = post.topic.category_id
post.revise(post.user, category_id: new_category.id)
expect(post.reload.topic.category_id).to eq(old_category_id)
new_category.custom_fields[Category::REQUIRE_TOPIC_APPROVAL] = false
new_category.save!
post.revise(post.user, category_id: new_category.id)
expect(post.reload.topic.category_id).to eq(new_category.id)
end
end
context 'revise wiki' do