FIX: Do not attempt to serialize Tag objects when tagging disabled (#18264)

When tagging is enabled, we were correctly serializing tags by their name. However, when tagging was disabled we were attempting to serialize an entire Tag object which raises an error since ee07f6da7d.

https://meta.discourse.org/t/232885
This commit is contained in:
David Taylor 2022-09-15 16:17:48 +01:00 committed by GitHub
parent 87f8bafa7e
commit 3e8b6c67ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -208,6 +208,7 @@ class PostRevisionSerializer < ApplicationSerializer
# Retrieve any `tracked_topic_fields`
PostRevisor.tracked_topic_fields.each_key do |field|
next if field == :tags # Special handling below
if topic.respond_to?(field)
latest_modifications[field.to_s] = [topic.public_send(field)]
end

View File

@ -1750,6 +1750,23 @@ RSpec.describe PostsController do
expect(response.status).to eq(200)
end
end
context "with a tagged topic" do
let(:tag) { Fabricate(:tag) }
it "works" do
SiteSetting.tagging_enabled = true
post_revision.post.topic.update(tags: [tag])
get "/posts/#{post_revision.post_id}/revisions/latest.json"
expect(response.status).to eq(200)
SiteSetting.tagging_enabled = false
get "/posts/#{post_revision.post_id}/revisions/latest.json"
expect(response.status).to eq(200)
end
end
end
describe '#revert' do