FIX: only show edit history when navigating via edit notification for posts which have revisions and can have its edit history viewed (#26418)

This commit is contained in:
Kelv 2024-04-01 11:00:28 +08:00 committed by GitHub
parent a84757fd91
commit 07605e52c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 123 additions and 54 deletions

View File

@ -172,11 +172,10 @@ export default Controller.extend(bufferedProperty("model"), {
_showRevision(postNumber, revision) { _showRevision(postNumber, revision) {
const post = this.model.get("postStream").postForPostNumber(postNumber); const post = this.model.get("postStream").postForPostNumber(postNumber);
if (!post) {
return;
}
if (post && post.version > 1 && post.can_view_edit_history) {
schedule("afterRender", () => this.send("showHistory", post, revision)); schedule("afterRender", () => this.send("showHistory", post, revision));
}
}, },
showCategoryChooser: not("model.isPrivateMessage"), showCategoryChooser: not("model.isPrivateMessage"),

View File

@ -1,12 +1,10 @@
import { click, visit } from "@ember/test-helpers"; import { click, visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import topicFixtures from "discourse/tests/fixtures/topic";
import { acceptance, queryAll } from "discourse/tests/helpers/qunit-helpers"; import { acceptance, queryAll } from "discourse/tests/helpers/qunit-helpers";
import { cloneJSON } from "discourse-common/lib/object";
acceptance("Edit Notification Click", function (needs) { const revisionResponse = {
needs.user();
needs.pretender((server, helper) => {
server.get("/posts/133/revisions/1.json", () => {
return helper.response({
created_at: "2021-07-30T11:19:59.549Z", created_at: "2021-07-30T11:19:59.549Z",
post_id: 133, post_id: 133,
previous_hidden: false, previous_hidden: false,
@ -34,7 +32,20 @@ acceptance("Edit Notification Click", function (needs) {
user_changes: null, user_changes: null,
wiki: false, wiki: false,
can_edit: true, can_edit: true,
}); };
acceptance(
"Edit Notification Click - when post revisions are present",
function (needs) {
needs.user();
needs.pretender((server, helper) => {
const topicRef = "/t/130.json";
const topicResponse = cloneJSON(topicFixtures[topicRef]);
const originalPost = topicResponse.post_stream.posts[0];
originalPost.version = 2;
server.get(topicRef, () => helper.response(topicResponse));
server.get(`/posts/${originalPost.id}/revisions/1.json`, () => {
return helper.response(revisionResponse);
}); });
}); });
@ -56,4 +67,63 @@ acceptance("Edit Notification Click", function (needs) {
"history modal for the edited post is shown" "history modal for the edited post is shown"
); );
}); });
}); }
);
acceptance(
"Edit Notification Click - when post has no revisions",
function (needs) {
needs.user();
needs.pretender((server, helper) => {
const topicRef = "/t/130.json";
const topicResponse = cloneJSON(topicFixtures[topicRef]);
const originalPost = topicResponse.post_stream.posts[0];
originalPost.version = 1;
originalPost.can_view_edit_history = true;
server.get(topicRef, () => helper.response(topicResponse));
server.get(`/posts/${originalPost.id}/revisions/1.json`, () => {
return helper.response(revisionResponse);
});
});
test("history modal is not shown when navigating from a non-topic page", async function (assert) {
await visit("/");
await click(".header-dropdown-toggle.current-user");
await click(".notification.edited a");
assert
.dom(".history-modal")
.doesNotExist(
"history modal should not open for post on its first version"
);
});
}
);
acceptance(
"Edit Notification Click - when post edit history cannot be viewed",
function (needs) {
needs.user();
needs.pretender((server, helper) => {
const topicRef = "/t/130.json";
const topicResponse = cloneJSON(topicFixtures[topicRef]);
const originalPost = topicResponse.post_stream.posts[0];
originalPost.version = 2;
originalPost.can_view_edit_history = false;
server.get(topicRef, () => helper.response(topicResponse));
server.get(`/posts/${originalPost.id}/revisions/1.json`, () => {
return helper.response(revisionResponse);
});
});
test("history modal is not shown when navigating from a non-topic page", async function (assert) {
await visit("/");
await click(".header-dropdown-toggle.current-user");
await click(".notification.edited a");
assert
.dom(".history-modal")
.doesNotExist(
"history modal should not open for post which cannot have edit history viewed"
);
});
}
);