Skip to content

feat: add server flag to disable user custom quiet hours #11124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cli/testdata/coder_server_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,12 @@ USER QUIET HOURS SCHEDULE OPTIONS:
Allow users to set quiet hours schedules each day for workspaces to avoid
workspaces stopping during the day due to template max TTL.

--allow-custom-quiet-hours bool, $CODER_ALLOW_CUSTOM_QUIET_HOURS (default: true)
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.

--default-quiet-hours-schedule string, $CODER_QUIET_HOURS_DEFAULT_SCHEDULE
The default daily cron schedule applied to users that haven't set a
custom quiet hours schedule themselves. The quiet hours schedule
Expand Down
5 changes: 5 additions & 0 deletions cli/testdata/server-config.yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,8 @@ userQuietHoursSchedule:
# values are not supported).
# (default: <unset>, type: string)
defaultQuietHoursSchedule: ""
# 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.
# (default: true, type: bool)
allowCustomQuietHours: true
7 changes: 7 additions & 0 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 14 additions & 8 deletions coderd/schedule/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import (
"context"

"github.com/google/uuid"
"golang.org/x/xerrors"

"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/schedule/cron"
)

var ErrUserCannotSetQuietHoursSchedule = xerrors.New("user cannot set custom quiet hours schedule due to deployment configuration")

type UserQuietHoursScheduleOptions struct {
// Schedule is the cron schedule to use for quiet hours windows for all
// workspaces owned by the user.
Expand All @@ -19,7 +22,13 @@ type UserQuietHoursScheduleOptions struct {
// entitled or disabled instance-wide, this value will be nil to denote that
// quiet hours windows should not be used.
Schedule *cron.Schedule
UserSet bool
// UserSet is true if the user has set a custom schedule, false if the
// default schedule is being used.
UserSet bool
// UserCanSet is true if the user is allowed to set a custom schedule. If
// false, the user cannot set a custom schedule and the default schedule
// will always be used.
UserCanSet bool
}

type UserQuietHoursScheduleStore interface {
Expand Down Expand Up @@ -47,15 +56,12 @@ func NewAGPLUserQuietHoursScheduleStore() UserQuietHoursScheduleStore {
func (*agplUserQuietHoursScheduleStore) Get(_ context.Context, _ database.Store, _ uuid.UUID) (UserQuietHoursScheduleOptions, error) {
// User quiet hours windows are not supported in AGPL.
return UserQuietHoursScheduleOptions{
Schedule: nil,
UserSet: false,
Schedule: nil,
UserSet: false,
UserCanSet: false,
}, nil
}

func (*agplUserQuietHoursScheduleStore) Set(_ context.Context, _ database.Store, _ uuid.UUID, _ string) (UserQuietHoursScheduleOptions, error) {
// User quiet hours windows are not supported in AGPL.
return UserQuietHoursScheduleOptions{
Schedule: nil,
UserSet: false,
}, nil
return UserQuietHoursScheduleOptions{}, ErrUserCannotSetQuietHoursSchedule
}
11 changes: 11 additions & 0 deletions codersdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ type DangerousConfig struct {

type UserQuietHoursScheduleConfig struct {
DefaultSchedule clibase.String `json:"default_schedule" typescript:",notnull"`
AllowUserCustom clibase.Bool `json:"allow_user_custom" typescript:",notnull"`
// TODO: add WindowDuration and the ability to postpone max_deadline by this
// amount
// WindowDuration clibase.Duration `json:"window_duration" typescript:",notnull"`
Expand Down Expand Up @@ -1824,6 +1825,16 @@ Write out the current server config as YAML to stdout.`,
Group: &deploymentGroupUserQuietHoursSchedule,
YAML: "defaultQuietHoursSchedule",
},
{
Name: "Allow Custom Quiet Hours",
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.",
Flag: "allow-custom-quiet-hours",
Env: "CODER_ALLOW_CUSTOM_QUIET_HOURS",
Default: "true",
Value: &c.UserQuietHoursSchedule.AllowUserCustom,
Group: &deploymentGroupUserQuietHoursSchedule,
YAML: "allowCustomQuietHours",
},
{
Name: "Web Terminal Renderer",
Description: "The renderer to use when opening a web terminal. Valid values are 'canvas', 'webgl', or 'dom'.",
Expand Down
4 changes: 4 additions & 0 deletions codersdk/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ type UserQuietHoursScheduleResponse struct {
// UserSet is true if the user has set their own quiet hours schedule. If
// false, the user is using the default schedule.
UserSet bool `json:"user_set"`
// UserCanSet is true if the user is allowed to set their own quiet hours
// schedule. If false, the user cannot set a custom schedule and the default
// schedule will always be used.
UserCanSet bool `json:"user_can_set"`
// Time is the time of day that the quiet hours window starts in the given
// Timezone each day.
Time string `json:"time"` // HH:mm (24-hour)
Expand Down
36 changes: 20 additions & 16 deletions docs/api/enterprise.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/api/general.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 16 additions & 10 deletions docs/api/schemas.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading