mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 08:43:25 +08:00
FIX: Display pending posts in a moderated category
Currently we display pending posts in topics (both for author and staff members) but the feature is only enabled when there’s an enabled global site setting related to moderation. This patch allows to have the same behavior for a site where there’s nothing enabled globally but where a moderated category exists. So when browsing a topic of a moderated category, the presence of pending posts will be checked whereas nothing will happen in a normal category.
This commit is contained in:
parent
412a6c0e8c
commit
d0888c190e
|
@ -244,7 +244,7 @@ class TopicViewSerializer < ApplicationSerializer
|
|||
alias_method :include_is_shared_draft?, :include_destination_category_id?
|
||||
|
||||
def include_pending_posts?
|
||||
scope.authenticated? && object.queued_posts_enabled
|
||||
scope.authenticated? && object.queued_posts_enabled?
|
||||
end
|
||||
|
||||
def queued_posts_count
|
||||
|
@ -252,7 +252,7 @@ class TopicViewSerializer < ApplicationSerializer
|
|||
end
|
||||
|
||||
def include_queued_posts_count?
|
||||
scope.is_staff? && object.queued_posts_enabled
|
||||
scope.is_staff? && object.queued_posts_enabled?
|
||||
end
|
||||
|
||||
def show_read_indicator
|
||||
|
|
|
@ -35,6 +35,7 @@ class TopicView
|
|||
:personal_message,
|
||||
:can_review_topic
|
||||
)
|
||||
alias queued_posts_enabled? queued_posts_enabled
|
||||
|
||||
attr_accessor(
|
||||
:draft,
|
||||
|
@ -45,6 +46,9 @@ class TopicView
|
|||
:post_number
|
||||
)
|
||||
|
||||
delegate :category, to: :topic, allow_nil: true, private: true
|
||||
delegate :require_reply_approval?, to: :category, prefix: true, allow_nil: true, private: true
|
||||
|
||||
def self.print_chunk_size
|
||||
1000
|
||||
end
|
||||
|
@ -146,7 +150,7 @@ class TopicView
|
|||
@draft_sequence = DraftSequence.current(@user, @draft_key)
|
||||
|
||||
@can_review_topic = @guardian.can_review_topic?(@topic)
|
||||
@queued_posts_enabled = NewPostManager.queue_enabled?
|
||||
@queued_posts_enabled = NewPostManager.queue_enabled? || category_require_reply_approval?
|
||||
@personal_message = @topic.private_message?
|
||||
end
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
require 'rails_helper'
|
||||
require 'topic_view'
|
||||
|
||||
describe TopicView do
|
||||
RSpec.describe TopicView do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:moderator) { Fabricate(:moderator) }
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
|
@ -991,4 +991,38 @@ describe TopicView do
|
|||
expect(topic_view.filtered_post_ids).to eq([post_2.id, post.id])
|
||||
end
|
||||
end
|
||||
|
||||
describe "#queued_posts_enabled?" do
|
||||
subject(:topic_view) { described_class.new(topic, user) }
|
||||
|
||||
let(:topic) { Fabricate.build(:topic) }
|
||||
let(:user) { Fabricate.build(:user, id: 1) }
|
||||
let(:category) { topic.category }
|
||||
|
||||
before do
|
||||
NewPostManager.stubs(:queue_enabled?).returns(queue_enabled)
|
||||
end
|
||||
|
||||
context "when queue is enabled globally" do
|
||||
let(:queue_enabled) { true }
|
||||
|
||||
it { is_expected.to be_queued_posts_enabled }
|
||||
end
|
||||
|
||||
context "when queue is not enabled globally" do
|
||||
let(:queue_enabled) { false }
|
||||
|
||||
context "when category is moderated" do
|
||||
before do
|
||||
category.custom_fields[Category::REQUIRE_REPLY_APPROVAL] = true
|
||||
end
|
||||
|
||||
it { is_expected.to be_queued_posts_enabled }
|
||||
end
|
||||
|
||||
context "when category is not moderated" do
|
||||
it { is_expected.not_to be_queued_posts_enabled }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user