From 77c77fbd42a2cafcb31ecf042a94141a7ca31c98 Mon Sep 17 00:00:00 2001 From: Anton Antonov Date: Tue, 14 Nov 2017 05:27:30 +0200 Subject: api: add endpoint /api/v1/user/orgs (#4835) * Add API endpoint /api/v1/user/orgs The difference between this endpoint and /api/v1/admin/users//orgs, is that here you're creating a repo with the `user` that corresponds to the API token you're using. * Extract duplicate API org creation --- routes/api/v1/admin/org.go | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) (limited to 'routes/api/v1/admin') diff --git a/routes/api/v1/admin/org.go b/routes/api/v1/admin/org.go index 0f84ed2e..89251d2e 100644 --- a/routes/api/v1/admin/org.go +++ b/routes/api/v1/admin/org.go @@ -7,38 +7,12 @@ package admin import ( api "github.com/gogits/go-gogs-client" - "github.com/gogits/gogs/models" "github.com/gogits/gogs/pkg/context" - "github.com/gogits/gogs/routes/api/v1/convert" "github.com/gogits/gogs/routes/api/v1/user" + "github.com/gogits/gogs/routes/api/v1/org" ) // https://github.com/gogits/go-gogs-client/wiki/Administration-Organizations#create-a-new-organization func CreateOrg(c *context.APIContext, form api.CreateOrgOption) { - u := user.GetUserByParams(c) - if c.Written() { - return - } - - org := &models.User{ - Name: form.UserName, - FullName: form.FullName, - Description: form.Description, - Website: form.Website, - Location: form.Location, - IsActive: true, - Type: models.USER_TYPE_ORGANIZATION, - } - if err := models.CreateOrganization(org, u); err != nil { - if models.IsErrUserAlreadyExist(err) || - models.IsErrNameReserved(err) || - models.IsErrNamePatternNotAllowed(err) { - c.Error(422, "", err) - } else { - c.Error(500, "CreateOrganization", err) - } - return - } - - c.JSON(201, convert.ToOrganization(org)) + org.CreateOrgForUser(c, form, user.GetUserByParams(c)) } -- cgit v1.2.3