mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE - allow category group moderators to split/merge topics (#10351)
This commit is contained in:
@@ -99,6 +99,8 @@ RSpec.describe TopicsController do
|
||||
end
|
||||
|
||||
context 'success' do
|
||||
fab!(:category) { Fabricate(:category) }
|
||||
|
||||
before { sign_in(admin) }
|
||||
|
||||
it "returns success" do
|
||||
@@ -106,7 +108,7 @@ RSpec.describe TopicsController do
|
||||
post "/t/#{topic.id}/move-posts.json", params: {
|
||||
title: 'Logan is a good movie',
|
||||
post_ids: [p2.id],
|
||||
category_id: 123,
|
||||
category_id: category.id,
|
||||
tags: ["tag1", "tag2"]
|
||||
}
|
||||
end.to change { Topic.count }.by(1)
|
||||
@@ -130,7 +132,7 @@ RSpec.describe TopicsController do
|
||||
post "/t/#{topic.id}/move-posts.json", params: {
|
||||
title: 'Logan is a good movie',
|
||||
post_ids: [p2.id],
|
||||
category_id: 123
|
||||
category_id: category.id
|
||||
}
|
||||
end.to change { Topic.count }.by(1)
|
||||
|
||||
@@ -185,6 +187,59 @@ RSpec.describe TopicsController do
|
||||
end
|
||||
end
|
||||
|
||||
describe "moving to a new topic as a group moderator" do
|
||||
fab!(:group_user) { Fabricate(:group_user) }
|
||||
fab!(:category) { Fabricate(:category, reviewable_by_group: group_user.group) }
|
||||
fab!(:topic) { Fabricate(:topic, category: category) }
|
||||
fab!(:p1) { Fabricate(:post, user: group_user.user, post_number: 1, topic: topic) }
|
||||
fab!(:p2) { Fabricate(:post, user: group_user.user, post_number: 2, topic: topic) }
|
||||
let(:user) { group_user.user }
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
SiteSetting.enable_category_group_moderation = true
|
||||
end
|
||||
|
||||
it "moves the posts" do
|
||||
expect do
|
||||
post "/t/#{topic.id}/move-posts.json", params: {
|
||||
title: 'Logan is a good movie',
|
||||
post_ids: [p2.id],
|
||||
category_id: category.id
|
||||
}
|
||||
end.to change { Topic.count }.by(1)
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
result = response.parsed_body
|
||||
expect(result['success']).to eq(true)
|
||||
expect(result['url']).to eq(Topic.last.relative_url)
|
||||
end
|
||||
|
||||
it "does not allow posts to be moved to a private category" do
|
||||
staff_category = Fabricate(:category)
|
||||
staff_category.set_permissions(staff: :full)
|
||||
staff_category.save!
|
||||
|
||||
post "/t/#{topic.id}/move-posts.json", params: {
|
||||
title: 'Logan is a good movie',
|
||||
post_ids: [p2.id],
|
||||
category_id: staff_category.id
|
||||
}
|
||||
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it "does not allow posts outside of the category to be moved" do
|
||||
topic.update!(category: nil)
|
||||
|
||||
post "/t/#{topic.id}/move-posts.json", params: {
|
||||
title: 'blah', post_ids: [p1.post_number, p2.post_number]
|
||||
}
|
||||
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
end
|
||||
|
||||
describe 'moving to an existing topic' do
|
||||
let!(:user) { sign_in(moderator) }
|
||||
let(:p1) { Fabricate(:post, user: user) }
|
||||
@@ -246,6 +301,59 @@ RSpec.describe TopicsController do
|
||||
end
|
||||
end
|
||||
|
||||
describe "moving to an existing topic as a group moderator" do
|
||||
fab!(:group_user) { Fabricate(:group_user) }
|
||||
fab!(:category) { Fabricate(:category, reviewable_by_group: group_user.group) }
|
||||
fab!(:topic) { Fabricate(:topic, category: category) }
|
||||
fab!(:p1) { Fabricate(:post, user: group_user.user, post_number: 1, topic: topic) }
|
||||
fab!(:p2) { Fabricate(:post, user: group_user.user, post_number: 2, topic: topic) }
|
||||
fab!(:dest_topic) { Fabricate(:topic) }
|
||||
|
||||
let(:user) { group_user.user }
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
SiteSetting.enable_category_group_moderation = true
|
||||
end
|
||||
|
||||
it "moves the posts" do
|
||||
post "/t/#{topic.id}/move-posts.json", params: {
|
||||
post_ids: [p2.id],
|
||||
destination_topic_id: dest_topic.id
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
result = response.parsed_body
|
||||
expect(result['success']).to eq(true)
|
||||
expect(result['url']).to be_present
|
||||
end
|
||||
|
||||
it "does not allow posts to be moved to a private category" do
|
||||
staff_category = Fabricate(:category)
|
||||
staff_category.set_permissions(staff: :full)
|
||||
staff_category.save!
|
||||
dest_topic.update!(category: staff_category)
|
||||
|
||||
post "/t/#{topic.id}/move-posts.json", params: {
|
||||
post_ids: [p2.id],
|
||||
destination_topic_id: dest_topic.id
|
||||
}
|
||||
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it "does not allow posts outside of the category to be moved" do
|
||||
topic.update!(category: nil)
|
||||
|
||||
post "/t/#{topic.id}/move-posts.json", params: {
|
||||
post_ids: [p1.post_number, p2.post_number],
|
||||
destination_topic_id: dest_topic.id
|
||||
}
|
||||
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
end
|
||||
|
||||
describe 'moving to a new message' do
|
||||
let!(:message) { Fabricate(:private_message_topic) }
|
||||
let!(:p1) { Fabricate(:post, user: user, post_number: 1, topic: message) }
|
||||
@@ -417,6 +525,55 @@ RSpec.describe TopicsController do
|
||||
end
|
||||
end
|
||||
|
||||
describe "merging into another topic as a group moderator" do
|
||||
fab!(:group_user) { Fabricate(:group_user) }
|
||||
fab!(:category) { Fabricate(:category, reviewable_by_group: group_user.group) }
|
||||
fab!(:topic) { Fabricate(:topic, category: category) }
|
||||
fab!(:p1) { Fabricate(:post, post_number: 1, topic: topic) }
|
||||
fab!(:p2) { Fabricate(:post, post_number: 2, topic: topic) }
|
||||
fab!(:dest_topic) { Fabricate(:topic) }
|
||||
let(:user) { group_user.user }
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
SiteSetting.enable_category_group_moderation = true
|
||||
end
|
||||
|
||||
it "moves the posts" do
|
||||
post "/t/#{topic.id}/merge-topic.json", params: {
|
||||
destination_topic_id: dest_topic.id
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
result = response.parsed_body
|
||||
expect(result['success']).to eq(true)
|
||||
expect(result['url']).to be_present
|
||||
end
|
||||
|
||||
it "does not allow posts to be moved to a private category" do
|
||||
staff_category = Fabricate(:category)
|
||||
staff_category.set_permissions(staff: :full)
|
||||
staff_category.save!
|
||||
dest_topic.update!(category: staff_category)
|
||||
|
||||
post "/t/#{topic.id}/merge-topic.json", params: {
|
||||
destination_topic_id: dest_topic.id
|
||||
}
|
||||
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it "does not allow posts outside of the category to be moved" do
|
||||
topic.update!(category: nil)
|
||||
|
||||
post "/t/#{topic.id}/merge-topic.json", params: {
|
||||
destination_topic_id: dest_topic.id
|
||||
}
|
||||
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
end
|
||||
|
||||
describe 'merging into another message' do
|
||||
let(:message) { Fabricate(:private_message_topic, user: user) }
|
||||
let!(:p1) { Fabricate(:post, topic: message, user: trust_level_4) }
|
||||
@@ -708,9 +865,7 @@ RSpec.describe TopicsController do
|
||||
fab!(:group_user) { Fabricate(:group_user) }
|
||||
fab!(:category) { Fabricate(:category, reviewable_by_group: group_user.group) }
|
||||
fab!(:topic) { Fabricate(:topic, category: category) }
|
||||
|
||||
let(:user) { group_user.user }
|
||||
let(:group) { group_user.group }
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
@@ -743,7 +898,6 @@ RSpec.describe TopicsController do
|
||||
expect(response.status).to eq(403)
|
||||
expect(topic.reload.pinned_at).to eq(nil)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user