[[projects]]
branch = "master"
- digest = "1:bf4f822f636b99ac7d4f8fa5210a7439bacaf8d1f15d5783956bdd5dd2069bdc"
+ digest = "1:b194da40b41ae99546dfeec5a85f1fec2a6c51350d438e511ef90f4293c6dcd7"
name = "code.gitea.io/sdk"
packages = ["gitea"]
pruneopts = "NUT"
- revision = "11c860c8e49a23be26e6d6c6a039a46ad2ae1d27"
+ revision = "4f96d9ac89886e78c50de8c835ebe87461578a5e"
[[projects]]
digest = "1:3fcef06a1a6561955c94af6c7757a6fa37605eb653f0d06ab960e5bb80092195"
return err
}
+// GetUnitNames returns the team units names
+func (t *Team) GetUnitNames() (res []string) {
+ for _, u := range t.Units {
+ res = append(res, Units[u.Type].NameKey)
+ }
+ return
+}
+
// HasWriteAccess returns true if team has at least write level access mode.
func (t *Team) HasWriteAccess() bool {
return t.Authorize >= AccessModeWrite
return fmt.Errorf("update: %v", err)
}
+ // update units for team
+ if len(t.Units) > 0 {
+ for _, unit := range t.Units {
+ unit.TeamID = t.ID
+ }
+ // Delete team-unit.
+ if _, err := sess.
+ Where("team_id=?", t.ID).
+ Delete(new(TeamUnit)); err != nil {
+ return err
+ }
+
+ if _, err = sess.Insert(&t.Units); err != nil {
+ sess.Rollback()
+ return err
+ }
+ }
+
// Update access for team members if needed.
if authChanged {
if err = t.getRepositories(sess); err != nil {
package models
+import (
+ "strings"
+)
+
// UnitType is Unit's Type
type UnitType int
UnitTypeExternalWiki: UnitExternalWiki,
}
)
+
+// FindUnitTypes give the unit key name and return unit
+func FindUnitTypes(nameKeys ...string) (res []UnitType) {
+ for _, key := range nameKeys {
+ for t, u := range Units {
+ if strings.EqualFold(key, u.NameKey) {
+ res = append(res, t)
+ break
+ }
+ }
+ }
+ return
+}
Name: team.Name,
Description: team.Description,
Permission: team.Authorize.String(),
+ Units: team.GetUnitNames(),
}
}
Description: form.Description,
Authorize: models.ParseAccessMode(form.Permission),
}
+
+ unitTypes := models.FindUnitTypes(form.Units...)
+
+ if team.Authorize < models.AccessModeOwner {
+ var units = make([]*models.TeamUnit, 0, len(form.Units))
+ for _, tp := range unitTypes {
+ units = append(units, &models.TeamUnit{
+ OrgID: ctx.Org.Organization.ID,
+ Type: tp,
+ })
+ }
+ team.Units = units
+ }
+
if err := models.NewTeam(team); err != nil {
if models.IsErrTeamAlreadyExist(err) {
ctx.Error(422, "", err)
team.Name = form.Name
team.Description = form.Description
team.Authorize = models.ParseAccessMode(form.Permission)
+ unitTypes := models.FindUnitTypes(form.Units...)
+
+ if team.Authorize < models.AccessModeOwner {
+ var units = make([]*models.TeamUnit, 0, len(form.Units))
+ for _, tp := range unitTypes {
+ units = append(units, &models.TeamUnit{
+ OrgID: ctx.Org.Organization.ID,
+ Type: tp,
+ })
+ }
+ team.Units = units
+ }
+
if err := models.UpdateTeam(team, true); err != nil {
ctx.Error(500, "EditTeam", err)
return
"admin"
],
"x-go-name": "Permission"
+ },
+ "units": {
+ "type": "array",
+ "enum": [
+ "repo.code",
+ "repo.issues",
+ "repo.ext_issues",
+ "repo.wiki",
+ "repo.pulls",
+ "repo.releases",
+ "repo.ext_wiki"
+ ],
+ "items": {
+ "type": "string"
+ },
+ "x-go-name": "Units"
}
},
"x-go-package": "code.gitea.io/gitea/vendor/code.gitea.io/sdk/gitea"
"admin"
],
"x-go-name": "Permission"
+ },
+ "units": {
+ "type": "array",
+ "enum": [
+ "repo.code",
+ "repo.issues",
+ "repo.ext_issues",
+ "repo.wiki",
+ "repo.pulls",
+ "repo.releases",
+ "repo.ext_wiki"
+ ],
+ "items": {
+ "type": "string"
+ },
+ "x-go-name": "Units"
}
},
"x-go-package": "code.gitea.io/gitea/vendor/code.gitea.io/sdk/gitea"
"owner"
],
"x-go-name": "Permission"
+ },
+ "units": {
+ "type": "array",
+ "enum": [
+ "repo.code",
+ "repo.issues",
+ "repo.ext_issues",
+ "repo.wiki",
+ "repo.pulls",
+ "repo.releases",
+ "repo.ext_wiki"
+ ],
+ "items": {
+ "type": "string"
+ },
+ "x-go-name": "Units"
}
},
"x-go-package": "code.gitea.io/gitea/vendor/code.gitea.io/sdk/gitea"
// Copyright 2016 The Gogs Authors. All rights reserved.
+// Copyright 2018 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
Description string `json:"description"`
// enum: none,read,write,admin,owner
Permission string `json:"permission"`
+ // enum: repo.code,repo.issues,repo.ext_issues,repo.wiki,repo.pulls,repo.releases,repo.ext_wiki
+ Units []string `json:"units"`
}
// CreateTeamOption options for creating a team
Description string `json:"description" binding:"MaxSize(255)"`
// enum: read,write,admin
Permission string `json:"permission"`
+ // enum: repo.code,repo.issues,repo.ext_issues,repo.wiki,repo.pulls,repo.releases,repo.ext_wiki
+ Units []string `json:"units"`
}
// EditTeamOption options for editing a team
Description string `json:"description" binding:"MaxSize(255)"`
// enum: read,write,admin
Permission string `json:"permission"`
+ // enum: repo.code,repo.issues,repo.ext_issues,repo.wiki,repo.pulls,repo.releases,repo.ext_wiki
+ Units []string `json:"units"`
}