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