A platform for community discussion. Free, open, simple.
FIX: Keep scheduled publish pending when category rejects a tag (#44166)
Alan Guo Xiang Tan0f0e70998ca4
diff --git a/lib/topic_publisher.rb b/lib/topic_publisher.rbindex c18285457b7..6835e4d6609 100644--- a/lib/topic_publisher.rb+++ b/lib/topic_publisher.rb@@ -15,11 +15,13 @@ class TopicPublisher.change! doif @topic.private_message?@topic = TopicConverter.new(@topic, @published_by).convert_to_public_topic(@category_id)- else- PostRevisor.new(@topic.first_post, @topic).revise!(- @published_by,- category_id: @category_id,- )+ elsif @topic.category_id != @category_id+ revised =+ PostRevisor.new(@topic.first_post, @topic).revise!(+ @published_by,+ category_id: @category_id,+ )+ raise ActiveRecord::RecordInvalid.new(@topic) unless revisedend@topic.update_columns(visible: true)diff --git a/spec/jobs/publish_topic_to_category_spec.rb b/spec/jobs/publish_topic_to_category_spec.rbindex 65d2bf9317d..525fc934784 100644--- a/spec/jobs/publish_topic_to_category_spec.rb+++ b/spec/jobs/publish_topic_to_category_spec.rb@@ -62,6 +62,51 @@ RSpec.describe Jobs::PublishTopicToCategory doendend+ it "keeps the publishing timer when the destination rejects a topic tag" do+ user = Fabricate(:trust_level_4)++ forbidden_tag = Fabricate(:tag)+ allowed_tag = Fabricate(:tag)+ allowed_tag_group = Fabricate(:tag_group, tags: [allowed_tag])+ another_category.update!(tag_groups: [allowed_tag_group])++ topic.update!(user: user, tags: [forbidden_tag], visible: false, created_at: 1.hour.ago)+ timer = topic.public_topic_timer+ timer.update!(user: user)+ timestamp_attributes = %w[created_at bumped_at updated_at last_posted_at]+ original_timestamps = topic.reload.attributes.slice(*timestamp_attributes)++ expect { described_class.new.execute(topic_timer_id: timer.id) }.to raise_error(+ ActiveRecord::RecordInvalid,+ )++ topic.reload+ expect(topic.category).to eq(category)+ expect(topic).not_to be_visible+ expect(topic.attributes.slice(*timestamp_attributes)).to eq(original_timestamps)+ expect(topic.public_topic_timer).to eq(timer)+ expect(+ UserHistory.exists?(+ action: UserHistory.actions[:topic_published],+ acting_user_id: user.id,+ topic_id: topic.id,+ ),+ ).to eq(false)+ end++ it "publishes when the topic is already in the destination category" do+ topic.update!(visible: false)+ timer = topic.public_topic_timer+ timer.update!(category_id: category.id)++ described_class.new.execute(topic_timer_id: timer.id)++ topic.reload+ expect(topic.category).to eq(category)+ expect(topic).to be_visible+ expect(topic.public_topic_timer).to be_nil+ end+describe "when topic is a private message" doit "publishes the topic to the new category" dofreeze_time 1.hour.ago do