forked from forgejo/forgejo
#1692 add organization APIs
This commit is contained in:
parent
6673dcb038
commit
9cd16c5b12
20 changed files with 204 additions and 55 deletions
44
routers/api/v1/admin/orgs.go
Normal file
44
routers/api/v1/admin/orgs.go
Normal file
|
@ -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))
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue