mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-19 15:14:40 +09:00
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:
1 parent
6579749a02
commit
9bc19f2823
2 files changed
+20
-1
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user