This commit is contained in:
hang 2021-11-23 17:02:55 +08:00
parent 3919b05285
commit ad65d78976
3 changed files with 55 additions and 1 deletions

View File

@ -438,3 +438,18 @@ func ToLFSLock(l *models.LFSLock) *api.LFSLock {
},
}
}
// 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,
}
}

View File

@ -44,3 +44,28 @@ type EditTeamOption struct {
Units []string `json:"units"`
CanCreateOrgRepo *bool `json:"can_create_org_repo"`
}
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"` //团队关系;
}
type EditOrgOptionExt struct {
Name string `json:"name"` // 添加对name的修改,lower_name 其值跟随name变化;
FullName string `json:"full_name"`
Description string `json:"description"`
Website string `json:"website"`
Location string `json:"location"`
// possible values are `public`, `limited` or `private`
// enum: public,limited,private
Visibility string `json:"visibility" binding:"In(,public,limited,private)"`
RepoAdminChangeTeamAccess bool `json:"repo_admin_change_team_access"`
}

View File

@ -206,7 +206,21 @@ func Create(ctx *context.APIContext) {
return
}
ctx.JSON(http.StatusCreated, convert.ToOrganization(org))
// ctx.JSON(http.StatusCreated, convert.ToOrganization(org))
// 根据业务需要 自定义创建组织时将默认团队同时返回.
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)
}
// Get get an organization