Skip to content

Commit 1e49190

Browse files
authored
feat: add server flag to disable user custom quiet hours (#11124)
1 parent a58e4fe commit 1e49190

22 files changed

+358
-46
lines changed

cli/testdata/coder_server_--help.golden

+6
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,12 @@ USER QUIET HOURS SCHEDULE OPTIONS:
447447
Allow users to set quiet hours schedules each day for workspaces to avoid
448448
workspaces stopping during the day due to template max TTL.
449449

450+
--allow-custom-quiet-hours bool, $CODER_ALLOW_CUSTOM_QUIET_HOURS (default: true)
451+
Allow users to set their own quiet hours schedule for workspaces to
452+
stop in (depending on template autostop requirement settings). If
453+
false, users can't change their quiet hours schedule and the site
454+
default is always used.
455+
450456
--default-quiet-hours-schedule string, $CODER_QUIET_HOURS_DEFAULT_SCHEDULE (default: CRON_TZ=UTC 0 0 * * *)
451457
The default daily cron schedule applied to users that haven't set a
452458
custom quiet hours schedule themselves. The quiet hours schedule

cli/testdata/server-config.yaml.golden

+5
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,8 @@ userQuietHoursSchedule:
457457
# comma separated values are not supported).
458458
# (default: CRON_TZ=UTC 0 0 * * *, type: string)
459459
defaultQuietHoursSchedule: CRON_TZ=UTC 0 0 * * *
460+
# Allow users to set their own quiet hours schedule for workspaces to stop in
461+
# (depending on template autostop requirement settings). If false, users can't
462+
# change their quiet hours schedule and the site default is always used.
463+
# (default: true, type: bool)
464+
allowCustomQuietHours: true

coderd/apidoc/docs.go

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/schedule/user.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ import (
44
"context"
55

66
"github.com/google/uuid"
7+
"golang.org/x/xerrors"
78

89
"github.com/coder/coder/v2/coderd/database"
910
"github.com/coder/coder/v2/coderd/schedule/cron"
1011
)
1112

13+
var ErrUserCannotSetQuietHoursSchedule = xerrors.New("user cannot set custom quiet hours schedule due to deployment configuration")
14+
1215
type UserQuietHoursScheduleOptions struct {
1316
// Schedule is the cron schedule to use for quiet hours windows for all
1417
// workspaces owned by the user.
@@ -19,7 +22,13 @@ type UserQuietHoursScheduleOptions struct {
1922
// entitled or disabled instance-wide, this value will be nil to denote that
2023
// quiet hours windows should not be used.
2124
Schedule *cron.Schedule
22-
UserSet bool
25+
// UserSet is true if the user has set a custom schedule, false if the
26+
// default schedule is being used.
27+
UserSet bool
28+
// UserCanSet is true if the user is allowed to set a custom schedule. If
29+
// false, the user cannot set a custom schedule and the default schedule
30+
// will always be used.
31+
UserCanSet bool
2332
}
2433

2534
type UserQuietHoursScheduleStore interface {
@@ -47,15 +56,12 @@ func NewAGPLUserQuietHoursScheduleStore() UserQuietHoursScheduleStore {
4756
func (*agplUserQuietHoursScheduleStore) Get(_ context.Context, _ database.Store, _ uuid.UUID) (UserQuietHoursScheduleOptions, error) {
4857
// User quiet hours windows are not supported in AGPL.
4958
return UserQuietHoursScheduleOptions{
50-
Schedule: nil,
51-
UserSet: false,
59+
Schedule: nil,
60+
UserSet: false,
61+
UserCanSet: false,
5262
}, nil
5363
}
5464

5565
func (*agplUserQuietHoursScheduleStore) Set(_ context.Context, _ database.Store, _ uuid.UUID, _ string) (UserQuietHoursScheduleOptions, error) {
56-
// User quiet hours windows are not supported in AGPL.
57-
return UserQuietHoursScheduleOptions{
58-
Schedule: nil,
59-
UserSet: false,
60-
}, nil
66+
return UserQuietHoursScheduleOptions{}, ErrUserCannotSetQuietHoursSchedule
6167
}

codersdk/deployment.go

+11
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ type DangerousConfig struct {
390390

391391
type UserQuietHoursScheduleConfig struct {
392392
DefaultSchedule clibase.String `json:"default_schedule" typescript:",notnull"`
393+
AllowUserCustom clibase.Bool `json:"allow_user_custom" typescript:",notnull"`
393394
// TODO: add WindowDuration and the ability to postpone max_deadline by this
394395
// amount
395396
// WindowDuration clibase.Duration `json:"window_duration" typescript:",notnull"`
@@ -1821,6 +1822,16 @@ Write out the current server config as YAML to stdout.`,
18211822
Group: &deploymentGroupUserQuietHoursSchedule,
18221823
YAML: "defaultQuietHoursSchedule",
18231824
},
1825+
{
1826+
Name: "Allow Custom Quiet Hours",
1827+
Description: "Allow users to set their own quiet hours schedule for workspaces to stop in (depending on template autostop requirement settings). If false, users can't change their quiet hours schedule and the site default is always used.",
1828+
Flag: "allow-custom-quiet-hours",
1829+
Env: "CODER_ALLOW_CUSTOM_QUIET_HOURS",
1830+
Default: "true",
1831+
Value: &c.UserQuietHoursSchedule.AllowUserCustom,
1832+
Group: &deploymentGroupUserQuietHoursSchedule,
1833+
YAML: "allowCustomQuietHours",
1834+
},
18241835
{
18251836
Name: "Web Terminal Renderer",
18261837
Description: "The renderer to use when opening a web terminal. Valid values are 'canvas', 'webgl', or 'dom'.",

codersdk/users.go

+4
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ type UserQuietHoursScheduleResponse struct {
107107
// UserSet is true if the user has set their own quiet hours schedule. If
108108
// false, the user is using the default schedule.
109109
UserSet bool `json:"user_set"`
110+
// UserCanSet is true if the user is allowed to set their own quiet hours
111+
// schedule. If false, the user cannot set a custom schedule and the default
112+
// schedule will always be used.
113+
UserCanSet bool `json:"user_can_set"`
110114
// Time is the time of day that the quiet hours window starts in the given
111115
// Timezone each day.
112116
Time string `json:"time"` // HH:mm (24-hour)

docs/api/enterprise.md

+20-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/general.md

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)