Skip to content

Commit 5dc37ef

Browse files
lunnywxiaoguang
andauthored
Display deprecated warning in admin panel pages as well as in the log file (#26094)
This PR includes #26007 's changes but have a UI to prompt administrator about the deprecated settings as well as the log or console warning. Then users will have enough time to notice the problem and don't have surprise like before. <img width="1293" alt="图片" src="https://github.com/go-gitea/gitea/assets/81045/c33355f0-1ea7-4fb3-ad43-cd23cd15391d"> --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
1 parent 915cdf8 commit 5dc37ef

File tree

7 files changed

+55
-9
lines changed

7 files changed

+55
-9
lines changed

modules/setting/config_provider.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,14 @@ func mustMapSetting(rootCfg ConfigProvider, sectionName string, setting any) {
316316
}
317317
}
318318

319-
func deprecatedSetting(rootCfg ConfigProvider, oldSection, oldKey, newSection, newKey, version string) {
320-
if rootCfg.Section(oldSection).HasKey(oldKey) {
321-
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)
322-
}
323-
}
319+
// DeprecatedWarnings contains the warning message for various deprecations, including: setting option, file/folder, etc
320+
var DeprecatedWarnings []string
324321

325-
func deprecatedSettingFatal(rootCfg ConfigProvider, oldSection, oldKey, newSection, newKey, version string) {
322+
func deprecatedSetting(rootCfg ConfigProvider, oldSection, oldKey, newSection, newKey, version string) {
326323
if rootCfg.Section(oldSection).HasKey(oldKey) {
327-
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)
324+
msg := fmt.Sprintf("Deprecated config option `[%s]` `%s` present. Use `[%s]` `%s` instead. This fallback will be/has been removed in %s", oldSection, oldKey, newSection, newKey, version)
325+
log.Error("%v", msg)
326+
DeprecatedWarnings = append(DeprecatedWarnings, msg)
328327
}
329328
}
330329

modules/setting/lfs.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@ func loadLFSFrom(rootCfg ConfigProvider) error {
3434
// Specifically default PATH to LFS_CONTENT_PATH
3535
// DEPRECATED should not be removed because users maybe upgrade from lower version to the latest version
3636
// if these are removed, the warning will not be shown
37-
deprecatedSettingFatal(rootCfg, "server", "LFS_CONTENT_PATH", "lfs", "PATH", "v1.19.0")
37+
deprecatedSetting(rootCfg, "server", "LFS_CONTENT_PATH", "lfs", "PATH", "v1.19.0")
38+
39+
if val := sec.Key("LFS_CONTENT_PATH").String(); val != "" {
40+
if lfsSec == nil {
41+
lfsSec = rootCfg.Section("lfs")
42+
}
43+
lfsSec.Key("PATH").MustString(val)
44+
}
3845

3946
var err error
4047
LFS.Storage, err = getStorage(rootCfg, "lfs", "", lfsSec)

modules/setting/lfs_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,30 @@ func Test_getStorageInheritNameSectionTypeForLFS(t *testing.T) {
2121
assert.EqualValues(t, "minio", LFS.Storage.Type)
2222
assert.EqualValues(t, "lfs/", LFS.Storage.MinioConfig.BasePath)
2323

24+
iniStr = `
25+
[server]
26+
LFS_CONTENT_PATH = path_ignored
27+
[lfs]
28+
PATH = path_used
29+
`
30+
cfg, err = NewConfigProviderFromData(iniStr)
31+
assert.NoError(t, err)
32+
assert.NoError(t, loadLFSFrom(cfg))
33+
34+
assert.EqualValues(t, "local", LFS.Storage.Type)
35+
assert.Contains(t, LFS.Storage.Path, "path_used")
36+
37+
iniStr = `
38+
[server]
39+
LFS_CONTENT_PATH = deprecatedpath
40+
`
41+
cfg, err = NewConfigProviderFromData(iniStr)
42+
assert.NoError(t, err)
43+
assert.NoError(t, loadLFSFrom(cfg))
44+
45+
assert.EqualValues(t, "local", LFS.Storage.Type)
46+
assert.Contains(t, LFS.Storage.Path, "deprecatedpath")
47+
2448
iniStr = `
2549
[storage.lfs]
2650
STORAGE_TYPE = minio

routers/web/admin/admin.go

+11
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ func updateSystemStatus() {
113113
sysStatus.NumGC = m.NumGC
114114
}
115115

116+
func prepareDeprecatedWarningsAlert(ctx *context.Context) {
117+
if len(setting.DeprecatedWarnings) > 0 {
118+
content := setting.DeprecatedWarnings[0]
119+
if len(setting.DeprecatedWarnings) > 1 {
120+
content += fmt.Sprintf(" (and %d more)", len(setting.DeprecatedWarnings)-1)
121+
}
122+
ctx.Flash.Error(content, true)
123+
}
124+
}
125+
116126
// Dashboard show admin panel dashboard
117127
func Dashboard(ctx *context.Context) {
118128
ctx.Data["Title"] = ctx.Tr("admin.dashboard")
@@ -123,6 +133,7 @@ func Dashboard(ctx *context.Context) {
123133
updateSystemStatus()
124134
ctx.Data["SysStatus"] = sysStatus
125135
ctx.Data["SSH"] = setting.SSH
136+
prepareDeprecatedWarningsAlert(ctx)
126137
ctx.HTML(http.StatusOK, tplDashboard)
127138
}
128139

routers/web/admin/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ func Config(ctx *context.Context) {
171171

172172
ctx.Data["Loggers"] = log.GetManager().DumpLoggers()
173173

174+
prepareDeprecatedWarningsAlert(ctx)
175+
174176
ctx.HTML(http.StatusOK, tplConfig)
175177
}
176178

templates/admin/layout_head.tmpl

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{{template "base/head" .ctxData}}
22
<div role="main" aria-label="{{.ctxData.Title}}" class="page-content {{.pageClass}}">
3+
<div class="ui container">
4+
{{template "base/alert" .ctxData}}
5+
</div>
36
<div class="ui container admin-container">
47
{{template "admin/navbar" .ctxData}}
58
<div class="admin-main">
6-
{{template "base/alert" .ctxData}}
79
{{/* block: admin-setting-content */}}
810

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

web_src/css/admin.css

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.admin-container {
2+
margin-top: 15px;
23
display: flex !important;
34
gap: 16px;
45
}

0 commit comments

Comments
 (0)