From 816cd117f7ba7f325af9d39974fc23c2b8a30d87 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 8 Feb 2025 15:06:02 +0000 Subject: [PATCH] fix(ui): hide 'New migration' button on org pages with migrations disabled (#6850) (#6851) When migrations are disabled via `[repository].DISABLE_MIGRATIONS = true`, on organisation pages next to the 'New repository' button, the 'New migration' button is still shown. This is caused by a logic error in the templates: instead of checking for disabled migrations, it checks for disabled pull mirrors. This patch fixes that to use `DisableMigrations` instead of `DisableNewPullMirrors`. Signed-off-by: Daniel Baumann Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6851 Reviewed-by: Beowulf Reviewed-by: 0ko <0ko@noreply.codeberg.org> Reviewed-by: Gusted Co-authored-by: Daniel Baumann Co-committed-by: Daniel Baumann --- templates/org/home.tmpl | 2 +- tests/integration/org_test.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl index 3ae5f01d04..a4fafc3432 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -23,7 +23,7 @@ {{if .CanCreateOrgRepo}}
{{ctx.Locale.Tr "new_repo.link"}} - {{if not .DisableNewPullMirrors}} + {{if not .DisableMigrations}} {{ctx.Locale.Tr "new_migrate.link"}} {{end}}
diff --git a/tests/integration/org_test.go b/tests/integration/org_test.go index 74579d7d51..eabfe11dcd 100644 --- a/tests/integration/org_test.go +++ b/tests/integration/org_test.go @@ -15,7 +15,9 @@ import ( "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/tests" "github.com/stretchr/testify/assert" @@ -266,3 +268,32 @@ func TestOwnerTeamUnit(t *testing.T) { unittest.AssertExistsAndLoadBean(t, &organization.TeamUnit{TeamID: 1, Type: unit.TypeIssues, AccessMode: perm.AccessModeOwner}) } + +func TestOrgNewMigrationButton(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + migrateSelector := `a[href^="/repo/migrate?org="]` + + session := loginUser(t, "user2") + t.Run("Migration disabled", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + defer test.MockVariableValue(&setting.Repository.DisableMigrations, true)() + + req := NewRequest(t, "GET", "/org3") + resp := session.MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + htmlDoc.AssertElement(t, migrateSelector, false) + }) + + t.Run("Migration enabled", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + defer test.MockVariableValue(&setting.Repository.DisableMigrations, false)() + + req := NewRequest(t, "GET", "/org3") + resp := session.MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + htmlDoc.AssertElement(t, migrateSelector, true) + }) +}