FIX: Skip shared drafts logic if disabled (#11918)

It always showed shared drafts if no category was set.

Follow-up to dd175537f3.
This commit is contained in:
Dan Ungureanu 2021-02-01 20:29:04 +02:00 committed by GitHub
parent 0f31a221c9
commit 4b3d34d3d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View File

@ -58,7 +58,7 @@ class ListController < ApplicationController
list = TopicQuery.new(user, list_opts).public_send("list_#{filter}")
if guardian.can_see_shared_draft? && @category.present?
if guardian.can_create_shared_draft? && @category.present?
if @category.id == SiteSetting.shared_drafts_category.to_i
# On shared drafts, show the destination category
list.topics.each do |t|

View File

@ -779,4 +779,37 @@ RSpec.describe ListController do
end
end
end
describe "shared drafts" do
fab!(:category1) { Fabricate(:category) }
fab!(:category2) { Fabricate(:category) }
fab!(:topic1) { Fabricate(:topic, category: category1) }
fab!(:topic2) { Fabricate(:topic, category: category2) }
fab!(:shared_draft_topic) { Fabricate(:topic, category: category1) }
fab!(:shared_draft) { Fabricate(:shared_draft, topic: shared_draft_topic, category: category2) }
it "are not displayed if they are disabled" do
SiteSetting.shared_drafts_category = ""
sign_in(admin)
get "/c/#{category1.slug}/#{category1.id}.json"
expect(response.parsed_body['topic_list']['shared_drafts']).to eq(nil)
expect(response.parsed_body['topic_list']['topics'].map { |t| t['id'] }).to contain_exactly(topic1.id, shared_draft_topic.id)
end
it "are displayed in both shared drafts category and target category" do
SiteSetting.shared_drafts_category = category1.id
sign_in(admin)
get "/c/#{category1.slug}/#{category1.id}.json"
expect(response.parsed_body['topic_list']['shared_drafts']).to be_nil
expect(response.parsed_body['topic_list']['topics'].map { |t| t['id'] }).to contain_exactly(topic1.id, shared_draft_topic.id)
get "/c/#{category2.slug}/#{category2.id}.json"
expect(response.parsed_body['topic_list']['shared_drafts'].map { |t| t['id'] }).to contain_exactly(shared_draft_topic.id)
expect(response.parsed_body['topic_list']['topics'].map { |t| t['id'] }).to contain_exactly(topic2.id)
end
end
end