FIX: Update post's raw from server response (#13414)
The client used to update the raw, but sometimes the server changed the raw text, which resulted in false edit conflicts.
This commit is contained in:
parent
90bd88627a
commit
ea2833d0d8
|
@ -929,7 +929,6 @@ const Composer = RestModel.extend({
|
||||||
|
|
||||||
editPost(opts) {
|
editPost(opts) {
|
||||||
const post = this.post;
|
const post = this.post;
|
||||||
const oldRaw = post.raw;
|
|
||||||
const oldCooked = post.cooked;
|
const oldCooked = post.cooked;
|
||||||
let promise = Promise.resolve();
|
let promise = Promise.resolve();
|
||||||
|
|
||||||
|
@ -971,14 +970,14 @@ const Composer = RestModel.extend({
|
||||||
this.set("composeState", SAVING);
|
this.set("composeState", SAVING);
|
||||||
|
|
||||||
const rollback = throwAjaxError((error) => {
|
const rollback = throwAjaxError((error) => {
|
||||||
post.setProperties({ raw: oldRaw, cooked: oldCooked });
|
post.setProperties("cooked", oldCooked);
|
||||||
this.set("composeState", OPEN);
|
this.set("composeState", OPEN);
|
||||||
if (error.jqXHR && error.jqXHR.status === 409) {
|
if (error.jqXHR && error.jqXHR.status === 409) {
|
||||||
this.set("editConflict", true);
|
this.set("editConflict", true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
post.setProperties({ raw: props.raw, cooked: props.cooked, staged: true });
|
post.setProperties({ cooked: props.cooked, staged: true });
|
||||||
this.appEvents.trigger("post-stream:refresh", { id: post.id });
|
this.appEvents.trigger("post-stream:refresh", { id: post.id });
|
||||||
|
|
||||||
return promise
|
return promise
|
||||||
|
|
|
@ -247,7 +247,7 @@ class PostsController < ApplicationController
|
||||||
return render_json_error(post) if post.errors.present?
|
return render_json_error(post) if post.errors.present?
|
||||||
return render_json_error(topic) if topic.errors.present?
|
return render_json_error(topic) if topic.errors.present?
|
||||||
|
|
||||||
post_serializer = PostSerializer.new(post, scope: guardian, root: false)
|
post_serializer = PostSerializer.new(post, scope: guardian, root: false, add_raw: true)
|
||||||
post_serializer.draft_sequence = DraftSequence.current(current_user, topic.draft_key)
|
post_serializer.draft_sequence = DraftSequence.current(current_user, topic.draft_key)
|
||||||
link_counts = TopicLink.counts_for(guardian, topic, [post])
|
link_counts = TopicLink.counts_for(guardian, topic, [post])
|
||||||
post_serializer.single_post_link_counts = link_counts[post.id] if link_counts.present?
|
post_serializer.single_post_link_counts = link_counts[post.id] if link_counts.present?
|
||||||
|
|
|
@ -415,10 +415,11 @@ describe PostsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "updates post's raw attribute" do
|
it "updates post's raw attribute" do
|
||||||
put "/posts/#{post.id}.json", params: update_params
|
put "/posts/#{post.id}.json", params: { post: { raw: 'edited body ' } }
|
||||||
|
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(post.reload.raw).to eq(update_params[:post][:raw])
|
expect(response.parsed_body['post']['raw']).to eq('edited body')
|
||||||
|
expect(post.reload.raw).to eq('edited body')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "extracts links from the new body" do
|
it "extracts links from the new body" do
|
||||||
|
|
Loading…
Reference in New Issue