forked from Gitlink/gitea-1120-rc1
C:/Program Files/Git/orgs 创建组织补全默认团队信息
This commit is contained in:
parent
da5cce281c
commit
099b5d7015
|
@ -0,0 +1,25 @@
|
|||
// 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 convert
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
)
|
||||
|
||||
// ToOrganization convert models.User to api.Organization
|
||||
func ToOrganizationExt(org *models.User) *api.OrganizationExt {
|
||||
return &api.OrganizationExt{
|
||||
ID: org.ID,
|
||||
AvatarURL: org.AvatarLink(),
|
||||
UserName: org.Name,
|
||||
FullName: org.FullName,
|
||||
Description: org.Description,
|
||||
Website: org.Website,
|
||||
Location: org.Location,
|
||||
Visibility: org.Visibility.String(),
|
||||
RepoAdminChangeTeamAccess: org.RepoAdminChangeTeamAccess,
|
||||
}
|
||||
}
|
|
@ -5,6 +5,23 @@
|
|||
package structs
|
||||
|
||||
|
||||
// Organization represents an organization
|
||||
|
||||
type OrganizationExt struct {
|
||||
ID int64 `json:"id"`
|
||||
UserName string `json:"username"`
|
||||
FullName string `json:"full_name"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
Description string `json:"description"`
|
||||
Website string `json:"website"`
|
||||
Location string `json:"location"`
|
||||
Visibility string `json:"visibility"`
|
||||
RepoAdminChangeTeamAccess bool `json:"repo_admin_change_team_access"`
|
||||
OwnerTeam interface{} `json:"owner_team"` //团队关系;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// EditOrgOption options for editing an organization
|
||||
type EditOrgOptionExt struct {
|
||||
Name string `json:"name"` // 添加对name的修改,lower_name 其值跟随name变化;
|
||||
|
|
|
@ -931,7 +931,11 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
// Organizations
|
||||
m.Get("/user/orgs", reqToken(), org.ListMyOrgs)
|
||||
m.Get("/users/:username/orgs", org.ListUserOrgs)
|
||||
m.Post("/orgs", reqToken(), bind(api.CreateOrgOption{}), org.Create)
|
||||
// modified on 2021-01-14 begin 创建组织时返回默认的团队 begin
|
||||
//m.Post("/orgs", reqToken(), bind(api.CreateOrgOption{}), org.Create)
|
||||
m.Post("/orgs", reqToken(), bind(api.CreateOrgOption{}), org.CreateExt)
|
||||
// modified on 2021-01-14 begin 创建组织时返回默认的团队 end
|
||||
|
||||
m.Get("/orgs", org.GetAll)
|
||||
m.Group("/orgs/:org", func() {
|
||||
m.Combo("").Get(org.Get).
|
||||
|
|
|
@ -85,3 +85,76 @@ func Edit_Ext(ctx *context.APIContext, form api.EditOrgOptionExt) {
|
|||
ctx.JSON(http.StatusOK, convert.ToOrganization(org))
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Create api for create organization ext inferface
|
||||
func CreateExt(ctx *context.APIContext, form api.CreateOrgOption) {
|
||||
// swagger:operation POST /orgs organization orgCreate
|
||||
// ---
|
||||
// summary: Create an organization
|
||||
// consumes:
|
||||
// - application/json
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: organization
|
||||
// in: body
|
||||
// required: true
|
||||
// schema: { "$ref": "#/definitions/CreateOrgOption" }
|
||||
// responses:
|
||||
// "201":
|
||||
// "$ref": "#/responses/Organization"
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
if !ctx.User.CanCreateOrganization() {
|
||||
ctx.Error(http.StatusForbidden, "Create organization not allowed", nil)
|
||||
return
|
||||
}
|
||||
|
||||
visibility := api.VisibleTypePublic
|
||||
if form.Visibility != "" {
|
||||
visibility = api.VisibilityModes[form.Visibility]
|
||||
}
|
||||
|
||||
org := &models.User{
|
||||
Name: form.UserName,
|
||||
FullName: form.FullName,
|
||||
Description: form.Description,
|
||||
Website: form.Website,
|
||||
Location: form.Location,
|
||||
IsActive: true,
|
||||
Type: models.UserTypeOrganization,
|
||||
Visibility: visibility,
|
||||
RepoAdminChangeTeamAccess: form.RepoAdminChangeTeamAccess,
|
||||
}
|
||||
if err := models.CreateOrganization(org, ctx.User); err != nil {
|
||||
if models.IsErrUserAlreadyExist(err) ||
|
||||
models.IsErrNameReserved(err) ||
|
||||
models.IsErrNameCharsNotAllowed(err) ||
|
||||
models.IsErrNamePatternNotAllowed(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
||||
} else {
|
||||
ctx.Error(http.StatusInternalServerError, "CreateOrganization", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 根据业务需要 自定义创建组织时将默认团队同时返回.
|
||||
Team, err := models.GetTeam(org.ID,"")
|
||||
if err != nil {
|
||||
if models.IsErrUserNotExist(err) {
|
||||
ctx.NotFound()
|
||||
} else {
|
||||
ctx.Error(http.StatusInternalServerError, "GetTeam", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
apiOrg:=convert.ToOrganizationExt(org)
|
||||
apiOrg.OwnerTeam=convert.ToTeam(Team)
|
||||
ctx.JSON(http.StatusCreated, apiOrg)
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue