FIX: Endless loading post history (#28425)

This commit is contained in:
Jan Cernik 2024-08-27 07:33:13 -05:00 committed by GitHub
parent d05d23f947
commit 437d7a0ad1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 92 additions and 3 deletions

View File

@ -24,6 +24,7 @@ export default class History extends Component {
@service site;
@service currentUser;
@service siteSettings;
@service appEvents;
@tracked loading;
@tracked postRevision;
@ -169,13 +170,29 @@ export default class History extends Component {
}
}
refresh(postId, postVersion) {
async refresh(postId, postVersion) {
this.loading = true;
Post.loadRevision(postId, postVersion).then((result) => {
try {
const result = await Post.loadRevision(postId, postVersion);
this.postRevision = result;
} catch (error) {
this.args.closeModal();
this.dialog.alert(error.jqXHR.responseJSON.errors[0]);
const postStream = this.args.model.post?.topic?.postStream;
if (!postStream) {
return;
}
postStream
.triggerChangedPost(postId, this.args.model)
.then(() =>
this.appEvents.trigger("post-stream:refresh", { id: postId })
);
} finally {
this.loading = false;
this.initialLoad = false;
});
}
}
hide(postId, postVersion) {

View File

@ -1,6 +1,8 @@
import { click, visit } from "@ember/test-helpers";
import { test } from "qunit";
import topicFixtures from "discourse/tests/fixtures/topic";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { cloneJSON } from "discourse-common/lib/object";
const revisionResponse = {
created_at: "2021-11-24T10:59:36.163Z",
@ -101,3 +103,34 @@ acceptance("History Modal - anonymous", function (needs) {
);
});
});
acceptance("History Modal - not found", function (needs) {
needs.pretender((server, helper) => {
const json = cloneJSON(topicFixtures["/t/280/1.json"]);
json.post_stream.posts[0].version = 2;
json.post_stream.posts[0].can_view_edit_history = true;
server.get("/t/280.json", () => helper.response(json));
server.get("/t/280/:post_number.json", () => {
helper.response(json);
});
server.get("/posts/398/revisions/latest.json", () => {
return helper.response(404, {
errors: ["The requested URL or resource could not be found."],
error_type: "not_found",
});
});
});
test("try to view a nonexistent revision", async function (assert) {
await visit("/t/internationalization-localization/280");
await click("article[data-post-id='398'] .edits button");
assert.dom(".dialog-body").exists();
await click(".dialog-footer .btn-primary");
assert
.dom("article[data-post-id='398'] .edits button")
.doesNotExist("it should refresh the post to hide the revisions button");
});
});

View File

@ -469,6 +469,8 @@ class PostsController < ApplicationController
post.public_version -= 1
post.save
post.publish_change_to_clients!(:revised)
render body: nil
end
@ -509,6 +511,8 @@ class PostsController < ApplicationController
post.public_version += 1
post.save
post.publish_change_to_clients!(:revised)
render body: nil
end

View File

@ -2105,6 +2105,41 @@ RSpec.describe PostsController do
end
end
context "when the history on a specific post is hidden" do
it "works when hiding a revision" do
sign_in(admin)
message =
MessageBus
.track_publish("/topic/#{post.topic.id}") do
put "/posts/#{post_revision.post_id}/revisions/#{post_revision.number}/hide"
end
.first
expect(response.status).to eq(200)
expect(message.data[:type]).to eq(:revised)
expect(message.data[:version]).to eq(2)
expect(post_revision.reload[:hidden]).to eq(true)
end
it "works when showing a revision" do
post_revision.update!(hidden: true)
sign_in(admin)
message =
MessageBus
.track_publish("/topic/#{post.topic.id}") do
put "/posts/#{post_revision.post_id}/revisions/#{post_revision.number}/show"
end
.first
expect(response.status).to eq(200)
expect(message.data[:type]).to eq(:revised)
expect(message.data[:version]).to eq(2)
expect(post_revision.reload[:hidden]).to eq(false)
end
end
context "when post is hidden" do
before do
post.hidden = true