2021-06-24 01:28:44 +05:30
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2021-06-24 01:28:44 +05:30
|
|
|
|
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2021-11-24 15:19:20 +05:30
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2021-06-24 01:28:44 +05:30
|
|
|
"code.gitea.io/gitea/modules/context"
|
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
|
|
|
"code.gitea.io/gitea/modules/web"
|
2022-12-29 08:27:15 +05:30
|
|
|
"code.gitea.io/gitea/services/convert"
|
2021-06-24 01:28:44 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
// 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 12:33:22 +05:30
|
|
|
ctx.JSON(http.StatusOK, convert.User2UserSettings(ctx.Doer))
|
2021-06-24 01:28:44 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
|
|
|
if form.FullName != nil {
|
2022-03-22 12:33:22 +05:30
|
|
|
ctx.Doer.FullName = *form.FullName
|
2021-06-24 01:28:44 +05:30
|
|
|
}
|
|
|
|
if form.Description != nil {
|
2022-03-22 12:33:22 +05:30
|
|
|
ctx.Doer.Description = *form.Description
|
2021-06-24 01:28:44 +05:30
|
|
|
}
|
|
|
|
if form.Website != nil {
|
2022-03-22 12:33:22 +05:30
|
|
|
ctx.Doer.Website = *form.Website
|
2021-06-24 01:28:44 +05:30
|
|
|
}
|
|
|
|
if form.Location != nil {
|
2022-03-22 12:33:22 +05:30
|
|
|
ctx.Doer.Location = *form.Location
|
2021-06-24 01:28:44 +05:30
|
|
|
}
|
|
|
|
if form.Language != nil {
|
2022-03-22 12:33:22 +05:30
|
|
|
ctx.Doer.Language = *form.Language
|
2021-06-24 01:28:44 +05:30
|
|
|
}
|
|
|
|
if form.Theme != nil {
|
2022-03-22 12:33:22 +05:30
|
|
|
ctx.Doer.Theme = *form.Theme
|
2021-06-24 01:28:44 +05:30
|
|
|
}
|
|
|
|
if form.DiffViewStyle != nil {
|
2022-03-22 12:33:22 +05:30
|
|
|
ctx.Doer.DiffViewStyle = *form.DiffViewStyle
|
2021-06-24 01:28:44 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if form.HideEmail != nil {
|
2022-03-22 12:33:22 +05:30
|
|
|
ctx.Doer.KeepEmailPrivate = *form.HideEmail
|
2021-06-24 01:28:44 +05:30
|
|
|
}
|
|
|
|
if form.HideActivity != nil {
|
2022-03-22 12:33:22 +05:30
|
|
|
ctx.Doer.KeepActivityPrivate = *form.HideActivity
|
2021-06-24 01:28:44 +05:30
|
|
|
}
|
|
|
|
|
2022-05-20 19:38:52 +05:30
|
|
|
if err := user_model.UpdateUser(ctx, ctx.Doer, false); err != nil {
|
2021-06-24 01:28:44 +05:30
|
|
|
ctx.InternalServerError(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-22 12:33:22 +05:30
|
|
|
ctx.JSON(http.StatusOK, convert.User2UserSettings(ctx.Doer))
|
2021-06-24 01:28:44 +05:30
|
|
|
}
|