aboutsummaryrefslogtreecommitdiff
path: root/routes/api/v1/org
diff options
context:
space:
mode:
authorAnton Antonov <anton.synd.antonov@gmail.com>2017-11-14 05:27:30 +0200
committer无闻 <u@gogs.io>2017-11-13 22:27:30 -0500
commit77c77fbd42a2cafcb31ecf042a94141a7ca31c98 (patch)
tree39b1d951de585516de217604b10ace525ec1f43e /routes/api/v1/org
parent9b4054f1fc3a92c7c582770a2c9997213434a792 (diff)
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/<username>/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
Diffstat (limited to 'routes/api/v1/org')
-rw-r--r--routes/api/v1/org/org.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/routes/api/v1/org/org.go b/routes/api/v1/org/org.go
index 2f8832ca..25a0e5b6 100644
--- a/routes/api/v1/org/org.go
+++ b/routes/api/v1/org/org.go
@@ -13,6 +13,34 @@ import (
"github.com/gogits/gogs/routes/api/v1/user"
)
+func CreateOrgForUser(c *context.APIContext, apiForm api.CreateOrgOption, user *models.User) {
+ if c.Written() {
+ return
+ }
+
+ org := &models.User{
+ Name: apiForm.UserName,
+ FullName: apiForm.FullName,
+ Description: apiForm.Description,
+ Website: apiForm.Website,
+ Location: apiForm.Location,
+ IsActive: true,
+ Type: models.USER_TYPE_ORGANIZATION,
+ }
+ if err := models.CreateOrganization(org, user); 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))
+}
+
func listUserOrgs(c *context.APIContext, u *models.User, all bool) {
if err := u.GetOrganizations(all); err != nil {
c.Error(500, "GetOrganizations", err)
@@ -31,6 +59,11 @@ func ListMyOrgs(c *context.APIContext) {
listUserOrgs(c, c.User, true)
}
+// https://github.com/gogits/go-gogs-client/wiki/Organizations#create-your-organization
+func CreateMyOrg(c *context.APIContext, apiForm api.CreateOrgOption) {
+ CreateOrgForUser(c, apiForm, c.User)
+}
+
// https://github.com/gogits/go-gogs-client/wiki/Organizations#list-user-organizations
func ListUserOrgs(c *context.APIContext) {
u := user.GetUserByParams(c)