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

This commit is contained in:
Dean Sheather
2023-12-15 19:33:51 +10:00
committed by GitHub
parent a58e4febb9
commit 1e49190e12
22 changed files with 358 additions and 46 deletions
+7
View File
@@ -11353,6 +11353,9 @@ const docTemplate = `{
"codersdk.UserQuietHoursScheduleConfig": {
"type": "object",
"properties": {
"allow_user_custom": {
"type": "boolean"
},
"default_schedule": {
"type": "string"
}
@@ -11377,6 +11380,10 @@ const docTemplate = `{
"description": "raw format from the cron expression, UTC if unspecified",
"type": "string"
},
"user_can_set": {
"description": "UserCanSet is true if the user is allowed to set their own quiet hours\nschedule. If false, the user cannot set a custom schedule and the default\nschedule will always be used.",
"type": "boolean"
},
"user_set": {
"description": "UserSet is true if the user has set their own quiet hours schedule. If\nfalse, the user is using the default schedule.",
"type": "boolean"
+7
View File
@@ -10292,6 +10292,9 @@
"codersdk.UserQuietHoursScheduleConfig": {
"type": "object",
"properties": {
"allow_user_custom": {
"type": "boolean"
},
"default_schedule": {
"type": "string"
}
@@ -10316,6 +10319,10 @@
"description": "raw format from the cron expression, UTC if unspecified",
"type": "string"
},
"user_can_set": {
"description": "UserCanSet is true if the user is allowed to set their own quiet hours\nschedule. If false, the user cannot set a custom schedule and the default\nschedule will always be used.",
"type": "boolean"
},
"user_set": {
"description": "UserSet is true if the user has set their own quiet hours schedule. If\nfalse, the user is using the default schedule.",
"type": "boolean"
+14 -8
View File
@@ -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.
@@ -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 {
@@ -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
}