Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display deprecated warning in admin panel pages as well as in the log file #26094

Merged
merged 7 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions modules/setting/config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,15 @@ func mustMapSetting(rootCfg ConfigProvider, sectionName string, setting any) {

func deprecatedSetting(rootCfg ConfigProvider, oldSection, oldKey, newSection, newKey, version string) {
if rootCfg.Section(oldSection).HasKey(oldKey) {
log.Error("Deprecated fallback `[%s]` `%s` present. Use `[%s]` `%s` instead. This fallback will be/has been removed in %s", oldSection, oldKey, newSection, newKey, version)
}
}

func deprecatedSettingFatal(rootCfg ConfigProvider, oldSection, oldKey, newSection, newKey, version string) {
if rootCfg.Section(oldSection).HasKey(oldKey) {
log.Fatal("Deprecated fallback `[%s]` `%s` present. Use `[%s]` `%s` instead. This fallback will be/has been removed in %s. Shutting down", oldSection, oldKey, newSection, newKey, version)
dw := DeprecatedWarning{
OldSection: oldSection,
OldKey: oldKey,
NewSection: newSection,
NewKey: newKey,
Version: version,
}
log.Error("%v", dw.String())
DeprecatedWarnings = append(DeprecatedWarnings, dw)
}
}

Expand Down
22 changes: 22 additions & 0 deletions modules/setting/deprecated.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package setting

import "fmt"

type DeprecatedWarning struct {
OldSection string
OldKey string
NewSection string
NewKey string
Version string
}

func (dw DeprecatedWarning) String() string {
return fmt.Sprintf("Deprecated fallback `[%s]` `%s` present. Use `[%s]` `%s` instead. This fallback will be/has been removed in %s",
dw.OldSection, dw.OldKey, dw.NewSection, dw.NewKey, dw.Version)
}

// DeprecatedWarnings all warnings which need administrator to change
var DeprecatedWarnings []DeprecatedWarning
9 changes: 8 additions & 1 deletion modules/setting/lfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ func loadLFSFrom(rootCfg ConfigProvider) error {
// Specifically default PATH to LFS_CONTENT_PATH
// DEPRECATED should not be removed because users maybe upgrade from lower version to the latest version
// if these are removed, the warning will not be shown
deprecatedSettingFatal(rootCfg, "server", "LFS_CONTENT_PATH", "lfs", "PATH", "v1.19.0")
deprecatedSetting(rootCfg, "server", "LFS_CONTENT_PATH", "lfs", "PATH", "v1.19.0")

if val := sec.Key("LFS_CONTENT_PATH").String(); val != "" {
if lfsSec == nil {
lfsSec = rootCfg.Section("lfs")
}
lfsSec.Key("PATH").MustString(val)
}

var err error
LFS.Storage, err = getStorage(rootCfg, "lfs", "", lfsSec)
Expand Down
24 changes: 24 additions & 0 deletions modules/setting/lfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,30 @@ func Test_getStorageInheritNameSectionTypeForLFS(t *testing.T) {
assert.EqualValues(t, "minio", LFS.Storage.Type)
assert.EqualValues(t, "lfs/", LFS.Storage.MinioConfig.BasePath)

iniStr = `
[server]
LFS_CONTENT_PATH = path_ignored
[lfs]
PATH = path_used
`
cfg, err = NewConfigProviderFromData(iniStr)
assert.NoError(t, err)
assert.NoError(t, loadLFSFrom(cfg))

assert.EqualValues(t, "local", LFS.Storage.Type)
assert.Contains(t, LFS.Storage.Path, "path_used")

iniStr = `
[server]
LFS_CONTENT_PATH = deprecatedpath
`
cfg, err = NewConfigProviderFromData(iniStr)
assert.NoError(t, err)
assert.NoError(t, loadLFSFrom(cfg))

assert.EqualValues(t, "local", LFS.Storage.Type)
assert.Contains(t, LFS.Storage.Path, "deprecatedpath")

iniStr = `
[storage.lfs]
STORAGE_TYPE = minio
Expand Down
14 changes: 13 additions & 1 deletion routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package web

import (
gocontext "context"
"fmt"
"net/http"

"code.gitea.io/gitea/models/perm"
Expand Down Expand Up @@ -644,7 +645,18 @@ func registerRoutes(m *web.Route) {
m.Get("", admin.RedirectToDefaultSetting)
addSettingsRunnersRoutes()
})
}, adminReq, ctxDataSet("EnableOAuth2", setting.OAuth2.Enable, "EnablePackages", setting.Packages.Enabled))
}, adminReq, ctxDataSet(
"EnableOAuth2", setting.OAuth2.Enable,
"EnablePackages", setting.Packages.Enabled,
), func(ctx *context.Context) {
if len(setting.DeprecatedWarnings) > 0 {
content := setting.DeprecatedWarnings[0].String()
if len(setting.DeprecatedWarnings) > 1 {
content += fmt.Sprintf(" (and %d more)", len(setting.DeprecatedWarnings)-1)
}
ctx.Flash.Error(content)
}
})
lunny marked this conversation as resolved.
Show resolved Hide resolved
// ***** END: Admin *****

m.Group("", func() {
Expand Down
4 changes: 3 additions & 1 deletion templates/admin/layout_head.tmpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{{template "base/head" .ctxData}}
<div role="main" aria-label="{{.ctxData.Title}}" class="page-content {{.pageClass}}">
<div class="ui container negative center aligned">
{{template "base/alert" .ctxData}}
</div>
<div class="ui container admin-container">
{{template "admin/navbar" .ctxData}}
<div class="admin-main">
{{template "base/alert" .ctxData}}
{{/* block: admin-setting-content */}}

{{if false}}{{/* to make html structure "likely" complete to prevent IDE warnings */}}
Expand Down