mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 14:38:17 +08:00
FIX: Endless loading post history (#28425)
This commit is contained in:
parent
d05d23f947
commit
437d7a0ad1
|
@ -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) {
|
||||
|
|
|
@ -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");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user