2025-03-15 16:26:49 +08:00
|
|
|
// Copyright 2025 The Gitea Authors. All rights reserved.
|
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
|
|
package setting
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
|
|
|
"code.gitea.io/gitea/modules/json"
|
2026-03-23 23:30:48 +01:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2025-03-15 16:26:49 +08:00
|
|
|
"code.gitea.io/gitea/services/context"
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-23 23:30:48 +01:00
|
|
|
func SettingsCtxData(ctx *context.Context) {
|
|
|
|
|
ctx.Data["PageIsUserSettings"] = true
|
|
|
|
|
ctx.Data["EnablePackages"] = setting.Packages.Enabled
|
|
|
|
|
ctx.Data["EnableNotifyMail"] = setting.Service.EnableNotifyMail
|
|
|
|
|
ctx.Data["UserDisabledFeatures"] = user_model.DisabledFeaturesWithLoginType(ctx.Doer)
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-15 16:26:49 +08:00
|
|
|
func UpdatePreferences(ctx *context.Context) {
|
|
|
|
|
type preferencesForm struct {
|
|
|
|
|
CodeViewShowFileTree bool `json:"codeViewShowFileTree"`
|
|
|
|
|
}
|
|
|
|
|
form := &preferencesForm{}
|
|
|
|
|
if err := json.NewDecoder(ctx.Req.Body).Decode(&form); err != nil {
|
|
|
|
|
ctx.HTTPError(http.StatusBadRequest, "json decode failed")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
_ = user_model.SetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyCodeViewShowFileTree, strconv.FormatBool(form.CodeViewShowFileTree))
|
|
|
|
|
ctx.JSONOK()
|
|
|
|
|
}
|