mirror of
https://github.com/discourse/discourse.git
synced 2025-05-10 01:43:06 +08:00
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:
parent
a84757fd91
commit
07605e52c2
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
schedule("afterRender", () => this.send("showHistory", post, revision));
|
if (post && post.version > 1 && post.can_view_edit_history) {
|
||||||
|
schedule("afterRender", () => this.send("showHistory", post, revision));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
showCategoryChooser: not("model.isPrivateMessage"),
|
showCategoryChooser: not("model.isPrivateMessage"),
|
||||||
|
@ -1,59 +1,129 @@
|
|||||||
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();
|
created_at: "2021-07-30T11:19:59.549Z",
|
||||||
needs.pretender((server, helper) => {
|
post_id: 133,
|
||||||
server.get("/posts/133/revisions/1.json", () => {
|
previous_hidden: false,
|
||||||
return helper.response({
|
current_hidden: false,
|
||||||
created_at: "2021-07-30T11:19:59.549Z",
|
first_revision: 2,
|
||||||
post_id: 133,
|
previous_revision: null,
|
||||||
previous_hidden: false,
|
current_revision: 2,
|
||||||
current_hidden: false,
|
next_revision: null,
|
||||||
first_revision: 2,
|
last_revision: 2,
|
||||||
previous_revision: null,
|
current_version: 2,
|
||||||
current_revision: 2,
|
version_count: 2,
|
||||||
next_revision: null,
|
username: "velesin",
|
||||||
last_revision: 2,
|
display_username: "velesin",
|
||||||
current_version: 2,
|
avatar_template: "/letter_avatar_proxy/v4/letter/j/13edae/{size}.png",
|
||||||
version_count: 2,
|
edit_reason: null,
|
||||||
username: "velesin",
|
body_changes: {
|
||||||
display_username: "velesin",
|
inline:
|
||||||
avatar_template: "/letter_avatar_proxy/v4/letter/j/13edae/{size}.png",
|
'<div class="inline-diff"><p>Hello world this is a test</p><p class="diff-ins">another edit!</p></div>',
|
||||||
edit_reason: null,
|
side_by_side:
|
||||||
body_changes: {
|
'<div class="revision-content"><p>Hello world this is a test</p></div><div class="revision-content"><p>Hello world this is a test</p><p class="diff-ins">This is an edit!</p></div>',
|
||||||
inline:
|
side_by_side_markdown:
|
||||||
'<div class="inline-diff"><p>Hello world this is a test</p><p class="diff-ins">another edit!</p></div>',
|
'<table class="markdown"><tr><td class="diff-del">Hello world this is a test</td><td class="diff-ins">Hello world this is a test<ins>\n\nThis is an edit!</ins></td></tr></table>',
|
||||||
side_by_side:
|
},
|
||||||
'<div class="revision-content"><p>Hello world this is a test</p></div><div class="revision-content"><p>Hello world this is a test</p><p class="diff-ins">This is an edit!</p></div>',
|
title_changes: null,
|
||||||
side_by_side_markdown:
|
user_changes: null,
|
||||||
'<table class="markdown"><tr><td class="diff-del">Hello world this is a test</td><td class="diff-ins">Hello world this is a test<ins>\n\nThis is an edit!</ins></td></tr></table>',
|
wiki: false,
|
||||||
},
|
can_edit: true,
|
||||||
title_changes: null,
|
};
|
||||||
user_changes: null,
|
acceptance(
|
||||||
wiki: false,
|
"Edit Notification Click - when post revisions are present",
|
||||||
can_edit: true,
|
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
test("history modal is shown when navigating from a non-topic page", async function (assert) {
|
test("history modal is shown when navigating from a non-topic page", async function (assert) {
|
||||||
await visit("/");
|
await visit("/");
|
||||||
await click(".header-dropdown-toggle.current-user");
|
await click(".header-dropdown-toggle.current-user");
|
||||||
await click(".notification.edited a");
|
await click(".notification.edited a");
|
||||||
const [v1, v2] = queryAll(".history-modal .revision-content");
|
const [v1, v2] = queryAll(".history-modal .revision-content");
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
v1.textContent.trim(),
|
v1.textContent.trim(),
|
||||||
"Hello world this is a test",
|
"Hello world this is a test",
|
||||||
"history modal for the edited post is shown"
|
"history modal for the edited post is shown"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
v2.textContent.trim(),
|
v2.textContent.trim(),
|
||||||
"Hello world this is a testThis is an edit!",
|
"Hello world this is a testThis is an edit!",
|
||||||
"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"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user