A platform for community discussion. Free, open, simple.
FIX: Display pending posts in a moderated category
Loïc Guitautd0888c190e50
diff --git a/app/serializers/topic_view_serializer.rb b/app/serializers/topic_view_serializer.rbindex b300b368026..0d717fa2b5a 100644--- a/app/serializers/topic_view_serializer.rb+++ b/app/serializers/topic_view_serializer.rb@@ -244,7 +244,7 @@ class TopicViewSerializer < ApplicationSerializeralias_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?enddef queued_posts_count@@ -252,7 +252,7 @@ class TopicViewSerializer < ApplicationSerializerenddef include_queued_posts_count?- scope.is_staff? && object.queued_posts_enabled+ scope.is_staff? && object.queued_posts_enabled?enddef show_read_indicatordiff --git a/lib/topic_view.rb b/lib/topic_view.rbindex 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_enabledattr_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_size1000end@@ -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?enddiff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rbindex 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 dofab!(:user) { Fabricate(:user) }fab!(:moderator) { Fabricate(:moderator) }fab!(:admin) { Fabricate(:admin) }@@ -991,4 +991,38 @@ describe TopicView doexpect(topic_view.filtered_post_ids).to eq([post_2.id, post.id])endend++ 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+ endend