aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/admin
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-12-17 02:28:47 -0500
committerUnknwon <u@gogs.io>2015-12-17 02:28:47 -0500
commit9cd16c5b12d093dd694e146d6c845ee4c405c774 (patch)
treed9f1a037ba8ecbc3e5fe2f15f0baec6dec6242b4 /routers/api/v1/admin
parent6673dcb0380aa99da25b4d1d68cf129635fe30d9 (diff)
downloadgitea-9cd16c5b12d093dd694e146d6c845ee4c405c774.tar.gz
gitea-9cd16c5b12d093dd694e146d6c845ee4c405c774.zip
#1692 add organization APIs
Diffstat (limited to 'routers/api/v1/admin')
-rw-r--r--routers/api/v1/admin/orgs.go44
-rw-r--r--routers/api/v1/admin/users.go6
2 files changed, 47 insertions, 3 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))
+}
diff --git a/routers/api/v1/admin/users.go b/routers/api/v1/admin/users.go
index 1bd253681b..9a8c906f29 100644
--- a/routers/api/v1/admin/users.go
+++ b/routers/api/v1/admin/users.go
@@ -12,8 +12,8 @@ import (
"github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
+ "github.com/gogits/gogs/routers/api/v1/convert"
"github.com/gogits/gogs/routers/api/v1/user"
- to "github.com/gogits/gogs/routers/api/v1/utils"
)
func parseLoginSource(ctx *middleware.Context, u *models.User, sourceID int64, loginName string) {
@@ -69,7 +69,7 @@ func CreateUser(ctx *middleware.Context, form api.CreateUserOption) {
mailer.SendRegisterNotifyMail(ctx.Context, u)
}
- ctx.JSON(201, to.ApiUser(u))
+ ctx.JSON(201, convert.ToApiUser(u))
}
// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#edit-an-existing-user
@@ -118,7 +118,7 @@ func EditUser(ctx *middleware.Context, form api.EditUserOption) {
}
log.Trace("Account profile updated by admin (%s): %s", ctx.User.Name, u.Name)
- ctx.JSON(200, to.ApiUser(u))
+ ctx.JSON(200, convert.ToApiUser(u))
}
// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#delete-a-user