loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Lunny Xiao
wxiaoguang
and committed by
GitHub
5dc37ef9 915cdf8f

+55 -9
+6 -7
modules/setting/config_provider.go
··· 316 316 } 317 317 } 318 318 319 + // DeprecatedWarnings contains the warning message for various deprecations, including: setting option, file/folder, etc 320 + var DeprecatedWarnings []string 321 + 319 322 func deprecatedSetting(rootCfg ConfigProvider, oldSection, oldKey, newSection, newKey, version string) { 320 323 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 - } 324 - 325 - func deprecatedSettingFatal(rootCfg ConfigProvider, oldSection, oldKey, newSection, newKey, version string) { 326 - 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) 328 327 } 329 328 } 330 329
+8 -1
modules/setting/lfs.go
··· 34 34 // Specifically default PATH to LFS_CONTENT_PATH 35 35 // DEPRECATED should not be removed because users maybe upgrade from lower version to the latest version 36 36 // 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 + } 38 45 39 46 var err error 40 47 LFS.Storage, err = getStorage(rootCfg, "lfs", "", lfsSec)
+24
modules/setting/lfs_test.go
··· 22 22 assert.EqualValues(t, "lfs/", LFS.Storage.MinioConfig.BasePath) 23 23 24 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 + 48 + iniStr = ` 25 49 [storage.lfs] 26 50 STORAGE_TYPE = minio 27 51 `
+11
routers/web/admin/admin.go
··· 113 113 sysStatus.NumGC = m.NumGC 114 114 } 115 115 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 + 116 126 // Dashboard show admin panel dashboard 117 127 func Dashboard(ctx *context.Context) { 118 128 ctx.Data["Title"] = ctx.Tr("admin.dashboard") ··· 123 133 updateSystemStatus() 124 134 ctx.Data["SysStatus"] = sysStatus 125 135 ctx.Data["SSH"] = setting.SSH 136 + prepareDeprecatedWarningsAlert(ctx) 126 137 ctx.HTML(http.StatusOK, tplDashboard) 127 138 } 128 139
+2
routers/web/admin/config.go
··· 171 171 172 172 ctx.Data["Loggers"] = log.GetManager().DumpLoggers() 173 173 174 + prepareDeprecatedWarningsAlert(ctx) 175 + 174 176 ctx.HTML(http.StatusOK, tplConfig) 175 177 } 176 178
+3 -1
templates/admin/layout_head.tmpl
··· 1 1 {{template "base/head" .ctxData}} 2 2 <div role="main" aria-label="{{.ctxData.Title}}" class="page-content {{.pageClass}}"> 3 + <div class="ui container"> 4 + {{template "base/alert" .ctxData}} 5 + </div> 3 6 <div class="ui container admin-container"> 4 7 {{template "admin/navbar" .ctxData}} 5 8 <div class="admin-main"> 6 - {{template "base/alert" .ctxData}} 7 9 {{/* block: admin-setting-content */}} 8 10 9 11 {{if false}}{{/* to make html structure "likely" complete to prevent IDE warnings */}}
+1
web_src/css/admin.css
··· 1 1 .admin-container { 2 + margin-top: 15px; 2 3 display: flex !important; 3 4 gap: 16px; 4 5 }