From 9bc19f28230145d1026985cfd71edc0be2b7e86a Mon Sep 17 00:00:00 2001 From: bircni Date: Sun, 15 Nov 2026 12:50:48 +0000 Subject: [PATCH] fix(api): do not allow renaming the Owners team (#40381) The API accepted a new name for an organization's Owners team. The owner team is looked up by its name, so the organization had no owner team afterwards and its owners lost access to it. The API now rejects the rename, as the web UI already does. Fixes #40380 --- routers/api/v1/org/team.go | 6 +++++- tests/integration/api_team_test.go | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index 9fbab29092e..d9ab45ff853 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -273,7 +273,11 @@ func EditTeam(ctx *context.APIContext) { team.CanCreateOrgRepo = team.IsOwnerTeam() || *form.CanCreateOrgRepo } - if len(form.Name) > 0 { + if len(form.Name) > 0 && form.Name != team.Name { + if team.IsOwnerTeam() { + ctx.APIError(http.StatusUnprocessableEntity, "the owner team cannot be renamed") + return + } team.Name = form.Name } diff --git a/tests/integration/api_team_test.go b/tests/integration/api_team_test.go index cd4f70d9702..ef37b373e9f 100644 --- a/tests/integration/api_team_test.go +++ b/tests/integration/api_team_test.go @@ -248,6 +248,21 @@ func TestAPITeam(t *testing.T) { unittest.AssertNotExistsBean(t, &organization.Team{ID: teamID}) }) + t.Run("RenameOwnerTeam", func(t *testing.T) { + ownerTeam := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 1, Name: organization.OwnerTeamName}) + token := getUserToken(t, "user2", auth_model.AccessTokenScopeWriteOrganization) + teamURL := fmt.Sprintf("/api/v1/teams/%d", ownerTeam.ID) + + req := NewRequestWithJSON(t, "PATCH", teamURL, api.EditTeamOption{Name: "renamed"}).AddTokenAuth(token) + MakeRequest(t, req, http.StatusUnprocessableEntity) + unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: ownerTeam.ID, Name: organization.OwnerTeamName}) + + description := "owner team" + req = NewRequestWithJSON(t, "PATCH", teamURL, api.EditTeamOption{Name: organization.OwnerTeamName, Description: &description}).AddTokenAuth(token) + MakeRequest(t, req, http.StatusOK) + unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: ownerTeam.ID, Name: organization.OwnerTeamName, Description: description}) + }) + t.Run("VisibilityAccess", func(t *testing.T) { insertTestTeam := func(t *testing.T, orgID int64, name string, visibility structs.VisibleType) *organization.Team { t.Helper()