mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 16:44:26 +00:00
#1692 api: admin list and create team under organization
This commit is contained in:
parent
60ae8ac3d2
commit
e6f927f61a
@ -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)
|
||||
|
||||
##### Current version: 0.9.13
|
||||
##### Current version: 0.9.14
|
||||
|
||||
| Web | UI | Preview |
|
||||
|:-------------:|:-------:|:-------:|
|
||||
|
2
gogs.go
2
gogs.go
@ -17,7 +17,7 @@ import (
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
const APP_VER = "0.9.13.0321"
|
||||
const APP_VER = "0.9.14.0321"
|
||||
|
||||
func init() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
@ -20,6 +20,33 @@ const (
|
||||
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
|
||||
// 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.
|
||||
|
56
routers/api/v1/admin/org_team.go
Normal file
56
routers/api/v1/admin/org_team.go
Normal file
@ -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))
|
||||
}
|
@ -223,6 +223,10 @@ func RegisterRoutes(m *macaron.Macaron) {
|
||||
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())
|
||||
}, context.APIContexter())
|
||||
}
|
||||
|
@ -196,3 +196,12 @@ func ToOrganization(org *models.User) *api.Organization {
|
||||
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(),
|
||||
}
|
||||
}
|
||||
|
@ -154,25 +154,11 @@ func NewTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
|
||||
ctx.Data["PageIsOrgTeams"] = 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{
|
||||
OrgID: ctx.Org.Organization.Id,
|
||||
Name: form.TeamName,
|
||||
Description: form.Description,
|
||||
Authorize: auth,
|
||||
Authorize: models.ParseAccessMode(form.Permission),
|
||||
}
|
||||
ctx.Data["Team"] = t
|
||||
|
||||
|
@ -1 +1 @@
|
||||
0.9.13.0321
|
||||
0.9.14.0321
|
Loading…
Reference in New Issue
Block a user