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"
|
|
|
|
|
2024-02-04 18:59:09 +05:30
|
|
|
"code.gitea.io/gitea/modules/optional"
|
2021-06-24 01:28:44 +05:30
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
|
|
|
"code.gitea.io/gitea/modules/web"
|
2024-02-27 12:42:22 +05:30
|
|
|
"code.gitea.io/gitea/services/context"
|
2022-12-29 08:27:15 +05:30
|
|
|
"code.gitea.io/gitea/services/convert"
|
2024-02-04 18:59:09 +05:30
|
|
|
user_service "code.gitea.io/gitea/services/user"
|
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)
|
|
|
|
|
2024-02-04 18:59:09 +05:30
|
|
|
opts := &user_service.UpdateOptions{
|
|
|
|
FullName: optional.FromPtr(form.FullName),
|
|
|
|
Description: optional.FromPtr(form.Description),
|
2023-09-26 08:09:12 +05:30
|
|
|
Pronouns: optional.FromPtr(form.Pronouns),
|
2024-02-04 18:59:09 +05:30
|
|
|
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 17:52:40 +05:30
|
|
|
EnableRepoUnitHints: optional.FromPtr(form.EnableRepoUnitHints),
|
2021-06-24 01:28:44 +05:30
|
|
|
}
|
2024-02-04 18:59:09 +05:30
|
|
|
if err := user_service.UpdateUser(ctx, ctx.Doer, opts); 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
|
|
|
}
|