Skip to content

Commit 8e1cac1

Browse files
committed
Use UpdateTeamOptions instead of multiple parameters of function
1 parent df785f6 commit 8e1cac1

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

routers/api/v1/org/team.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,14 @@ func EditTeam(ctx *context.APIContext) {
320320
}
321321
}
322322

323-
if err := org_service.UpdateTeam(ctx, team,
324-
teamName,
325-
description,
326-
form.Permission == "admin",
327-
includeAllRepos,
328-
canCreateOrgRepo,
329-
unitPerms,
330-
); err != nil {
323+
if err := org_service.UpdateTeam(ctx, team, org_service.UpdateTeamOptions{
324+
TeamName: teamName,
325+
Description: description,
326+
IsAdmin: form.Permission == "admin",
327+
IncludesAllRepositories: includeAllRepos,
328+
CanCreateOrgRepo: canCreateOrgRepo,
329+
UnitPerms: unitPerms,
330+
}); err != nil {
331331
ctx.Error(http.StatusInternalServerError, "EditTeam", err)
332332
return
333333
}

routers/web/org/teams.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,14 @@ func EditTeamPost(ctx *context.Context) {
494494
return
495495
}
496496

497-
if err := org_service.UpdateTeam(ctx, t, form.TeamName, form.Description,
498-
form.Permission == "admin",
499-
form.RepoAccess == "all",
500-
form.CanCreateOrgRepo,
501-
unitPerms,
502-
); err != nil {
497+
if err := org_service.UpdateTeam(ctx, t, org_service.UpdateTeamOptions{
498+
TeamName: form.TeamName,
499+
Description: form.Description,
500+
IsAdmin: form.Permission == "admin",
501+
IncludesAllRepositories: form.RepoAccess == "all",
502+
CanCreateOrgRepo: form.CanCreateOrgRepo,
503+
UnitPerms: unitPerms,
504+
}); err != nil {
503505
ctx.Data["Err_TeamName"] = true
504506
switch {
505507
case org_model.IsErrTeamAlreadyExist(err):

services/org/team.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,40 @@ import (
1212
unit_model "code.gitea.io/gitea/models/unit"
1313
)
1414

15-
func UpdateTeam(ctx context.Context, team *org_model.Team, teamName, description string, isAdmin, includesAllRepositories, canCreateOrgRepo bool, unitPerms map[unit_model.Type]perm.AccessMode) error {
15+
type UpdateTeamOptions struct {
16+
TeamName string
17+
Description string
18+
IsAdmin bool
19+
IncludesAllRepositories bool
20+
CanCreateOrgRepo bool
21+
UnitPerms map[unit_model.Type]perm.AccessMode
22+
}
23+
24+
func UpdateTeam(ctx context.Context, team *org_model.Team, opts UpdateTeamOptions) error {
1625
var changedCols []string
1726

1827
newAccessMode := perm.AccessModeRead
19-
if isAdmin {
28+
if opts.IsAdmin {
2029
newAccessMode = perm.AccessModeAdmin
2130
} else {
2231
// if newAccessMode is less than admin accessmode, then it should be general accessmode,
2332
// so we should calculate the minial accessmode from units accessmodes.
24-
newAccessMode = unit_model.MinUnitAccessMode(unitPerms)
33+
newAccessMode = unit_model.MinUnitAccessMode(opts.UnitPerms)
2534
}
2635

2736
if !team.IsOwnerTeam() {
28-
team.Name = teamName
37+
team.Name = opts.TeamName
2938
if team.AccessMode != newAccessMode {
3039
team.AccessMode = newAccessMode
3140
changedCols = append(changedCols, "authorize")
3241
}
3342

34-
if team.IncludesAllRepositories != includesAllRepositories {
35-
team.IncludesAllRepositories = includesAllRepositories
43+
if team.IncludesAllRepositories != opts.IncludesAllRepositories {
44+
team.IncludesAllRepositories = opts.IncludesAllRepositories
3645
changedCols = append(changedCols, "includes_all_repositories")
3746
}
38-
units := make([]*org_model.TeamUnit, 0, len(unitPerms))
39-
for tp, perm := range unitPerms {
47+
units := make([]*org_model.TeamUnit, 0, len(opts.UnitPerms))
48+
for tp, perm := range opts.UnitPerms {
4049
units = append(units, &org_model.TeamUnit{
4150
OrgID: team.OrgID,
4251
TeamID: team.ID,
@@ -46,8 +55,8 @@ func UpdateTeam(ctx context.Context, team *org_model.Team, teamName, description
4655
}
4756
team.Units = units
4857
changedCols = append(changedCols, "units")
49-
if team.CanCreateOrgRepo != canCreateOrgRepo {
50-
team.CanCreateOrgRepo = canCreateOrgRepo
58+
if team.CanCreateOrgRepo != opts.CanCreateOrgRepo {
59+
team.CanCreateOrgRepo = opts.CanCreateOrgRepo
5160
changedCols = append(changedCols, "can_create_org_repo")
5261
}
5362
} else {
@@ -56,9 +65,9 @@ func UpdateTeam(ctx context.Context, team *org_model.Team, teamName, description
5665
changedCols = append(changedCols, "can_create_org_repo", "includes_all_repositories")
5766
}
5867

59-
if team.Description != description {
68+
if team.Description != opts.Description {
6069
changedCols = append(changedCols, "description")
61-
team.Description = description
70+
team.Description = opts.Description
6271
}
6372

6473
return models.UpdateTeam(ctx, team, changedCols...)

0 commit comments

Comments
 (0)