mirror of
https://github.com/discourse/discourse.git
synced 2025-05-04 23:04:36 +08:00
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.push(shortcutsFactory.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
shortcuts = hideDynamicTimeShortcuts(shortcuts, this.userTimezone);
|
shortcuts = hideDynamicTimeShortcuts(
|
||||||
|
shortcuts,
|
||||||
|
this.userTimezone,
|
||||||
|
this.siteSettings
|
||||||
|
);
|
||||||
|
|
||||||
return shortcuts.map((s) => {
|
return shortcuts.map((s) => {
|
||||||
return {
|
return {
|
||||||
|
@ -182,7 +182,11 @@ export default Component.extend({
|
|||||||
} else {
|
} else {
|
||||||
options = defaultTimeShortcuts(userTimezone);
|
options = defaultTimeShortcuts(userTimezone);
|
||||||
}
|
}
|
||||||
options = hideDynamicTimeShortcuts(options, userTimezone);
|
options = hideDynamicTimeShortcuts(
|
||||||
|
options,
|
||||||
|
userTimezone,
|
||||||
|
this.siteSettings
|
||||||
|
);
|
||||||
|
|
||||||
let specialOptions = specialShortcutOptions();
|
let specialOptions = specialShortcutOptions();
|
||||||
if (this.lastCustomDate && this.lastCustomTime) {
|
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 shortcutsToHide = new Set();
|
||||||
const _now = now(timezone);
|
const _now = now(timezone);
|
||||||
if (_now.hour() >= LATER_TODAY_CUTOFF_HOUR) {
|
if (_now.hour() >= LATER_TODAY_CUTOFF_HOUR) {
|
||||||
@ -256,6 +260,7 @@ export function hideDynamicTimeShortcuts(shortcuts, timezone) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
!siteSettings.suggest_weekends_in_date_pickers ||
|
||||||
_now.day() === MOMENT_FRIDAY ||
|
_now.day() === MOMENT_FRIDAY ||
|
||||||
_now.day() === MOMENT_SATURDAY ||
|
_now.day() === MOMENT_SATURDAY ||
|
||||||
_now.day() === MOMENT_SUNDAY
|
_now.day() === MOMENT_SUNDAY
|
||||||
|
@ -346,6 +346,7 @@ acceptance("Topic - Edit timer", function (needs) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("Shows correct time frame options", async function (assert) {
|
test("Shows correct time frame options", async function (assert) {
|
||||||
|
this.siteSettings.suggest_weekends_in_date_pickers = true;
|
||||||
updateCurrentUser({ moderator: true });
|
updateCurrentUser({ moderator: true });
|
||||||
|
|
||||||
await visit("/t/internationalization-localization");
|
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) {
|
test("Shows correct timeframe options", async function (assert) {
|
||||||
|
this.siteSettings.suggest_weekends_in_date_pickers = true;
|
||||||
await visit("/u/eviltrout/preferences/users");
|
await visit("/u/eviltrout/preferences/users");
|
||||||
|
|
||||||
await click("div.user-notifications div div button");
|
await click("div.user-notifications div div button");
|
||||||
|
@ -38,6 +38,7 @@ discourseModule(
|
|||||||
template,
|
template,
|
||||||
|
|
||||||
beforeEach() {
|
beforeEach() {
|
||||||
|
this.siteSettings.suggest_weekends_in_date_pickers = true;
|
||||||
const tuesday = "2100-06-08T08:00:00";
|
const tuesday = "2100-06-08T08:00:00";
|
||||||
this.clock = fakeTime(tuesday, this.currentUser._timezone, true);
|
this.clock = fakeTime(tuesday, this.currentUser._timezone, true);
|
||||||
},
|
},
|
||||||
|
@ -57,36 +57,70 @@ module(
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("hides 'This Weekend' on Fridays, Saturdays and Sundays", function (assert) {
|
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 timezone = moment.tz.guess();
|
||||||
const shortcuts = defaultTimeShortcuts(timezone);
|
const shortcuts = defaultTimeShortcuts(timezone);
|
||||||
|
|
||||||
this.clock = fakeTime("2100-04-22 18:00:00", timezone, true); // Thursday
|
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(
|
assert.ok(
|
||||||
result.includes("this_weekend"),
|
result.includes("this_weekend"),
|
||||||
"shows this_weekend on Thursdays"
|
"shows this_weekend on Thursdays"
|
||||||
);
|
);
|
||||||
|
|
||||||
this.clock = fakeTime("2100-04-23 18:00:00", timezone, true); // Friday
|
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(
|
assert.notOk(
|
||||||
result.includes("this_weekend"),
|
result.includes("this_weekend"),
|
||||||
"doesn't show this_weekend on Fridays"
|
"doesn't show this_weekend on Fridays"
|
||||||
);
|
);
|
||||||
|
|
||||||
this.clock = fakeTime("2100-04-24 18:00:00", timezone, true); // Saturday
|
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(
|
assert.notOk(
|
||||||
result.includes("this_weekend"),
|
result.includes("this_weekend"),
|
||||||
"doesn't show this_weekend on Saturdays"
|
"doesn't show this_weekend on Saturdays"
|
||||||
);
|
);
|
||||||
|
|
||||||
this.clock = fakeTime("2100-04-25 18:00:00", timezone, true); // Sunday
|
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(
|
assert.notOk(
|
||||||
result.includes("this_weekend"),
|
result.includes("this_weekend"),
|
||||||
"doesn't show this_weekend on Sundays"
|
"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."
|
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_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."
|
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:
|
errors:
|
||||||
invalid_css_color: "Invalid color. Enter a color name or hex value."
|
invalid_css_color: "Invalid color. Enter a color name or hex value."
|
||||||
|
@ -2399,6 +2399,10 @@ uncategorized:
|
|||||||
default: false
|
default: false
|
||||||
hidden: true
|
hidden: true
|
||||||
|
|
||||||
|
suggest_weekends_in_date_pickers:
|
||||||
|
client: true
|
||||||
|
default: true
|
||||||
|
|
||||||
user_preferences:
|
user_preferences:
|
||||||
default_email_digest_frequency:
|
default_email_digest_frequency:
|
||||||
enum: "DigestEmailSiteSetting"
|
enum: "DigestEmailSiteSetting"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user