FIX: Reorder and hide topic timer options (#13597)

This PR changes the order of the topic timer options
into a more logical order when the topic is open/closed.

Also, we are now hiding the "Schedule Publishing" option
if the topic is not a private message or in a private category.
It does not make sense to schedule publishing to a different
category for a public topic.
This commit is contained in:
Martin Brennan 2021-07-01 13:18:38 +10:00 committed by GitHub
parent b579e9a7de
commit eb898e5523
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 176 additions and 41 deletions

View File

@ -20,53 +20,77 @@ export default Controller.extend(ModalFunctionality, {
loading: false, loading: false,
isPublic: "true", isPublic: "true",
@discourseComputed("model.closed") @discourseComputed(
publicTimerTypes(closed) { "model.closed",
let types = [ "model.category",
{ "model.isPrivateMessage",
id: CLOSE_STATUS_TYPE, "model.invisible"
name: I18n.t( )
closed ? "topic.temp_open.title" : "topic.auto_close.title" publicTimerTypes(closed, category, isPrivateMessage, invisible) {
), let types = [];
},
];
if (!closed) { if (!closed) {
types.push({
id: CLOSE_STATUS_TYPE,
name: I18n.t("topic.auto_close.title"),
});
types.push({ types.push({
id: CLOSE_AFTER_LAST_POST_STATUS_TYPE, id: CLOSE_AFTER_LAST_POST_STATUS_TYPE,
name: I18n.t("topic.auto_close_after_last_post.title"), name: I18n.t("topic.auto_close_after_last_post.title"),
}); });
} }
types.push( if (closed) {
{ types.push({
id: OPEN_STATUS_TYPE, id: OPEN_STATUS_TYPE,
name: I18n.t( name: I18n.t("topic.auto_reopen.title"),
closed ? "topic.auto_reopen.title" : "topic.temp_close.title" });
), }
},
{ if (this.currentUser.staff) {
types.push({
id: DELETE_STATUS_TYPE,
name: I18n.t("topic.auto_delete.title"),
});
}
types.push({
id: BUMP_TYPE,
name: I18n.t("topic.auto_bump.title"),
});
if (this.currentUser.staff) {
types.push({
id: DELETE_REPLIES_TYPE,
name: I18n.t("topic.auto_delete_replies.title"),
});
}
if (closed) {
types.push({
id: CLOSE_STATUS_TYPE,
name: I18n.t("topic.temp_open.title"),
});
}
if (!closed) {
types.push({
id: OPEN_STATUS_TYPE,
name: I18n.t("topic.temp_close.title"),
});
}
if (
(category && category.read_restricted) ||
isPrivateMessage ||
invisible
) {
types.push({
id: PUBLISH_TO_CATEGORY_STATUS_TYPE, id: PUBLISH_TO_CATEGORY_STATUS_TYPE,
name: I18n.t("topic.publish_to_category.title"), name: I18n.t("topic.publish_to_category.title"),
}, });
{
id: BUMP_TYPE,
name: I18n.t("topic.auto_bump.title"),
}
);
if (this.currentUser.get("staff")) {
types.push(
{
id: DELETE_STATUS_TYPE,
name: I18n.t("topic.auto_delete.title"),
},
{
id: DELETE_REPLIES_TYPE,
name: I18n.t("topic.auto_delete_replies.title"),
}
);
} }
return types; return types;
}, },

View File

@ -121,12 +121,12 @@ acceptance("Topic - Edit timer", function (needs) {
assert.ok(regex2.test(html2)); assert.ok(regex2.test(html2));
}); });
test("schedule", async function (assert) { test("schedule publish to category - visible for a PM", async function (assert) {
updateCurrentUser({ moderator: true }); updateCurrentUser({ moderator: true });
const timerType = selectKit(".select-kit.timer-type"); const timerType = selectKit(".select-kit.timer-type");
const categoryChooser = selectKit(".modal-body .category-chooser"); const categoryChooser = selectKit(".modal-body .category-chooser");
await visit("/t/internationalization-localization"); await visit("/t/pm-for-testing/12");
await click(".toggle-admin-menu"); await click(".toggle-admin-menu");
await click(".admin-topic-timer-update button"); await click(".admin-topic-timer-update button");
@ -141,14 +141,110 @@ acceptance("Topic - Edit timer", function (needs) {
await click("#tap_tile_start_of_next_business_week"); await click("#tap_tile_start_of_next_business_week");
const regex = /will be published to #dev/g;
const text = queryAll(".edit-topic-timer-modal .topic-timer-info") const text = queryAll(".edit-topic-timer-modal .topic-timer-info")
.text() .text()
.trim(); .trim();
assert.ok(regex.test(text));
// this needs to be done because there is no simple way to get the
// plain text version of a translation with HTML
let el = document.createElement("p");
el.innerHTML = I18n.t(
"topic.status_update_notice.auto_publish_to_category",
{
categoryUrl: "/c/dev/7",
categoryName: "dev",
timeLeft: "in 6 days",
}
);
assert.equal(text, el.innerText);
}); });
test("schedule - last custom date and time", async function (assert) { test("schedule publish to category - visible for a private category", async function (assert) {
updateCurrentUser({ moderator: true });
const timerType = selectKit(".select-kit.timer-type");
const categoryChooser = selectKit(".modal-body .category-chooser");
// has private category id 24 (shared drafts)
await visit("/t/some-topic/9");
await click(".toggle-admin-menu");
await click(".admin-topic-timer-update button");
await timerType.expand();
await timerType.selectRowByValue("publish_to_category");
assert.equal(categoryChooser.header().label(), "uncategorized");
assert.equal(categoryChooser.header().value(), null);
await categoryChooser.expand();
await categoryChooser.selectRowByValue("7");
await click("#tap_tile_start_of_next_business_week");
const text = queryAll(".edit-topic-timer-modal .topic-timer-info")
.text()
.trim();
// this needs to be done because there is no simple way to get the
// plain text version of a translation with HTML
let el = document.createElement("p");
el.innerHTML = I18n.t(
"topic.status_update_notice.auto_publish_to_category",
{
categoryUrl: "/c/dev/7",
categoryName: "dev",
timeLeft: "in 6 days",
}
);
assert.equal(text, el.innerText);
});
test("schedule publish to category - visible for an unlisted public topic", async function (assert) {
updateCurrentUser({ moderator: true });
const timerType = selectKit(".select-kit.timer-type");
const categoryChooser = selectKit(".modal-body .category-chooser");
await visit("/t/internationalization-localization/280");
// make topic not visible
await click(".toggle-admin-menu");
await click(".topic-admin-visible .btn");
await click(".toggle-admin-menu");
await click(".admin-topic-timer-update button");
await timerType.expand();
await timerType.selectRowByValue("publish_to_category");
assert.equal(categoryChooser.header().label(), "uncategorized");
assert.equal(categoryChooser.header().value(), null);
await categoryChooser.expand();
await categoryChooser.selectRowByValue("7");
await click("#tap_tile_start_of_next_business_week");
const text = queryAll(".edit-topic-timer-modal .topic-timer-info")
.text()
.trim();
// this needs to be done because there is no simple way to get the
// plain text version of a translation with HTML
let el = document.createElement("p");
el.innerHTML = I18n.t(
"topic.status_update_notice.auto_publish_to_category",
{
categoryUrl: "/c/dev/7",
categoryName: "dev",
timeLeft: "in 6 days",
}
);
assert.equal(text, el.innerText);
});
test("schedule publish to category - last custom date and time", async function (assert) {
updateCurrentUser({ moderator: true }); updateCurrentUser({ moderator: true });
await visit("/t/internationalization-localization"); await visit("/t/internationalization-localization");
@ -183,6 +279,21 @@ acceptance("Topic - Edit timer", function (needs) {
assert.ok(regex.test(text)); assert.ok(regex.test(text));
}); });
test("schedule publish to category - does not show for a public topic", async function (assert) {
updateCurrentUser({ moderator: true });
const timerType = selectKit(".select-kit.timer-type");
await visit("/t/internationalization-localization");
await click(".toggle-admin-menu");
await click(".admin-topic-timer-update button");
await timerType.expand();
assert.notOk(
timerType.rowByValue("publish_to_category").exists(),
"publish to category is not shown for a public topic"
);
});
test("TL4 can't auto-delete", async function (assert) { test("TL4 can't auto-delete", async function (assert) {
updateCurrentUser({ moderator: false, admin: false, trust_level: 4 }); updateCurrentUser({ moderator: false, admin: false, trust_level: 4 });

View File

@ -2566,7 +2566,7 @@ en:
temp_open: temp_open:
title: "Open Temporarily" title: "Open Temporarily"
auto_reopen: auto_reopen:
title: "Auto-open Topic" title: "Auto-Open Topic"
temp_close: temp_close:
title: "Close Temporarily" title: "Close Temporarily"
auto_close: auto_close: