MCPcopy Index your code
hub / github.com/coder/coder / putUserQuietHoursSchedule

Method putUserQuietHoursSchedule

enterprise/coderd/users.go:83–123  ·  view source on GitHub ↗

@Summary Update user quiet hours schedule @ID update-user-quiet-hours-schedule @Security CoderSessionToken @Accept json @Produce json @Tags Enterprise @Param user path string true "User ID" format(uuid) @Param request body codersdk.UpdateUserQuietHoursScheduleRequest true "Update schedule request" @

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

81// @Success 200 {array} codersdk.UserQuietHoursScheduleResponse
82// @Router /api/v2/users/{user}/quiet-hours [put]
83func (api *API) putUserQuietHoursSchedule(rw http.ResponseWriter, r *http.Request) {
84 var (
85 ctx = r.Context()
86 user = httpmw.UserParam(r)
87 params codersdk.UpdateUserQuietHoursScheduleRequest
88 aReq, commitAudit = audit.InitRequest[database.User](rw, &audit.RequestParams{
89 Audit: api.Auditor,
90 Log: api.Logger,
91 Request: r,
92 Action: database.AuditActionWrite,
93 })
94 )
95 defer commitAudit()
96 aReq.Old = user
97
98 if !httpapi.Read(ctx, rw, r, &params) {
99 return
100 }
101
102 opts, err := (*api.UserQuietHoursScheduleStore.Load()).Set(ctx, api.Database, user.ID, params.Schedule)
103 if xerrors.Is(err, schedule.ErrUserCannotSetQuietHoursSchedule) {
104 httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{
105 Message: "Users cannot set custom quiet hours schedule due to deployment configuration.",
106 })
107 return
108 } else if err != nil {
109 // TODO(@dean): some of these errors are related to bad syntax, so it
110 // would be nice to 400 instead
111 httpapi.InternalServerError(rw, err)
112 return
113 }
114
115 httpapi.Write(ctx, rw, http.StatusOK, codersdk.UserQuietHoursScheduleResponse{
116 RawSchedule: opts.Schedule.String(),
117 UserSet: opts.UserSet,
118 UserCanSet: opts.UserCanSet,
119 Time: opts.Schedule.TimeParsed().Format(TimeFormatHHMM),
120 Timezone: opts.Schedule.Location().String(),
121 Next: opts.Schedule.Next(time.Now().In(opts.Schedule.Location())),
122 })
123}

Callers

nothing calls this directly

Calls 14

UserParamFunction · 0.92
InitRequestFunction · 0.92
ReadFunction · 0.92
WriteFunction · 0.92
InternalServerErrorFunction · 0.92
TimeParsedMethod · 0.80
LocationMethod · 0.80
ContextMethod · 0.65
SetMethod · 0.65
FormatMethod · 0.65
NextMethod · 0.65
LoadMethod · 0.45

Tested by

no test coverage detected