[GITEA] admin: "Self Check" should only show for some db types

The "Self Check" menu essentially runs the collation check that is also
performed at startup, and displays the results. This is only a thing for
MariaDB/MySQL and MSSQL. As such, the menu item should only be available
for these database types.

Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
(cherry picked from commit 0ca118fdc3c39c0e7adf9285e074e5878a0ca1c1)
This commit is contained in:
Gergely Nagy 2024-02-04 09:43:59 +01:00 committed by Earl Warren
parent 76c2f5bf92
commit c335d076aa
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
3 changed files with 30 additions and 1 deletions

View file

@ -676,7 +676,9 @@ func registerRoutes(m *web.Route) {
m.Get("", admin.Dashboard) m.Get("", admin.Dashboard)
m.Post("", web.Bind(forms.AdminDashboardForm{}), admin.DashboardPost) m.Post("", web.Bind(forms.AdminDashboardForm{}), admin.DashboardPost)
m.Get("/self_check", admin.SelfCheck) if setting.Database.Type.IsMySQL() || setting.Database.Type.IsMSSQL() {
m.Get("/self_check", admin.SelfCheck)
}
m.Group("/config", func() { m.Group("/config", func() {
m.Get("", admin.Config) m.Get("", admin.Config)

View file

@ -4,9 +4,11 @@
<a class="{{if .PageIsAdminDashboard}}active {{end}}item" href="{{AppSubUrl}}/admin"> <a class="{{if .PageIsAdminDashboard}}active {{end}}item" href="{{AppSubUrl}}/admin">
{{ctx.Locale.Tr "admin.dashboard"}} {{ctx.Locale.Tr "admin.dashboard"}}
</a> </a>
{{if or .DatabaseType.IsMySQL .DatabaseType.IsMSSQL}}
<a class="{{if .PageIsAdminSelfCheck}}active {{end}}item" href="{{AppSubUrl}}/admin/self_check"> <a class="{{if .PageIsAdminSelfCheck}}active {{end}}item" href="{{AppSubUrl}}/admin/self_check">
{{ctx.Locale.Tr "admin.self_check"}} {{ctx.Locale.Tr "admin.self_check"}}
</a> </a>
{{end}}
<details class="item toggleable-item" {{if or .PageIsAdminUsers .PageIsAdminEmails .PageIsAdminOrganizations .PageIsAdminAuthentications}}open{{end}}> <details class="item toggleable-item" {{if or .PageIsAdminUsers .PageIsAdminEmails .PageIsAdminOrganizations .PageIsAdminAuthentications}}open{{end}}>
<summary>{{ctx.Locale.Tr "admin.identity_access"}}</summary> <summary>{{ctx.Locale.Tr "admin.identity_access"}}</summary>
<div class="menu"> <div class="menu">

View file

@ -1,9 +1,11 @@
// Copyright 2023 The Gitea Authors. All rights reserved. // Copyright 2023 The Gitea Authors. All rights reserved.
// Copyright 2024 The Forgejo Authors c/o Codeberg e.V.. All rights reserved.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
package integration package integration
import ( import (
"net/http"
"testing" "testing"
"time" "time"
@ -21,6 +23,29 @@ type TestCollationTbl struct {
Txt string `xorm:"VARCHAR(10) UNIQUE"` Txt string `xorm:"VARCHAR(10) UNIQUE"`
} }
func TestDatabaseCollationSelfCheckUI(t *testing.T) {
defer tests.PrepareTestEnv(t)()
assertSelfCheckExists := func(exists bool) {
expectedHTTPResponse := http.StatusOK
if !exists {
expectedHTTPResponse = http.StatusNotFound
}
session := loginUser(t, "user1")
req := NewRequest(t, "GET", "/admin/self_check")
resp := session.MakeRequest(t, req, expectedHTTPResponse)
htmlDoc := NewHTMLParser(t, resp.Body)
htmlDoc.AssertElement(t, "a.item[href*='/admin/self_check']", exists)
}
if setting.Database.Type.IsMySQL() || setting.Database.Type.IsMSSQL() {
assertSelfCheckExists(true)
} else {
assertSelfCheckExists(false)
}
}
func TestDatabaseCollation(t *testing.T) { func TestDatabaseCollation(t *testing.T) {
x := db.GetEngine(db.DefaultContext).(*xorm.Engine) x := db.GetEngine(db.DefaultContext).(*xorm.Engine)