2021-06-23 19:58:44 +00:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-06-23 19:58:44 +00:00
|
|
|
|
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2024-02-04 13:29:09 +00:00
|
|
|
"code.gitea.io/gitea/modules/optional"
|
2021-06-23 19:58:44 +00:00
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
|
|
|
"code.gitea.io/gitea/modules/web"
|
2024-02-27 07:12:22 +00:00
|
|
|
"code.gitea.io/gitea/services/context"
|
2022-12-29 02:57:15 +00:00
|
|
|
"code.gitea.io/gitea/services/convert"
|
2024-02-04 13:29:09 +00:00
|
|
|
user_service "code.gitea.io/gitea/services/user"
|
2021-06-23 19:58:44 +00: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"
|
2022-03-22 07:03:22 +00:00
|
|
|
ctx.JSON(http.StatusOK, convert.User2UserSettings(ctx.Doer))
|
2021-06-23 19:58:44 +00: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"
|
|
|
|
|
|
|
|
form := web.GetForm(ctx).(*api.UserSettingsOptions)
|
|
|
|
|
2024-02-04 13:29:09 +00:00
|
|
|
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),
|
2024-03-01 12:22:40 +00:00
|
|
|
EnableRepoUnitHints: optional.FromPtr(form.EnableRepoUnitHints),
|
2021-06-23 19:58:44 +00:00
|
|
|
}
|
2024-02-04 13:29:09 +00:00
|
|
|
if err := user_service.UpdateUser(ctx, ctx.Doer, opts); err != nil {
|
2021-06-23 19:58:44 +00:00
|
|
|
ctx.InternalServerError(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-22 07:03:22 +00:00
|
|
|
ctx.JSON(http.StatusOK, convert.User2UserSettings(ctx.Doer))
|
2021-06-23 19:58:44 +00:00
|
|
|
}
|