FIX: corrently handle hidden tags when checking for edit conflicts

In 806e37aaec549069a599fd31edc16c5cdcd0774e, I improved the conflict handling when editing a post to account for title and tags.

This fixes an edge cases when a topic has a hidden tag the current editor can't see. When they submit their edit, we automatically add the hidden tags before checking with the tags stored in the database.

Reported in https://meta.discourse.org/t/341375
This commit is contained in:
zogstrip
2024-12-09 18:50:57 +01:00
committed by Régis Hanol
parent 61f23b2d65
commit 6e54696003
2 changed files with 42 additions and 2 deletions

View File

@ -108,8 +108,15 @@ class DraftsController < ApplicationController
if post.post_number == 1
conflict ||= original_title.present? && original_title != post.topic.title
conflict ||=
original_tags.present? && original_tags.sort != post.topic.tags.pluck(:name).sort
# Since the topic might have hidden tags the current editor can't see,
# we need to check for conflicts even though there might not be any visible tags in the editor
if !conflict
original_tags = (original_tags || []).map(&:downcase).to_set
current_tags = post.topic.tags.pluck(:name).to_set
hidden_tags = DiscourseTagging.hidden_tag_names(@guardian).to_set
conflict = original_tags != (current_tags - hidden_tags)
end
end
if conflict