2021-06-23 21:58:44 +02:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-27 19:20:29 +01:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-06-23 21:58:44 +02:00
|
|
|
|
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2024-02-04 14:29:09 +01:00
|
|
|
"code.gitea.io/gitea/modules/optional"
|
2021-06-23 21:58:44 +02:00
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
|
|
|
"code.gitea.io/gitea/modules/web"
|
2024-02-27 08:12:22 +01:00
|
|
|
"code.gitea.io/gitea/services/context"
|
2022-12-29 03:57:15 +01:00
|
|
|
"code.gitea.io/gitea/services/convert"
|
2024-02-04 14:29:09 +01:00
|
|
|
user_service "code.gitea.io/gitea/services/user"
|
2021-06-23 21:58:44 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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"
|
2024-11-23 10:33:55 +01:00
|
|
|
// "401":
|
|
|
|
// "$ref": "#/responses/unauthorized"
|
|
|
|
// "403":
|
|
|
|
// "$ref": "#/responses/forbidden"
|
2022-03-22 08:03:22 +01:00
|
|
|
ctx.JSON(http.StatusOK, convert.User2UserSettings(ctx.Doer))
|
2021-06-23 21:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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"
|
2024-11-23 10:33:55 +01:00
|
|
|
// "401":
|
|
|
|
// "$ref": "#/responses/unauthorized"
|
|
|
|
// "403":
|
|
|
|
// "$ref": "#/responses/forbidden"
|
2021-06-23 21:58:44 +02:00
|
|
|
|
|
|
|
form := web.GetForm(ctx).(*api.UserSettingsOptions)
|
|
|
|
|
2024-02-04 14:29:09 +01:00
|
|
|
opts := &user_service.UpdateOptions{
|
|
|
|
FullName: optional.FromPtr(form.FullName),
|
|
|
|
Description: optional.FromPtr(form.Description),
|
2023-09-26 04:39:12 +02:00
|
|
|
Pronouns: optional.FromPtr(form.Pronouns),
|
2024-02-04 14:29:09 +01:00
|
|
|
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),
|
2024-03-01 13:22:40 +01:00
|
|
|
EnableRepoUnitHints: optional.FromPtr(form.EnableRepoUnitHints),
|
2021-06-23 21:58:44 +02:00
|
|
|
}
|
2024-02-04 14:29:09 +01:00
|
|
|
if err := user_service.UpdateUser(ctx, ctx.Doer, opts); err != nil {
|
2021-06-23 21:58:44 +02:00
|
|
|
ctx.InternalServerError(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-22 08:03:22 +01:00
|
|
|
ctx.JSON(http.StatusOK, convert.User2UserSettings(ctx.Doer))
|
2021-06-23 21:58:44 +02:00
|
|
|
}
|