diff --git a/app/serializers/topic_view_serializer.rb b/app/serializers/topic_view_serializer.rb index b300b368026..0d717fa2b5a 100644 --- a/app/serializers/topic_view_serializer.rb +++ b/app/serializers/topic_view_serializer.rb @@ -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 diff --git a/lib/topic_view.rb b/lib/topic_view.rb index d5014768ef0..4c8d4ac2331 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -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 diff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rb index 2a209e47fa6..d29a9f213be 100644 --- a/spec/components/topic_view_spec.rb +++ b/spec/components/topic_view_spec.rb @@ -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