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()