Skip to content

Commit c598741

Browse files
authored
Display deprecated warning in admin panel pages as well as in the log file (#26094) (#26154)
backport #26094 Temporily resolve #25915 Related #25994 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">
1 parent bc73e6a commit c598741

File tree

8 files changed

+80
-12
lines changed

8 files changed

+80
-12
lines changed

modules/setting/config_provider.go

Lines changed: 6 additions & 7 deletions
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

Lines changed: 8 additions & 1 deletion
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

Lines changed: 24 additions & 0 deletions
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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ func updateSystemStatus() {
110110
sysStatus.NumGC = m.NumGC
111111
}
112112

113+
func prepareDeprecatedWarningsAlert(ctx *context.Context) {
114+
if len(setting.DeprecatedWarnings) > 0 {
115+
content := setting.DeprecatedWarnings[0]
116+
if len(setting.DeprecatedWarnings) > 1 {
117+
content += fmt.Sprintf(" (and %d more)", len(setting.DeprecatedWarnings)-1)
118+
}
119+
ctx.Flash.Error(content, true)
120+
}
121+
}
122+
113123
// Dashboard show admin panel dashboard
114124
func Dashboard(ctx *context.Context) {
115125
ctx.Data["Title"] = ctx.Tr("admin.dashboard")
@@ -120,6 +130,7 @@ func Dashboard(ctx *context.Context) {
120130
updateSystemStatus()
121131
ctx.Data["SysStatus"] = sysStatus
122132
ctx.Data["SSH"] = setting.SSH
133+
prepareDeprecatedWarningsAlert(ctx)
123134
ctx.HTML(http.StatusOK, tplDashboard)
124135
}
125136

routers/web/admin/config.go

Lines changed: 2 additions & 0 deletions
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

Lines changed: 5 additions & 3 deletions
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 stackable grid">
3+
<div class="ui container">
4+
{{template "base/alert" .ctxData}}
5+
</div>
6+
<div class="ui container admin-container">
47
{{template "admin/navbar" .ctxData}}
5-
<div class="twelve wide column">
6-
{{template "base/alert" .ctxData}}
8+
<div class="admin-main">
79
{{/* block: admin-setting-content */}}
810

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

templates/admin/navbar.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="four wide column">
1+
<div class="admin-nav">
22
<div class="ui fluid vertical menu">
33
<div class="header item">{{.locale.Tr "settings"}}</div>
44
<a class="{{if .PageIsAdminDashboard}}active {{end}}item" href="{{AppSubUrl}}/admin">

web_src/css/admin.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
.admin-container {
2+
margin-top: 15px;
3+
display: flex !important;
4+
gap: 16px;
5+
}
6+
7+
.admin-nav {
8+
width: 240px;
9+
}
10+
11+
.admin-main {
12+
flex: 1;
13+
}
14+
15+
@media (max-width: 767.98px) {
16+
.admin-container {
17+
flex-direction: column;
18+
}
19+
.admin-nav {
20+
width: auto;
21+
}
22+
}
23+
124
.admin.hooks .list > .item:not(:first-child) {
225
border-top: 1px solid var(--color-secondary);
326
padding: 0.25rem 1rem;

0 commit comments

Comments
 (0)