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
+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
}