Browse Source

#1692 api: admin list and create team under organization

pull/2879/head
Unknwon 9 years ago
parent
commit
e6f927f61a
  1. 2
      README.md
  2. 2
      gogs.go
  3. 27
      models/access.go
  4. 0
      routers/api/v1/admin/org.go
  5. 56
      routers/api/v1/admin/org_team.go
  6. 0
      routers/api/v1/admin/repo.go
  7. 0
      routers/api/v1/admin/user.go
  8. 4
      routers/api/v1/api.go
  9. 9
      routers/api/v1/convert/convert.go
  10. 0
      routers/api/v1/repo/hook.go
  11. 0
      routers/api/v1/repo/key.go
  12. 0
      routers/api/v1/user/follower.go
  13. 0
      routers/api/v1/user/key.go
  14. 16
      routers/org/teams.go
  15. 2
      templates/.VERSION

2
README.md

@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
##### Current version: 0.9.13 ##### Current version: 0.9.14
| Web | UI | Preview | | Web | UI | Preview |
|:-------------:|:-------:|:-------:| |:-------------:|:-------:|:-------:|

2
gogs.go

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.9.13.0321" const APP_VER = "0.9.14.0321"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

27
models/access.go

@ -20,6 +20,33 @@ const (
ACCESS_MODE_OWNER // 4 ACCESS_MODE_OWNER // 4
) )
func (mode AccessMode) String() string {
switch mode {
case ACCESS_MODE_READ:
return "read"
case ACCESS_MODE_WRITE:
return "write"
case ACCESS_MODE_ADMIN:
return "admin"
case ACCESS_MODE_OWNER:
return "owner"
default:
return "none"
}
}
// ParseAccessMode returns corresponding access mode to given permission string.
func ParseAccessMode(permission string) AccessMode {
switch permission {
case "write":
return ACCESS_MODE_WRITE
case "admin":
return ACCESS_MODE_ADMIN
default:
return ACCESS_MODE_READ
}
}
// Access represents the highest access level of a user to the repository. The only access type // Access represents the highest access level of a user to the repository. The only access type
// that is not in this table is the real owner of a repository. In case of an organization // that is not in this table is the real owner of a repository. In case of an organization
// repository, the members of the owners team are in this table. // repository, the members of the owners team are in this table.

0
routers/api/v1/admin/orgs.go → routers/api/v1/admin/org.go

56
routers/api/v1/admin/org_team.go

@ -0,0 +1,56 @@
// Copyright 2016 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package admin
import (
api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/api/v1/convert"
"github.com/gogits/gogs/routers/api/v1/user"
)
func ListTeams(ctx *context.APIContext) {
org := user.GetUserByParamsName(ctx, ":orgname")
if ctx.Written() {
return
}
if err := org.GetTeams(); err != nil {
ctx.Error(500, "GetTeams", err)
return
}
apiTeams := make([]*api.Team, len(org.Teams))
for i := range org.Teams {
apiTeams[i] = convert.ToTeam(org.Teams[i])
}
ctx.JSON(200, apiTeams)
}
func CreateTeam(ctx *context.APIContext, form api.CreateTeamOption) {
org := user.GetUserByParamsName(ctx, ":orgname")
if ctx.Written() {
return
}
team := &models.Team{
OrgID: org.Id,
Name: form.Name,
Description: form.Description,
Authorize: models.ParseAccessMode(form.Permission),
}
if err := models.NewTeam(team); err != nil {
if models.IsErrTeamAlreadyExist(err) {
ctx.Error(422, "NewTeam", err)
} else {
ctx.Error(500, "NewTeam", err)
}
return
}
ctx.JSON(200, convert.ToTeam(team))
}

0
routers/api/v1/admin/repos.go → routers/api/v1/admin/repo.go

0
routers/api/v1/admin/users.go → routers/api/v1/admin/user.go

4
routers/api/v1/api.go

@ -223,6 +223,10 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Post("/repos", bind(api.CreateRepoOption{}), admin.CreateRepo) m.Post("/repos", bind(api.CreateRepoOption{}), admin.CreateRepo)
}) })
}) })
m.Group("/orgs/:orgname", func() {
m.Combo("/teams").Get(admin.ListTeams).Post(bind(api.CreateTeamOption{}), admin.CreateTeam)
})
}, ReqAdmin()) }, ReqAdmin())
}, context.APIContexter()) }, context.APIContexter())
} }

9
routers/api/v1/convert/convert.go

@ -196,3 +196,12 @@ func ToOrganization(org *models.User) *api.Organization {
Location: org.Location, Location: org.Location,
} }
} }
func ToTeam(team *models.Team) *api.Team {
return &api.Team{
ID: team.ID,
Name: team.Name,
Description: team.Description,
Permission: team.Authorize.String(),
}
}

0
routers/api/v1/repo/hooks.go → routers/api/v1/repo/hook.go

0
routers/api/v1/repo/keys.go → routers/api/v1/repo/key.go

0
routers/api/v1/user/followers.go → routers/api/v1/user/follower.go

0
routers/api/v1/user/keys.go → routers/api/v1/user/key.go

16
routers/org/teams.go

@ -154,25 +154,11 @@ func NewTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
ctx.Data["PageIsOrgTeams"] = true ctx.Data["PageIsOrgTeams"] = true
ctx.Data["PageIsOrgTeamsNew"] = true ctx.Data["PageIsOrgTeamsNew"] = true
// Validate permission level.
var auth models.AccessMode
switch form.Permission {
case "read":
auth = models.ACCESS_MODE_READ
case "write":
auth = models.ACCESS_MODE_WRITE
case "admin":
auth = models.ACCESS_MODE_ADMIN
default:
ctx.Error(401)
return
}
t := &models.Team{ t := &models.Team{
OrgID: ctx.Org.Organization.Id, OrgID: ctx.Org.Organization.Id,
Name: form.TeamName, Name: form.TeamName,
Description: form.Description, Description: form.Description,
Authorize: auth, Authorize: models.ParseAccessMode(form.Permission),
} }
ctx.Data["Team"] = t ctx.Data["Team"] = t

2
templates/.VERSION

@ -1 +1 @@
0.9.13.0321 0.9.14.0321
Loading…
Cancel
Save