From 83dd47f0b46b11ea773e89523115ce055b89435c Mon Sep 17 00:00:00 2001 From: Roman Rizzi Date: Wed, 26 May 2021 15:43:18 -0300 Subject: [PATCH] FEATURE: Navigate to an approved queued topic from the review queue. (#12841) Admins can visit an approved queued topic from the review queue by clicking their title. We no longer store the created post and topic ids in the reviewable's payload object. Instead, we set the `topic_id` and `target_id` attributes. --- app/models/reviewable_queued_post.rb | 6 ++++-- ...pproved_queued_posts_topic_and_post_data.rb | 18 ++++++++++++++++++ spec/models/reviewable_queued_post_spec.rb | 6 +++--- 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20210426193009_move_approved_queued_posts_topic_and_post_data.rb diff --git a/app/models/reviewable_queued_post.rb b/app/models/reviewable_queued_post.rb index 8d108c67078..105559444c7 100644 --- a/app/models/reviewable_queued_post.rb +++ b/app/models/reviewable_queued_post.rb @@ -83,8 +83,10 @@ class ReviewableQueuedPost < Reviewable return create_result(:failure) { |r| r.errors = creator.errors } end - payload['created_post_id'] = created_post.id - payload['created_topic_id'] = created_post.topic_id unless topic_id + self.target = created_post + if topic_id.nil? + self.topic_id = created_post.topic_id + end save UserSilencer.unsilence(created_by, performed_by) if created_by.silenced? diff --git a/db/migrate/20210426193009_move_approved_queued_posts_topic_and_post_data.rb b/db/migrate/20210426193009_move_approved_queued_posts_topic_and_post_data.rb new file mode 100644 index 00000000000..b2f548edc7b --- /dev/null +++ b/db/migrate/20210426193009_move_approved_queued_posts_topic_and_post_data.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class MoveApprovedQueuedPostsTopicAndPostData < ActiveRecord::Migration[6.1] + def up + DB.query_single <<~SQL + UPDATE reviewables r + SET topic_id = (payload->>'created_topic_id')::int, target_id = (payload->>'created_post_id')::int, target_type = 'Post' + WHERE r.type = 'ReviewableQueuedPost' AND r.status = 1 + AND (r.payload->>'created_topic_id') IS NOT NULL + AND (r.payload->>'created_post_id') IS NOT NULL + AND topic_id IS NULL + AND target_id IS NULL + SQL + end + + def down + end +end diff --git a/spec/models/reviewable_queued_post_spec.rb b/spec/models/reviewable_queued_post_spec.rb index 73125443b97..97e5b61b76d 100644 --- a/spec/models/reviewable_queued_post_spec.rb +++ b/spec/models/reviewable_queued_post_spec.rb @@ -61,7 +61,7 @@ RSpec.describe ReviewableQueuedPost, type: :model do expect(result.created_post.custom_fields['hello']).to eq('world') expect(result.created_post_topic).to eq(topic) expect(result.created_post.user).to eq(reviewable.created_by) - expect(reviewable.payload['created_post_id']).to eq(result.created_post.id) + expect(reviewable.target_id).to eq(result.created_post.id) expect(Topic.count).to eq(topic_count) expect(Post.count).to eq(post_count + 1) @@ -183,8 +183,8 @@ RSpec.describe ReviewableQueuedPost, type: :model do expect(result.created_post).to be_valid expect(result.created_post_topic).to be_present expect(result.created_post_topic).to be_valid - expect(reviewable.payload['created_post_id']).to eq(result.created_post.id) - expect(reviewable.payload['created_topic_id']).to eq(result.created_post_topic.id) + expect(reviewable.target_id).to eq(result.created_post.id) + expect(reviewable.topic_id).to eq(result.created_post_topic.id) expect(Topic.count).to eq(topic_count + 1) expect(Post.count).to eq(post_count + 1)