diff --git a/models/unit/unit.go b/models/unit/unit.go index 7cd679116f1bb..132f0ea5baa5e 100644 --- a/models/unit/unit.go +++ b/models/unit/unit.go @@ -353,19 +353,23 @@ func AllUnitKeyNames() []string { return res } -// MinUnitAccessMode returns the minial permission of the permission map +// MinUnitAccessMode returns the minimum permission of the permission map func MinUnitAccessMode(unitsMap map[Type]perm.AccessMode) perm.AccessMode { - res := perm.AccessModeNone + res := perm.AccessModeWrite for t, mode := range unitsMap { // Don't allow `TypeExternal{Tracker,Wiki}` to influence this as they can only be set to READ perms. if t == TypeExternalTracker || t == TypeExternalWiki { continue } - // get the minial permission great than AccessModeNone except all are AccessModeNone - if mode > perm.AccessModeNone && (res == perm.AccessModeNone || mode < res) { + // get the minimum permission + if mode < res { res = mode } + // There is no lower permission than AccessModeNone, so exit early + if res == perm.AccessModeNone { + break + } } return res } diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go index 2ce4bf5322717..a65d20fa19b36 100644 --- a/routers/web/org/teams.go +++ b/routers/web/org/teams.go @@ -308,7 +308,7 @@ func NewTeamPost(ctx *context.Context) { unitPerms := getUnitPerms(ctx.Req.Form, p) if p < perm.AccessModeAdmin { // if p is less than admin accessmode, then it should be general accessmode, - // so we should calculate the minial accessmode from units accessmodes. + // so we should calculate the minimum accessmode from units accessmodes. p = unit_model.MinUnitAccessMode(unitPerms) } @@ -459,7 +459,7 @@ func EditTeamPost(ctx *context.Context) { unitPerms := getUnitPerms(ctx.Req.Form, newAccessMode) if newAccessMode < perm.AccessModeAdmin { // if newAccessMode is less than admin accessmode, then it should be general accessmode, - // so we should calculate the minial accessmode from units accessmodes. + // so we should calculate the minimum accessmode from units accessmodes. newAccessMode = unit_model.MinUnitAccessMode(unitPerms) } isAuthChanged := false diff --git a/templates/org/team/new.tmpl b/templates/org/team/new.tmpl index 0cba09be51390..05db1166f26fd 100644 --- a/templates/org/team/new.tmpl +++ b/templates/org/team/new.tmpl @@ -56,7 +56,7 @@
- + {{.locale.Tr "org.teams.general_access_helper"}}
diff --git a/tests/integration/api_team_test.go b/tests/integration/api_team_test.go index 934e6bf23046f..7fe1a78b59654 100644 --- a/tests/integration/api_team_test.go +++ b/tests/integration/api_team_test.go @@ -139,9 +139,9 @@ func TestAPITeam(t *testing.T) { apiTeam = api.Team{} DecodeJSON(t, resp, &apiTeam) checkTeamResponse(t, "CreateTeam2", &apiTeam, teamToCreate.Name, teamToCreate.Description, teamToCreate.IncludesAllRepositories, - "read", nil, teamToCreate.UnitsMap) + "none", nil, teamToCreate.UnitsMap) checkTeamBean(t, apiTeam.ID, teamToCreate.Name, teamToCreate.Description, teamToCreate.IncludesAllRepositories, - "read", nil, teamToCreate.UnitsMap) + "none", nil, teamToCreate.UnitsMap) teamID = apiTeam.ID // Edit team.