Files
Gitea/routers/api/v1/user/settings.go
T
silverwind 76a81b24f9 chore: enable forcetypeassert linter, fix issues (#38804)
Enable [`forcetypeassert`](https://github.com/gostaticanalysis/forcetypeassert)
linter to prevent unchecked type assertions. ~650 issues fixed, most
fixes were clean, some use `setting.PanicInDevOrTesting`.

The only behaviour changes are where code would previously send a 500 error
or panic, a 4xx error is now emitted.

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2026-08-09 10:25:06 +00:00

66 lines
1.8 KiB
Go

// Copyright 2021 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package user
import (
"net/http"
"gitea.dev/modules/optional"
api "gitea.dev/modules/structs"
"gitea.dev/modules/web"
"gitea.dev/services/context"
"gitea.dev/services/convert"
user_service "gitea.dev/services/user"
)
// GetUserSettings returns user settings
func GetUserSettings(ctx *context.APIContext) {
// swagger:operation GET /user/settings user getUserSettings
// ---
// summary: Get user settings
// produces:
// - application/json
// responses:
// "200":
// "$ref": "#/responses/UserSettings"
ctx.JSON(http.StatusOK, convert.User2UserSettings(ctx.Doer))
}
// UpdateUserSettings returns user settings
func UpdateUserSettings(ctx *context.APIContext) {
// swagger:operation PATCH /user/settings user updateUserSettings
// ---
// summary: Update user settings
// parameters:
// - name: body
// in: body
// schema:
// "$ref": "#/definitions/UserSettingsOptions"
// produces:
// - application/json
// responses:
// "200":
// "$ref": "#/responses/UserSettings"
form := web.GetForm[*api.UserSettingsOptions](ctx)
opts := &user_service.UpdateOptions{
FullName: optional.FromPtr(form.FullName),
Description: optional.FromPtr(form.Description),
Website: optional.FromPtr(form.Website),
Location: optional.FromPtr(form.Location),
Language: optional.FromPtr(form.Language),
Theme: optional.FromPtr(form.Theme),
DiffViewStyle: optional.FromPtr(form.DiffViewStyle),
KeepEmailPrivate: optional.FromPtr(form.HideEmail),
KeepActivityPrivate: optional.FromPtr(form.HideActivity),
}
if err := user_service.UpdateUser(ctx, ctx.Doer, opts); err != nil {
ctx.APIErrorInternal(err)
return
}
ctx.JSON(http.StatusOK, convert.User2UserSettings(ctx.Doer))
}