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