EXPERIMENTAL: this endpoint is experimental and is subject to change.
(rw http.ResponseWriter, r *http.Request)
| 5252 | |
| 5253 | // EXPERIMENTAL: this endpoint is experimental and is subject to change. |
| 5254 | func (api *API) putUserChatDebugLogging(rw http.ResponseWriter, r *http.Request) { |
| 5255 | ctx := r.Context() |
| 5256 | apiKey := httpmw.APIKey(r) |
| 5257 | if api.deploymentChatDebugLoggingEnabled() { |
| 5258 | httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{ |
| 5259 | Message: "Chat debug logging is already forced on by deployment configuration.", |
| 5260 | }) |
| 5261 | return |
| 5262 | } |
| 5263 | |
| 5264 | allowUsers, err := api.Database.GetChatDebugLoggingAllowUsers(ctx) |
| 5265 | if err != nil && !errors.Is(err, sql.ErrNoRows) { |
| 5266 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 5267 | Message: "Internal error fetching chat debug logging setting.", |
| 5268 | Detail: err.Error(), |
| 5269 | }) |
| 5270 | return |
| 5271 | } |
| 5272 | if err != nil || !allowUsers { |
| 5273 | httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{ |
| 5274 | Message: "An administrator has not enabled user-controlled chat debug logging.", |
| 5275 | }) |
| 5276 | return |
| 5277 | } |
| 5278 | |
| 5279 | var req codersdk.UpdateUserChatDebugLoggingRequest |
| 5280 | if !httpapi.Read(ctx, rw, r, &req) { |
| 5281 | return |
| 5282 | } |
| 5283 | if err := api.Database.UpsertUserChatDebugLoggingEnabled(ctx, database.UpsertUserChatDebugLoggingEnabledParams{ |
| 5284 | UserID: apiKey.UserID, |
| 5285 | DebugLoggingEnabled: req.DebugLoggingEnabled, |
| 5286 | }); err != nil { |
| 5287 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 5288 | Message: "Internal error updating user chat debug logging setting.", |
| 5289 | Detail: err.Error(), |
| 5290 | }) |
| 5291 | return |
| 5292 | } |
| 5293 | rw.WriteHeader(http.StatusNoContent) |
| 5294 | } |
| 5295 | |
| 5296 | // EXPERIMENTAL: this endpoint is experimental and is subject to change. |
| 5297 | // |
nothing calls this directly
no test coverage detected