diff --git a/routers/web/admin/admin.go b/routers/web/admin/admin.go index 96a714376b..4e913ef9a1 100644 --- a/routers/web/admin/admin.go +++ b/routers/web/admin/admin.go @@ -135,7 +135,27 @@ func Dashboard(ctx *context.Context) { ctx.Data["RemoteVersion"] = updatechecker.GetRemoteVersion(ctx) updateSystemStatus() ctx.Data["SysStatus"] = sysStatus - ctx.Data["SSH"] = setting.SSH + + entries := []string{ + "delete_inactive_accounts", + "delete_repo_archives", + "delete_missing_repos", + "git_gc_repos", + } + if !setting.SSH.Disabled && !setting.SSH.StartBuiltinServer { + entries = append(entries, "resync_all_sshkeys", "resync_all_sshprincipals") + } + entries = append(entries, []string{ + "resync_all_hooks", + "reinit_missing_repos", + "sync_external_users", + "repo_health_check", + "delete_generated_repository_avatars", + "sync_repo_branches", + "sync_repo_tags", + }...) + ctx.Data["Entries"] = entries + prepareDeprecatedWarningsAlert(ctx) ctx.HTML(http.StatusOK, tplDashboard) } diff --git a/templates/admin/cron.tmpl b/templates/admin/cron.tmpl index 7df42afc0b..a89450c571 100644 --- a/templates/admin/cron.tmpl +++ b/templates/admin/cron.tmpl @@ -20,7 +20,7 @@ {{range .Entries}} - + {{ctx.Locale.Tr (printf "admin.dashboard.%s" .Name)}} {{.Spec}} {{DateUtils.FullTime .Next}} diff --git a/templates/admin/dashboard.tmpl b/templates/admin/dashboard.tmpl index 53f0259f96..c436e8a804 100644 --- a/templates/admin/dashboard.tmpl +++ b/templates/admin/dashboard.tmpl @@ -12,60 +12,16 @@
- - - - - - - - - - - - - - - - - {{if and (not .SSH.Disabled) (not .SSH.StartBuiltinServer)}} + {{range .Entries}} - - - - - - + + {{end}} - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{{ctx.Locale.Tr "admin.dashboard.delete_inactive_accounts"}}
{{ctx.Locale.Tr "admin.dashboard.delete_repo_archives"}}
{{ctx.Locale.Tr "admin.dashboard.delete_missing_repos"}}
{{ctx.Locale.Tr "admin.dashboard.git_gc_repos"}}
{{ctx.Locale.Tr "admin.dashboard.resync_all_sshkeys"}}
{{ctx.Locale.Tr "admin.dashboard.resync_all_sshprincipals"}}{{ctx.Locale.Tr (printf "admin.dashboard.%s" .)}} + +
{{ctx.Locale.Tr "admin.dashboard.resync_all_hooks"}}
{{ctx.Locale.Tr "admin.dashboard.reinit_missing_repos"}}
{{ctx.Locale.Tr "admin.dashboard.sync_external_users"}}
{{ctx.Locale.Tr "admin.dashboard.repo_health_check"}}
{{ctx.Locale.Tr "admin.dashboard.delete_generated_repository_avatars"}}
{{ctx.Locale.Tr "admin.dashboard.sync_repo_branches"}}
{{ctx.Locale.Tr "admin.dashboard.sync_repo_tags"}}
diff --git a/tests/integration/admin_dashboard_test.go b/tests/integration/admin_dashboard_test.go new file mode 100644 index 0000000000..be4e97d56c --- /dev/null +++ b/tests/integration/admin_dashboard_test.go @@ -0,0 +1,79 @@ +// Copyright 2025 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: GPL-3.0-or-later + +package integration + +import ( + "fmt" + "net/http" + "testing" + + "forgejo.org/modules/setting" + "forgejo.org/modules/test" + "forgejo.org/modules/translation" + "forgejo.org/tests" +) + +var commonEntries = []string{ + "delete_inactive_accounts", + "delete_repo_archives", + "delete_missing_repos", + "git_gc_repos", + "resync_all_hooks", + "reinit_missing_repos", + "sync_external_users", + "repo_health_check", + "delete_generated_repository_avatars", + "sync_repo_branches", + "sync_repo_tags", +} + +var sshEntries = []string{ + "resync_all_sshkeys", + "resync_all_sshprincipals", +} + +func testAssertAdminDashboardEntries(t *testing.T, page *HTMLDoc, locale translation.Locale, expectSSH bool) { + for _, entry := range commonEntries { + page.AssertSelection(t, page.FindByText("table tr td", locale.TrString(fmt.Sprintf("admin.dashboard.%s", entry))), true) + page.AssertSelection(t, page.Find(fmt.Sprintf("table tr td button[value='%s']", entry)), true) + } + for _, entry := range sshEntries { + page.AssertSelection(t, page.FindByText("table tr td", locale.TrString(fmt.Sprintf("admin.dashboard.%s", entry))), expectSSH) + page.AssertSelection(t, page.Find(fmt.Sprintf("table tr td button[value='%s']", entry)), expectSSH) + } +} + +func TestAdminDashboard(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + session := loginUser(t, "user1") + locale := translation.NewLocale("en-US") + url := "/admin" + + t.Run("SSH disabled", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + defer test.MockVariableValue(&setting.SSH.Disabled, true)() + + page := NewHTMLParser(t, session.MakeRequest(t, NewRequest(t, "GET", url), http.StatusOK).Body) + testAssertAdminDashboardEntries(t, page, locale, false) + }) + + t.Run("SSH enabled, but built-in", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + defer test.MockVariableValue(&setting.SSH.Disabled, false)() + defer test.MockVariableValue(&setting.SSH.StartBuiltinServer, true)() + + page := NewHTMLParser(t, session.MakeRequest(t, NewRequest(t, "GET", url), http.StatusOK).Body) + testAssertAdminDashboardEntries(t, page, locale, false) + }) + + t.Run("SSH enabled and external", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + defer test.MockVariableValue(&setting.SSH.Disabled, false)() + defer test.MockVariableValue(&setting.SSH.StartBuiltinServer, false)() + + page := NewHTMLParser(t, session.MakeRequest(t, NewRequest(t, "GET", url), http.StatusOK).Body) + testAssertAdminDashboardEntries(t, page, locale, true) + }) +}