fix(api): do not allow renaming the Owners team (#40381) (#40387)

Backport https://github.com/go-gitea/gitea/pull/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 13:41:13 +00:00
1 parent 58df887de6
commit df961a3962
2 files changed
+22 -1

No files matched your search

+5 -1
View File
@@ -279,7 +279,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
}
+17
View File
@@ -225,6 +225,23 @@ type TeamSearchResults struct {
Data []*api.Team `json:"data"`
}
func TestAPITeamRenameOwnerTeam(t *testing.T) {
defer tests.PrepareTestEnv(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})
}
func TestAPITeamSearch(t *testing.T) {
defer tests.PrepareTestEnv(t)()