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

Method putUserPreferenceSettings

coderd/users.go:1355–1507  ·  view source on GitHub ↗

@Summary Update user preference settings @ID update-user-preference-settings @Security CoderSessionToken @Accept json @Produce json @Tags Users @Param user path string true "User ID, name, or me" @Param request body codersdk.UpdateUserPreferenceSettingsRequest true "New preference settings" @Success

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

Source from the content-addressed store, hash-verified

1353// @Success 200 {object} codersdk.UserPreferenceSettings
1354// @Router /api/v2/users/{user}/preferences [put]
1355func (api *API) putUserPreferenceSettings(rw http.ResponseWriter, r *http.Request) {
1356 var (
1357 ctx = r.Context()
1358 user = httpmw.UserParam(r)
1359 )
1360
1361 var params codersdk.UpdateUserPreferenceSettingsRequest
1362 if !httpapi.Read(ctx, rw, r, &params) {
1363 return
1364 }
1365
1366 if params.ThinkingDisplayMode != "" &&
1367 !slices.Contains(codersdk.ValidThinkingDisplayModes, params.ThinkingDisplayMode) {
1368 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
1369 Message: "Invalid thinking display mode.",
1370 Validations: []codersdk.ValidationError{
1371 {Field: "thinking_display_mode", Detail: thinkingDisplayModeValidationDetail},
1372 },
1373 })
1374 return
1375 }
1376 if params.ShellToolDisplayMode != "" &&
1377 !slices.Contains(codersdk.ValidAgentDisplayModes, params.ShellToolDisplayMode) {
1378 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
1379 Message: "Invalid shell tool display mode.",
1380 Validations: []codersdk.ValidationError{
1381 {Field: "shell_tool_display_mode", Detail: agentDisplayModeValidationDetail},
1382 },
1383 })
1384 return
1385 }
1386 if params.CodeDiffDisplayMode != "" &&
1387 !slices.Contains(codersdk.ValidAgentDisplayModes, params.CodeDiffDisplayMode) {
1388 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
1389 Message: "Invalid code diff display mode.",
1390 Validations: []codersdk.ValidationError{
1391 {Field: "code_diff_display_mode", Detail: agentDisplayModeValidationDetail},
1392 },
1393 })
1394 return
1395 }
1396 if params.AgentChatSendShortcut != "" &&
1397 !slices.Contains(codersdk.ValidAgentChatSendShortcuts, params.AgentChatSendShortcut) {
1398 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
1399 Message: "Invalid agent chat send shortcut.",
1400 Validations: []codersdk.ValidationError{
1401 {Field: "agent_chat_send_shortcut", Detail: agentChatSendShortcutValidationDetail},
1402 },
1403 })
1404 return
1405 }
1406 var settings codersdk.UserPreferenceSettings
1407 err := api.Database.InTx(func(tx database.Store) error {
1408 var err error
1409 if params.TaskNotificationAlertDismissed != nil {
1410 settings.TaskNotificationAlertDismissed, err = tx.UpdateUserTaskNotificationAlertDismissed(ctx, database.UpdateUserTaskNotificationAlertDismissedParams{
1411 UserID: user.ID,
1412 TaskNotificationAlertDismissed: *params.TaskNotificationAlertDismissed,

Callers

nothing calls this directly

Calls 15

UserParamFunction · 0.92
ReadFunction · 0.92
WriteFunction · 0.92
DefaultTXOptionsFunction · 0.92
sanitizeAgentDisplayModeFunction · 0.85
AsMethod · 0.80
ContextMethod · 0.65
InTxMethod · 0.65

Tested by

no test coverage detected