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>
This commit is contained in:
Gergely Nagy 2024-02-04 09:43:59 +01:00
parent f36726b922
commit 0ca118fdc3
No known key found for this signature in database
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.Post("", web.Bind(forms.AdminDashboardForm{}), admin.DashboardPost)
if setting.Database.Type.IsMySQL() || setting.Database.Type.IsMSSQL() {
m.Get("/self_check", admin.SelfCheck)
}
m.Group("/config", func() {
m.Get("", admin.Config)

View file

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

View file

@ -1,9 +1,11 @@
// 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
package integration
import (
"net/http"
"testing"
"time"
@ -21,6 +23,29 @@ type TestCollationTbl struct {
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) {
x := db.GetEngine(db.DefaultContext).(*xorm.Engine)