mirror of
https://github.com/go-gitea/gitea
synced 2024-12-30 18:15:59 +01:00
Fix update team
This commit is contained in:
parent
c7262d65c7
commit
088cffb688
@ -12,7 +12,6 @@ import (
|
||||
git_model "code.gitea.io/gitea/models/git"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
"code.gitea.io/gitea/models/organization"
|
||||
org_model "code.gitea.io/gitea/models/organization"
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
access_model "code.gitea.io/gitea/models/perm/access"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
@ -101,7 +100,7 @@ type UpdateTeamOptions struct {
|
||||
UnitPerms map[unit_model.Type]perm.AccessMode
|
||||
}
|
||||
|
||||
func UpdateTeam(ctx context.Context, team *org_model.Team, opts UpdateTeamOptions) error {
|
||||
func UpdateTeam(ctx context.Context, team *organization.Team, opts UpdateTeamOptions) error {
|
||||
var changedCols []string
|
||||
|
||||
newAccessMode := team.AccessMode
|
||||
@ -130,9 +129,9 @@ func UpdateTeam(ctx context.Context, team *org_model.Team, opts UpdateTeamOption
|
||||
changedCols = append(changedCols, "includes_all_repositories")
|
||||
}
|
||||
if len(opts.UnitPerms) > 0 {
|
||||
units := make([]*org_model.TeamUnit, 0, len(opts.UnitPerms))
|
||||
units := make([]*organization.TeamUnit, 0, len(opts.UnitPerms))
|
||||
for tp, perm := range opts.UnitPerms {
|
||||
units = append(units, &org_model.TeamUnit{
|
||||
units = append(units, &organization.TeamUnit{
|
||||
OrgID: team.OrgID,
|
||||
TeamID: team.ID,
|
||||
Type: tp,
|
||||
@ -157,7 +156,7 @@ func UpdateTeam(ctx context.Context, team *org_model.Team, opts UpdateTeamOption
|
||||
team.Description = opts.Description
|
||||
}
|
||||
|
||||
return org_model.UpdateTeam(ctx, team, changedCols...)
|
||||
return organization.UpdateTeam(ctx, team, changedCols...)
|
||||
}
|
||||
|
||||
// UpdateTeam updates information of team.
|
||||
|
@ -78,11 +78,14 @@ func TestUpdateTeam(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 2})
|
||||
team.LowerName = "newname"
|
||||
team.Name = "newName"
|
||||
team.Description = strings.Repeat("A long description!", 100)
|
||||
team.AccessMode = perm.AccessModeAdmin
|
||||
assert.NoError(t, UpdateTeam(db.DefaultContext, team, "name", "lower_name", "description", "authorize"))
|
||||
assert.NoError(t, UpdateTeam(db.DefaultContext, team, UpdateTeamOptions{
|
||||
TeamName: "name",
|
||||
Description: "description",
|
||||
IsAdmin: true,
|
||||
}))
|
||||
|
||||
team = unittest.AssertExistsAndLoadBean(t, &organization.Team{Name: "newName"})
|
||||
assert.True(t, strings.HasPrefix(team.Description, "A long description!"))
|
||||
@ -101,7 +104,10 @@ func TestUpdateTeam2(t *testing.T) {
|
||||
team.LowerName = "owners"
|
||||
team.Name = "Owners"
|
||||
team.Description = strings.Repeat("A long description!", 100)
|
||||
err := UpdateTeam(db.DefaultContext, team, "name", "lower_name", "description", "authorize")
|
||||
err := UpdateTeam(db.DefaultContext, team, UpdateTeamOptions{
|
||||
TeamName: "name",
|
||||
Description: "description",
|
||||
})
|
||||
assert.True(t, organization.IsErrTeamAlreadyExist(err))
|
||||
|
||||
unittest.CheckConsistencyFor(t, &organization.Team{ID: team.ID})
|
||||
@ -277,7 +283,10 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
|
||||
teams[4].IncludesAllRepositories = true
|
||||
teamRepos[4] = repoIDs
|
||||
for i, team := range teams {
|
||||
assert.NoError(t, UpdateTeam(db.DefaultContext, team, false, true), "%s: UpdateTeam", team.Name)
|
||||
assert.NoError(t, UpdateTeam(db.DefaultContext, team, UpdateTeamOptions{
|
||||
IncludesAllRepositories: false,
|
||||
CanCreateOrgRepo: true,
|
||||
}), "%s: UpdateTeam", team.Name)
|
||||
testTeamRepositories(team.ID, teamRepos[i])
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user