This commit is contained in:
Lunny Xiao 2024-10-30 10:59:08 -07:00
parent 253ec37632
commit afade2f0c7
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
4 changed files with 24 additions and 16 deletions

View File

@ -84,7 +84,7 @@ func TestUpdateTeam(t *testing.T) {
team.Name = "newName"
team.Description = strings.Repeat("A long description!", 100)
team.AccessMode = perm.AccessModeAdmin
assert.NoError(t, UpdateTeam(db.DefaultContext, team, "authorize"))
assert.NoError(t, UpdateTeam(db.DefaultContext, team, "name", "lower_name", "description", "authorize"))
team = unittest.AssertExistsAndLoadBean(t, &organization.Team{Name: "newName"})
assert.True(t, strings.HasPrefix(team.Description, "A long description!"))
@ -103,7 +103,7 @@ func TestUpdateTeam2(t *testing.T) {
team.LowerName = "owners"
team.Name = "Owners"
team.Description = strings.Repeat("A long description!", 100)
err := UpdateTeam(db.DefaultContext, team, "authorize")
err := UpdateTeam(db.DefaultContext, team, "name", "lower_name", "description", "authorize")
assert.True(t, organization.IsErrTeamAlreadyExist(err))
unittest.CheckConsistencyFor(t, &organization.Team{ID: team.ID})

View File

@ -44,7 +44,7 @@ type EditTeamOption struct {
Description *string `json:"description" binding:"MaxSize(255)"`
IncludesAllRepositories *bool `json:"includes_all_repositories"`
// enum: read,write,admin
Permission string `json:"permission" binding:"Required;In(read,write,admin)"`
Permission string `json:"permission"`
// example: ["repo.code","repo.issues","repo.ext_issues","repo.wiki","repo.pulls","repo.releases","repo.projects","repo.ext_wiki"]
// Deprecated: This variable should be replaced by UnitsMap and will be dropped in later versions.
Units []string `json:"units"`

View File

@ -57,7 +57,7 @@ func (f *UpdateOrgSettingForm) Validate(req *http.Request, errs binding.Errors)
type CreateTeamForm struct {
TeamName string `binding:"Required;AlphaDashDot;MaxSize(255)"`
Description string `binding:"MaxSize(255)"`
Permission string `binding:"Required;In(read,write,admin)"`
Permission string `binding:"Required;In(,read,write,admin)"`
RepoAccess string `binding:"Required;In(specified, all)"`
CanCreateOrgRepo bool
}

View File

@ -5,6 +5,7 @@ package org
import (
"context"
"strings"
"code.gitea.io/gitea/models"
org_model "code.gitea.io/gitea/models/organization"
@ -34,7 +35,12 @@ func UpdateTeam(ctx context.Context, team *org_model.Team, opts UpdateTeamOption
}
if !team.IsOwnerTeam() {
team.Name = opts.TeamName
if team.Name != opts.TeamName {
team.Name = opts.TeamName
team.LowerName = strings.ToLower(opts.TeamName)
changedCols = append(changedCols, "name", "lower_name")
}
if team.AccessMode != newAccessMode {
team.AccessMode = newAccessMode
changedCols = append(changedCols, "authorize")
@ -44,22 +50,24 @@ func UpdateTeam(ctx context.Context, team *org_model.Team, opts UpdateTeamOption
team.IncludesAllRepositories = opts.IncludesAllRepositories
changedCols = append(changedCols, "includes_all_repositories")
}
units := make([]*org_model.TeamUnit, 0, len(opts.UnitPerms))
for tp, perm := range opts.UnitPerms {
units = append(units, &org_model.TeamUnit{
OrgID: team.OrgID,
TeamID: team.ID,
Type: tp,
AccessMode: perm,
})
if len(opts.UnitPerms) > 0 {
units := make([]*org_model.TeamUnit, 0, len(opts.UnitPerms))
for tp, perm := range opts.UnitPerms {
units = append(units, &org_model.TeamUnit{
OrgID: team.OrgID,
TeamID: team.ID,
Type: tp,
AccessMode: perm,
})
}
team.Units = units
changedCols = append(changedCols, "units")
}
team.Units = units
changedCols = append(changedCols, "units")
if team.CanCreateOrgRepo != opts.CanCreateOrgRepo {
team.CanCreateOrgRepo = opts.CanCreateOrgRepo
changedCols = append(changedCols, "can_create_org_repo")
}
} else {
} else { // make the possible legacy data correct, we force to update these fields
team.CanCreateOrgRepo = true
team.IncludesAllRepositories = true
changedCols = append(changedCols, "can_create_org_repo", "includes_all_repositories")