From e314dd94a3242defdc32db71e5a8cc7bb4f0d7bb Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Thu, 23 Aug 2018 08:58:05 +0100 Subject: [PATCH] give admin team all available permissions --- routers/org/teams.go | 59 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/routers/org/teams.go b/routers/org/teams.go index 1aee99fb8883b..b0d9132fc5456 100644 --- a/routers/org/teams.go +++ b/routers/org/teams.go @@ -187,17 +187,37 @@ func NewTeamPost(ctx *context.Context, form auth.CreateTeamForm) { Authorize: models.ParseAccessMode(form.Permission), } - if t.Authorize < models.AccessModeOwner { - var units = make([]*models.TeamUnit, 0, len(form.Units)) + var units []*models.TeamUnit + + switch t.Authorize { + + case models.AccessModeAdmin: + // If admin, just give all units regardless of the options + // coming in from the UI + + units = make([]*models.TeamUnit, 0, len(models.Units)) + + for tp := range models.Units { + units = append(units, &models.TeamUnit{ + OrgID: t.OrgID, + TeamID: t.ID, + Type: tp, + }) + } + + case models.AccessModeRead, models.AccessModeWrite: + units = make([]*models.TeamUnit, 0, len(form.Units)) for _, tp := range form.Units { units = append(units, &models.TeamUnit{ - OrgID: ctx.Org.Organization.ID, - Type: tp, + OrgID: t.OrgID, + TeamID: t.ID, + Type: tp, }) } - t.Units = units } + t.Units = units + ctx.Data["Team"] = t if ctx.HasError() { @@ -275,9 +295,29 @@ func EditTeamPost(ctx *context.Context, form auth.CreateTeamForm) { t.Authorize = auth } } + t.Description = form.Description - if t.Authorize < models.AccessModeOwner { - var units = make([]models.TeamUnit, 0, len(form.Units)) + + var units []models.TeamUnit + + switch t.Authorize { + + case models.AccessModeAdmin: + // If admin, just give all units regardless of the options + // coming in from the UI + + units = make([]models.TeamUnit, 0, len(models.Units)) + + for tp := range models.Units { + units = append(units, models.TeamUnit{ + OrgID: t.OrgID, + TeamID: t.ID, + Type: tp, + }) + } + + case models.AccessModeRead, models.AccessModeWrite: + units = make([]models.TeamUnit, 0, len(form.Units)) for _, tp := range form.Units { units = append(units, models.TeamUnit{ OrgID: t.OrgID, @@ -285,11 +325,10 @@ func EditTeamPost(ctx *context.Context, form auth.CreateTeamForm) { Type: tp, }) } - models.UpdateTeamUnits(t, units) - } else { - models.UpdateTeamUnits(t, nil) } + models.UpdateTeamUnits(t, units) + if ctx.HasError() { ctx.HTML(200, tplTeamNew) return