2021-06-23 13:58:44 -06:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2021-11-24 02:49:20 -07:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2021-06-23 13:58:44 -06:00
|
|
|
"code.gitea.io/gitea/modules/context"
|
|
|
|
"code.gitea.io/gitea/modules/convert"
|
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
|
|
|
"code.gitea.io/gitea/modules/web"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
|
|
|
if form.FullName != nil {
|
2022-03-22 01:03:22 -06:00
|
|
|
ctx.Doer.FullName = *form.FullName
|
2021-06-23 13:58:44 -06:00
|
|
|
}
|
|
|
|
if form.Description != nil {
|
2022-03-22 01:03:22 -06:00
|
|
|
ctx.Doer.Description = *form.Description
|
2021-06-23 13:58:44 -06:00
|
|
|
}
|
|
|
|
if form.Website != nil {
|
2022-03-22 01:03:22 -06:00
|
|
|
ctx.Doer.Website = *form.Website
|
2021-06-23 13:58:44 -06:00
|
|
|
}
|
|
|
|
if form.Location != nil {
|
2022-03-22 01:03:22 -06:00
|
|
|
ctx.Doer.Location = *form.Location
|
2021-06-23 13:58:44 -06:00
|
|
|
}
|
|
|
|
if form.Language != nil {
|
2022-03-22 01:03:22 -06:00
|
|
|
ctx.Doer.Language = *form.Language
|
2021-06-23 13:58:44 -06:00
|
|
|
}
|
|
|
|
if form.Theme != nil {
|
2022-03-22 01:03:22 -06:00
|
|
|
ctx.Doer.Theme = *form.Theme
|
2021-06-23 13:58:44 -06:00
|
|
|
}
|
|
|
|
if form.DiffViewStyle != nil {
|
2022-03-22 01:03:22 -06:00
|
|
|
ctx.Doer.DiffViewStyle = *form.DiffViewStyle
|
2021-06-23 13:58:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if form.HideEmail != nil {
|
2022-03-22 01:03:22 -06:00
|
|
|
ctx.Doer.KeepEmailPrivate = *form.HideEmail
|
2021-06-23 13:58:44 -06:00
|
|
|
}
|
|
|
|
if form.HideActivity != nil {
|
2022-03-22 01:03:22 -06:00
|
|
|
ctx.Doer.KeepActivityPrivate = *form.HideActivity
|
2021-06-23 13:58:44 -06:00
|
|
|
}
|
|
|
|
|
2022-05-20 08:08:52 -06:00
|
|
|
if err := user_model.UpdateUser(ctx, ctx.Doer, false); 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
|
|
|
}
|