@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)
| 81 | // @Success 200 {array} codersdk.UserQuietHoursScheduleResponse |
| 82 | // @Router /api/v2/users/{user}/quiet-hours [put] |
| 83 | func (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, ¶ms) { |
| 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 | } |
nothing calls this directly
no test coverage detected