FIX: better edit conflict handling (#29789)

* FIX: better edit conflict handling

Properly keep track of the original title and tags when dealing with edit conflicts.

Internal ref - t/141218
This commit is contained in:
Régis Hanol
2024-12-03 10:12:04 +01:00
committed by GitHub
parent 89a6cac968
commit 806e37aaec
8 changed files with 150 additions and 52 deletions

View File

@ -96,16 +96,26 @@ class DraftsController < ApplicationController
json = success_json.merge(draft_sequence: sequence)
if data.present?
# this is a bit of a kludge we need to remove (all the parsing) too many special cases here
# we need to catch action edit and action editSharedDraft
if data["postId"].present? && data["originalText"].present? &&
data["action"].to_s.start_with?("edit")
post = Post.find_by(id: data["postId"])
if post && post.raw != data["originalText"]
conflict_user = BasicUserSerializer.new(post.last_editor, root: false)
render json: json.merge(conflict_user: conflict_user)
return
# check for conflicts when editing a post
if data.present? && data["postId"].present? && data["action"].to_s.start_with?("edit")
original_text = data["original_text"] || data["originalText"]
original_title = data["original_title"]
original_tags = data["original_tags"]
if original_text.present?
if post = Post.find_by(id: data["postId"])
conflict = original_text != post.raw
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
end
if conflict
conflict_user = BasicUserSerializer.new(post.last_editor, root: false)
json.merge!(conflict_user:)
end
end
end
end