A platform for community discussion. Free, open, simple.
FIX: Ensure tag diffs use persisted topic tags (#35187)
Tethys Plex5dba734bc362
diff --git a/lib/post_revisor.rb b/lib/post_revisor.rbindex bd83e503bbd..c9dcc00bddc 100644--- a/lib/post_revisor.rb+++ b/lib/post_revisor.rb@@ -110,34 +110,38 @@ class PostRevisorif tc.guardian.can_tag_topics?prev_tags = tc.topic.tags.map(&:name)next if tags.blank? && prev_tags.blank?+if !DiscourseTagging.tag_topic_by_names(tc.topic, tc.guardian, tags)tc.check_result(false)nextend- if prev_tags.sort != tags.sort- tc.record_change("tags", prev_tags, tags)++ new_tags = tc.topic.tags.map(&:name)++ if prev_tags.sort != new_tags.sort+ tc.record_change("tags", prev_tags, new_tags)DB.after_commit do- post = tc.topic.ordered_posts.first+ topic = tc.topic.reload+ post = topic.ordered_posts.firstnotified_user_ids = [post.user_id, post.last_editor_id].uniq- added_tags = tags - prev_tags- removed_tags = prev_tags - tags-- if !SiteSetting.disable_tags_edit_notifications- Jobs.enqueue(- :notify_tag_change,- post_id: post.id,- notified_user_ids: notified_user_ids,- diff_tags: (added_tags | removed_tags),+ persisted_tag_names = topic.tags.pluck(:name)+ added_tags = persisted_tag_names - prev_tags+ removed_tags = prev_tags - persisted_tag_names+ diff_tags = added_tags | removed_tags++ if diff_tags.present?+ if !SiteSetting.disable_tags_edit_notifications+ Jobs.enqueue(:notify_tag_change, post_id: post.id, notified_user_ids:, diff_tags:)+ end++ create_small_action_for_tag_changes(+ topic: topic,+ user: tc.user,+ added_tags:,+ removed_tags:,)end-- create_small_action_for_tag_changes(- topic: tc.topic,- user: tc.user,- added_tags: added_tags,- removed_tags: removed_tags,- )endendenddiff --git a/spec/lib/post_revisor_spec.rb b/spec/lib/post_revisor_spec.rbindex eef2f2ef646..cbac1d300ce 100644--- a/spec/lib/post_revisor_spec.rb+++ b/spec/lib/post_revisor_spec.rb@@ -303,6 +303,24 @@ describe PostRevisor doexpect(post.topic.ordered_posts.last.post_type).to eq(Post.types[:whisper])end+ it "does not create a small_action or notification when a restricted tag is rejected" do+ allowed_tag = Fabricate(:tag, name: "allowed-tag")++ post.topic.update!(tags: [allowed_tag])++ category = post.topic.category+ category.update!(allow_global_tags: false)+ category.tags = [allowed_tag]+ category.save!++ expect do+ post_revisor.revise!(admin, tags: [allowed_tag.name, "disallowed-tag"])+ end.not_to change { Post.where(topic_id: post.topic_id, action_code: "tags_changed").count }++ expect(post.topic.reload.tags.pluck(:name)).to contain_exactly(allowed_tag.name)+ expect(Jobs::NotifyTagChange.jobs.size).to eq(0)+ end+describe "with PMs" dofab!(:pm, :private_message_topic)let(:first_post) { create_post(user: admin, topic: pm, allow_uncategorized_topics: false) }