Fix merge conflig in migrations.go Merge remote-tracking branch 'upstream/main' into limit-repo-size

This commit is contained in:
DmitryFrolovTri committed 2023-01-18 04:56:35 +00:00
commit bcea146ed2
103 files changed
+1747 -640

No files matched your search

+27
View File
@@ -5,9 +5,11 @@
package admin
import (
"fmt"
"net/http"
"net/url"
"os"
"strconv"
"strings"
system_model "code.gitea.io/gitea/models/system"
@@ -201,6 +203,16 @@ func ChangeConfig(ctx *context.Context) {
value := ctx.FormString("value")
version := ctx.FormInt("version")
if check, ok := changeConfigChecks[key]; ok {
if err := check(ctx, value); err != nil {
log.Warn("refused to set setting: %v", err)
ctx.JSON(http.StatusOK, map[string]string{
"err": ctx.Tr("admin.config.set_setting_failed", key),
})
return
}
}
if err := system_model.SetSetting(&system_model.Setting{
SettingKey: key,
SettingValue: value,
@@ -217,3 +229,18 @@ func ChangeConfig(ctx *context.Context) {
"version": version + 1,
})
}
var changeConfigChecks = map[string]func(ctx *context.Context, newValue string) error{
system_model.KeyPictureDisableGravatar: func(_ *context.Context, newValue string) error {
if v, _ := strconv.ParseBool(newValue); setting.OfflineMode && !v {
return fmt.Errorf("%q should be true when OFFLINE_MODE is true", system_model.KeyPictureDisableGravatar)
}
return nil
},
system_model.KeyPictureEnableFederatedAvatar: func(_ *context.Context, newValue string) error {
if v, _ := strconv.ParseBool(newValue); setting.OfflineMode && v {
return fmt.Errorf("%q cannot be false when OFFLINE_MODE is true", system_model.KeyPictureEnableFederatedAvatar)
}
return nil
},
}
+8 -2
View File
@@ -42,9 +42,15 @@ func ApplicationsPost(ctx *context.Context) {
return
}
scope, err := form.GetScope()
if err != nil {
ctx.ServerError("GetScope", err)
return
}
t := &auth_model.AccessToken{
UID: ctx.Doer.ID,
Name: form.Name,
UID: ctx.Doer.ID,
Name: form.Name,
Scope: scope,
}
exist, err := auth_model.AccessTokenByNameExists(t)