FEATURE: introduce a sitewide setting for disabling suggesting weekends in time pickers (#16563)
This commit is contained in:
parent
5bc80cde77
commit
187922d51c
|
@ -69,7 +69,11 @@ export default Component.extend({
|
|||
shortcuts.push(shortcutsFactory.now());
|
||||
}
|
||||
|
||||
shortcuts = hideDynamicTimeShortcuts(shortcuts, this.userTimezone);
|
||||
shortcuts = hideDynamicTimeShortcuts(
|
||||
shortcuts,
|
||||
this.userTimezone,
|
||||
this.siteSettings
|
||||
);
|
||||
|
||||
return shortcuts.map((s) => {
|
||||
return {
|
||||
|
|
|
@ -182,7 +182,11 @@ export default Component.extend({
|
|||
} else {
|
||||
options = defaultTimeShortcuts(userTimezone);
|
||||
}
|
||||
options = hideDynamicTimeShortcuts(options, userTimezone);
|
||||
options = hideDynamicTimeShortcuts(
|
||||
options,
|
||||
userTimezone,
|
||||
this.siteSettings
|
||||
);
|
||||
|
||||
let specialOptions = specialShortcutOptions();
|
||||
if (this.lastCustomDate && this.lastCustomTime) {
|
||||
|
|
|
@ -244,7 +244,11 @@ export function timeShortcuts(timezone) {
|
|||
};
|
||||
}
|
||||
|
||||
export function hideDynamicTimeShortcuts(shortcuts, timezone) {
|
||||
export function hideDynamicTimeShortcuts(
|
||||
shortcuts,
|
||||
timezone,
|
||||
siteSettings = {}
|
||||
) {
|
||||
const shortcutsToHide = new Set();
|
||||
const _now = now(timezone);
|
||||
if (_now.hour() >= LATER_TODAY_CUTOFF_HOUR) {
|
||||
|
@ -256,6 +260,7 @@ export function hideDynamicTimeShortcuts(shortcuts, timezone) {
|
|||
}
|
||||
|
||||
if (
|
||||
!siteSettings.suggest_weekends_in_date_pickers ||
|
||||
_now.day() === MOMENT_FRIDAY ||
|
||||
_now.day() === MOMENT_SATURDAY ||
|
||||
_now.day() === MOMENT_SUNDAY
|
||||
|
|
|
@ -346,6 +346,7 @@ acceptance("Topic - Edit timer", function (needs) {
|
|||
});
|
||||
|
||||
test("Shows correct time frame options", async function (assert) {
|
||||
this.siteSettings.suggest_weekends_in_date_pickers = true;
|
||||
updateCurrentUser({ moderator: true });
|
||||
|
||||
await visit("/t/internationalization-localization");
|
||||
|
|
|
@ -125,6 +125,7 @@ acceptance("User Notifications - Users - Ignore User", function (needs) {
|
|||
});
|
||||
|
||||
test("Shows correct timeframe options", async function (assert) {
|
||||
this.siteSettings.suggest_weekends_in_date_pickers = true;
|
||||
await visit("/u/eviltrout/preferences/users");
|
||||
|
||||
await click("div.user-notifications div div button");
|
||||
|
|
|
@ -38,6 +38,7 @@ discourseModule(
|
|||
template,
|
||||
|
||||
beforeEach() {
|
||||
this.siteSettings.suggest_weekends_in_date_pickers = true;
|
||||
const tuesday = "2100-06-08T08:00:00";
|
||||
this.clock = fakeTime(tuesday, this.currentUser._timezone, true);
|
||||
},
|
||||
|
|
|
@ -57,36 +57,70 @@ module(
|
|||
});
|
||||
|
||||
test("hides 'This Weekend' on Fridays, Saturdays and Sundays", function (assert) {
|
||||
const siteSettings = { suggest_weekends_in_date_pickers: true };
|
||||
const timezone = moment.tz.guess();
|
||||
const shortcuts = defaultTimeShortcuts(timezone);
|
||||
|
||||
this.clock = fakeTime("2100-04-22 18:00:00", timezone, true); // Thursday
|
||||
let result = hideDynamicTimeShortcuts(shortcuts, timezone).mapBy("id");
|
||||
let result = hideDynamicTimeShortcuts(
|
||||
shortcuts,
|
||||
timezone,
|
||||
siteSettings
|
||||
).mapBy("id");
|
||||
assert.ok(
|
||||
result.includes("this_weekend"),
|
||||
"shows this_weekend on Thursdays"
|
||||
);
|
||||
|
||||
this.clock = fakeTime("2100-04-23 18:00:00", timezone, true); // Friday
|
||||
result = hideDynamicTimeShortcuts(shortcuts, timezone).mapBy("id");
|
||||
result = hideDynamicTimeShortcuts(
|
||||
shortcuts,
|
||||
timezone,
|
||||
siteSettings
|
||||
).mapBy("id");
|
||||
assert.notOk(
|
||||
result.includes("this_weekend"),
|
||||
"doesn't show this_weekend on Fridays"
|
||||
);
|
||||
|
||||
this.clock = fakeTime("2100-04-24 18:00:00", timezone, true); // Saturday
|
||||
result = hideDynamicTimeShortcuts(shortcuts, timezone).mapBy("id");
|
||||
result = hideDynamicTimeShortcuts(
|
||||
shortcuts,
|
||||
timezone,
|
||||
siteSettings
|
||||
).mapBy("id");
|
||||
assert.notOk(
|
||||
result.includes("this_weekend"),
|
||||
"doesn't show this_weekend on Saturdays"
|
||||
);
|
||||
|
||||
this.clock = fakeTime("2100-04-25 18:00:00", timezone, true); // Sunday
|
||||
result = hideDynamicTimeShortcuts(shortcuts, timezone).mapBy("id");
|
||||
result = hideDynamicTimeShortcuts(
|
||||
shortcuts,
|
||||
timezone,
|
||||
siteSettings
|
||||
).mapBy("id");
|
||||
assert.notOk(
|
||||
result.includes("this_weekend"),
|
||||
"doesn't show this_weekend on Sundays"
|
||||
);
|
||||
});
|
||||
|
||||
test("hides 'This Weekend' when disabled in site settings", function (assert) {
|
||||
const siteSettings = { suggest_weekends_in_date_pickers: false };
|
||||
const timezone = moment.tz.guess();
|
||||
const shortcuts = defaultTimeShortcuts(timezone);
|
||||
|
||||
this.clock = fakeTime("2100-04-19 18:00:00", timezone, true); // Monday
|
||||
let result = hideDynamicTimeShortcuts(
|
||||
shortcuts,
|
||||
timezone,
|
||||
siteSettings
|
||||
).mapBy("id");
|
||||
assert.notOk(
|
||||
result.includes("this_weekend"),
|
||||
"shows this_weekend on Thursdays"
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
|
|
@ -2357,6 +2357,7 @@ en:
|
|||
allow_changing_staged_user_tracking: "Allow a staged user's category and tag notification preferences to be changed by an admin user."
|
||||
use_email_for_username_and_name_suggestions: "Use the first part of email addresses for username and name suggestions. Note that this makes it easier for the public to guess full user email addresses (because a large proportion of people share common services like `gmail.com`)."
|
||||
use_name_for_username_suggestions: "Use a user's full name when suggesting usernames."
|
||||
suggest_weekends_in_date_pickers: "Include weekends (Saturday and Sunday) in date picker suggestions (disable this if you use Discourse only on weekdays, Monday through Friday)."
|
||||
|
||||
errors:
|
||||
invalid_css_color: "Invalid color. Enter a color name or hex value."
|
||||
|
|
|
@ -2399,6 +2399,10 @@ uncategorized:
|
|||
default: false
|
||||
hidden: true
|
||||
|
||||
suggest_weekends_in_date_pickers:
|
||||
client: true
|
||||
default: true
|
||||
|
||||
user_preferences:
|
||||
default_email_digest_frequency:
|
||||
enum: "DigestEmailSiteSetting"
|
||||
|
|
Loading…
Reference in New Issue