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
This commit is contained in:
bircni authored and GitHub committed 2026-11-15 12:50:48 +00:00
1 parent 6579749a02
commit 9bc19f2823
2 files changed
+20 -1

No files matched your search

+5 -1
View File
@@ -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
}
+15
View File
@@ -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()