diff options
author | Unknwon <u@gogs.io> | 2015-12-17 02:28:47 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-12-17 02:28:47 -0500 |
commit | 9cd16c5b12d093dd694e146d6c845ee4c405c774 (patch) | |
tree | d9f1a037ba8ecbc3e5fe2f15f0baec6dec6242b4 /routers/api/v1/admin/orgs.go | |
parent | 6673dcb0380aa99da25b4d1d68cf129635fe30d9 (diff) | |
download | gitea-9cd16c5b12d093dd694e146d6c845ee4c405c774.tar.gz gitea-9cd16c5b12d093dd694e146d6c845ee4c405c774.zip |
#1692 add organization APIs
Diffstat (limited to 'routers/api/v1/admin/orgs.go')
-rw-r--r-- | routers/api/v1/admin/orgs.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/routers/api/v1/admin/orgs.go b/routers/api/v1/admin/orgs.go new file mode 100644 index 0000000000..5b5302ca15 --- /dev/null +++ b/routers/api/v1/admin/orgs.go @@ -0,0 +1,44 @@ +// Copyright 2015 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/middleware" + "github.com/gogits/gogs/routers/api/v1/convert" + "github.com/gogits/gogs/routers/api/v1/user" +) + +// https://github.com/gogits/go-gogs-client/wiki/Administration-Organizations#create-a-new-organization +func CreateOrg(ctx *middleware.Context, form api.CreateOrgOption) { + u := user.GetUserByParams(ctx) + if ctx.Written() { + return + } + + org := &models.User{ + Name: form.UserName, + FullName: form.FullName, + Description: form.Description, + Website: form.Website, + Location: form.Location, + IsActive: true, + Type: models.ORGANIZATION, + } + if err := models.CreateOrganization(org, u); err != nil { + if models.IsErrUserAlreadyExist(err) || + models.IsErrNameReserved(err) || + models.IsErrNamePatternNotAllowed(err) { + ctx.APIError(422, "CreateOrganization", err) + } else { + ctx.APIError(500, "CreateOrganization", err) + } + return + } + + ctx.JSON(201, convert.ToApiOrganization(org)) +} |