mirror of
https://github.com/go-gitea/gitea
synced 2024-11-21 22:01:18 +01:00
#1692 add organization APIs
This commit is contained in:
parent
6673dcb038
commit
9cd16c5b12
20 changed files with 204 additions and 55 deletions
|
@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
|
|||
|
||||
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
|
||||
|
||||
##### Current version: 0.8.8
|
||||
##### Current version: 0.8.9
|
||||
|
||||
| Web | UI | Preview |
|
||||
|:-------------:|:-------:|:-------:|
|
||||
|
|
|
@ -110,7 +110,7 @@ func handleUpdateTask(uuid string, user, repoUser *models.User, reponame string,
|
|||
}
|
||||
|
||||
// Ask for running deliver hook and test pull request tasks.
|
||||
reqURL := setting.LocalUrl + repoUser.Name + "/" + reponame + "/tasks/trigger?branch=" +
|
||||
reqURL := setting.LocalURL + repoUser.Name + "/" + reponame + "/tasks/trigger?branch=" +
|
||||
strings.TrimPrefix(task.RefName, "refs/heads/") + "&secret=" + base.EncodeMD5(repoUser.Salt)
|
||||
log.GitLogger.Trace("Trigger task: %s", reqURL)
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ Most of settings are obvious and easy to understand, but there are some settings
|
|||
- **Repository Root Path**: keep it as default value `/home/git/gogs-repositories` because `start.sh` already made a symbolic link for you.
|
||||
- **Run User**: keep it as default value `git` because `start.sh` already setup a user with name `git`.
|
||||
- **Domain**: fill in with Docker container IP(e.g. `192.168.99.100`). But if you want to access your Gogs instance from a different physical machine, please fill in with the hostname or IP address of the Docker host machine.
|
||||
- **SSH Port**: Use the exposed port from Docker container. For example, your SSH server listens on `22` inside Docker, but you expose it by `10022:22`, then use `10022` for this value.
|
||||
- **SSH Port**: Use the exposed port from Docker container. For example, your SSH server listens on `22` inside Docker, but you expose it by `10022:22`, then use `10022` for this value. **Builtin SSH server is not recommended inside Docker Container**
|
||||
- **HTTP Port**: Use port you want Gogs to listen on inside Docker container. For example, your Gogs listens on `3000` inside Docker, and you expose it by `10080:3000`, but you still use `3000` for this value.
|
||||
- **Application URL**: Use combination of **Domain** and **exposed HTTP Port** values(e.g. `http://192.168.99.100:10080/`).
|
||||
|
||||
|
|
2
gogs.go
2
gogs.go
|
@ -18,7 +18,7 @@ import (
|
|||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
const APP_VER = "0.8.8.1216"
|
||||
const APP_VER = "0.8.9.1217"
|
||||
|
||||
func init() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
|
|
@ -274,10 +274,15 @@ func GetOwnedOrgsByUserIDDesc(userID int64, desc string) ([]*User, error) {
|
|||
return getOwnedOrgsByUserID(sess.Desc(desc), userID)
|
||||
}
|
||||
|
||||
// GetOrgUsersByUserId returns all organization-user relations by user ID.
|
||||
func GetOrgUsersByUserId(uid int64) ([]*OrgUser, error) {
|
||||
// GetOrgUsersByUserID returns all organization-user relations by user ID.
|
||||
func GetOrgUsersByUserID(uid int64, all bool) ([]*OrgUser, error) {
|
||||
ous := make([]*OrgUser, 0, 10)
|
||||
err := x.Where("uid=?", uid).Find(&ous)
|
||||
sess := x.Where("uid=?", uid)
|
||||
if !all {
|
||||
// Only show public organizations
|
||||
sess.And("is_public=?", true)
|
||||
}
|
||||
err := sess.Find(&ous)
|
||||
return ous, err
|
||||
}
|
||||
|
||||
|
|
|
@ -376,8 +376,8 @@ func (u *User) GetOwnedOrganizations() (err error) {
|
|||
}
|
||||
|
||||
// GetOrganizations returns all organizations that user belongs to.
|
||||
func (u *User) GetOrganizations() error {
|
||||
ous, err := GetOrgUsersByUserId(u.Id)
|
||||
func (u *User) GetOrganizations(all bool) error {
|
||||
ous, err := GetOrgUsersByUserID(u.Id, all)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ var (
|
|||
Protocol Scheme
|
||||
Domain string
|
||||
HttpAddr, HttpPort string
|
||||
LocalUrl string
|
||||
LocalURL string
|
||||
DisableSSH bool
|
||||
StartSSHServer bool
|
||||
SSHDomain string
|
||||
|
@ -302,7 +302,7 @@ func NewContext() {
|
|||
Domain = sec.Key("DOMAIN").MustString("localhost")
|
||||
HttpAddr = sec.Key("HTTP_ADDR").MustString("0.0.0.0")
|
||||
HttpPort = sec.Key("HTTP_PORT").MustString("3000")
|
||||
LocalUrl = sec.Key("LOCAL_ROOT_URL").MustString("http://localhost:" + HttpPort + "/")
|
||||
LocalURL = sec.Key("LOCAL_ROOT_URL").MustString("http://localhost:" + HttpPort + "/")
|
||||
DisableSSH = sec.Key("DISABLE_SSH").MustBool()
|
||||
if !DisableSSH {
|
||||
StartSSHServer = sec.Key("START_SSH_SERVER").MustBool()
|
||||
|
|
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
|
||||
|
|
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/gogits/gogs/modules/middleware"
|
||||
"github.com/gogits/gogs/routers/api/v1/admin"
|
||||
"github.com/gogits/gogs/routers/api/v1/misc"
|
||||
"github.com/gogits/gogs/routers/api/v1/org"
|
||||
"github.com/gogits/gogs/routers/api/v1/repo"
|
||||
"github.com/gogits/gogs/routers/api/v1/user"
|
||||
)
|
||||
|
@ -179,6 +180,11 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
}, RepoAssignment())
|
||||
}, ReqToken())
|
||||
|
||||
// Organizations
|
||||
m.Get("/user/orgs", org.ListMyOrgs)
|
||||
m.Get("/users/:username/orgs", org.ListUserOrgs)
|
||||
m.Combo("/orgs/:orgname").Get(org.Get).Patch(bind(api.EditOrgOption{}), org.Edit)
|
||||
|
||||
m.Any("/*", func(ctx *middleware.Context) {
|
||||
ctx.Error(404)
|
||||
})
|
||||
|
@ -191,6 +197,7 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
m.Combo("").Patch(bind(api.EditUserOption{}), admin.EditUser).
|
||||
Delete(admin.DeleteUser)
|
||||
m.Post("/keys", admin.CreatePublicKey)
|
||||
m.Post("/orgs", bind(api.CreateOrgOption{}), admin.CreateOrg)
|
||||
})
|
||||
})
|
||||
}, ReqAdmin())
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package utils
|
||||
package convert
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -15,8 +15,8 @@ import (
|
|||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
// ApiUser converts user to its API format.
|
||||
func ApiUser(u *models.User) *api.User {
|
||||
// ToApiUser converts user to its API format.
|
||||
func ToApiUser(u *models.User) *api.User {
|
||||
return &api.User{
|
||||
ID: u.Id,
|
||||
UserName: u.Name,
|
||||
|
@ -26,7 +26,7 @@ func ApiUser(u *models.User) *api.User {
|
|||
}
|
||||
}
|
||||
|
||||
func ApiEmail(email *models.EmailAddress) *api.Email {
|
||||
func ToApiEmail(email *models.EmailAddress) *api.Email {
|
||||
return &api.Email{
|
||||
Email: email.Email,
|
||||
Verified: email.IsActivated,
|
||||
|
@ -34,12 +34,12 @@ func ApiEmail(email *models.EmailAddress) *api.Email {
|
|||
}
|
||||
}
|
||||
|
||||
// ApiRepository converts repository to API format.
|
||||
func ApiRepository(owner *models.User, repo *models.Repository, permission api.Permission) *api.Repository {
|
||||
// ToApiRepository converts repository to API format.
|
||||
func ToApiRepository(owner *models.User, repo *models.Repository, permission api.Permission) *api.Repository {
|
||||
cl := repo.CloneLink()
|
||||
return &api.Repository{
|
||||
Id: repo.ID,
|
||||
Owner: *ApiUser(owner),
|
||||
Owner: *ToApiUser(owner),
|
||||
FullName: owner.Name + "/" + repo.Name,
|
||||
Private: repo.IsPrivate,
|
||||
Fork: repo.IsFork,
|
||||
|
@ -50,8 +50,8 @@ func ApiRepository(owner *models.User, repo *models.Repository, permission api.P
|
|||
}
|
||||
}
|
||||
|
||||
// ApiPublicKey converts public key to its API format.
|
||||
func ApiPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey {
|
||||
// ToApiPublicKey converts public key to its API format.
|
||||
func ToApiPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey {
|
||||
return &api.PublicKey{
|
||||
ID: key.ID,
|
||||
Key: key.Content,
|
||||
|
@ -61,8 +61,8 @@ func ApiPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey {
|
|||
}
|
||||
}
|
||||
|
||||
// ApiHook converts webhook to its API format.
|
||||
func ApiHook(repoLink string, w *models.Webhook) *api.Hook {
|
||||
// ToApiHook converts webhook to its API format.
|
||||
func ToApiHook(repoLink string, w *models.Webhook) *api.Hook {
|
||||
config := map[string]string{
|
||||
"url": w.URL,
|
||||
"content_type": w.ContentType.Name(),
|
||||
|
@ -87,8 +87,8 @@ func ApiHook(repoLink string, w *models.Webhook) *api.Hook {
|
|||
}
|
||||
}
|
||||
|
||||
// ApiDeployKey converts deploy key to its API format.
|
||||
func ApiDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
|
||||
// ToApiDeployKey converts deploy key to its API format.
|
||||
func ToApiDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
|
||||
return &api.DeployKey{
|
||||
ID: key.ID,
|
||||
Key: key.Content,
|
||||
|
@ -98,3 +98,15 @@ func ApiDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
|
|||
ReadOnly: true, // All deploy keys are read-only.
|
||||
}
|
||||
}
|
||||
|
||||
func ToApiOrganization(org *models.User) *api.Organization {
|
||||
return &api.Organization{
|
||||
ID: org.Id,
|
||||
AvatarUrl: org.AvatarLink(),
|
||||
UserName: org.Name,
|
||||
FullName: org.FullName,
|
||||
Description: org.Description,
|
||||
Website: org.Website,
|
||||
Location: org.Location,
|
||||
}
|
||||
}
|
74
routers/api/v1/org/org.go
Normal file
74
routers/api/v1/org/org.go
Normal file
|
@ -0,0 +1,74 @@
|
|||
// 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 org
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
func listUserOrgs(ctx *middleware.Context, u *models.User, all bool) {
|
||||
if err := u.GetOrganizations(all); err != nil {
|
||||
ctx.APIError(500, "GetOrganizations", err)
|
||||
return
|
||||
}
|
||||
|
||||
apiOrgs := make([]*api.Organization, len(u.Orgs))
|
||||
for i := range u.Orgs {
|
||||
apiOrgs[i] = convert.ToApiOrganization(u.Orgs[i])
|
||||
}
|
||||
ctx.JSON(200, &apiOrgs)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Organizations#list-your-organizations
|
||||
func ListMyOrgs(ctx *middleware.Context) {
|
||||
listUserOrgs(ctx, ctx.User, true)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Organizations#list-user-organizations
|
||||
func ListUserOrgs(ctx *middleware.Context) {
|
||||
u := user.GetUserByParams(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
listUserOrgs(ctx, u, false)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Organizations#get-an-organization
|
||||
func Get(ctx *middleware.Context) {
|
||||
org := user.GetUserByParamsName(ctx, ":orgname")
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, convert.ToApiOrganization(org))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Organizations#edit-an-organization
|
||||
func Edit(ctx *middleware.Context, form api.EditOrgOption) {
|
||||
org := user.GetUserByParamsName(ctx, ":orgname")
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
if !org.IsOwnedBy(ctx.User.Id) {
|
||||
ctx.Error(403)
|
||||
return
|
||||
}
|
||||
|
||||
org.FullName = form.FullName
|
||||
org.Description = form.Description
|
||||
org.Website = form.Website
|
||||
org.Location = form.Location
|
||||
if err := models.UpdateUser(org); err != nil {
|
||||
ctx.APIError(500, "UpdateUser", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, convert.ToApiOrganization(org))
|
||||
}
|
|
@ -13,7 +13,7 @@ import (
|
|||
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
to "github.com/gogits/gogs/routers/api/v1/utils"
|
||||
"github.com/gogits/gogs/routers/api/v1/convert"
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-hooks
|
||||
|
@ -26,7 +26,7 @@ func ListHooks(ctx *middleware.Context) {
|
|||
|
||||
apiHooks := make([]*api.Hook, len(hooks))
|
||||
for i := range hooks {
|
||||
apiHooks[i] = to.ApiHook(ctx.Repo.RepoLink, hooks[i])
|
||||
apiHooks[i] = convert.ToApiHook(ctx.Repo.RepoLink, hooks[i])
|
||||
}
|
||||
|
||||
ctx.JSON(200, &apiHooks)
|
||||
|
@ -94,7 +94,7 @@ func CreateHook(ctx *middleware.Context, form api.CreateHookOption) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.JSON(201, to.ApiHook(ctx.Repo.RepoLink, w))
|
||||
ctx.JSON(201, convert.ToApiHook(ctx.Repo.RepoLink, w))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#edit-a-hook
|
||||
|
@ -104,7 +104,7 @@ func EditHook(ctx *middleware.Context, form api.EditHookOption) {
|
|||
if models.IsErrWebhookNotExist(err) {
|
||||
ctx.Error(404)
|
||||
} else {
|
||||
ctx.APIError(500, "GetWebhookById", err)
|
||||
ctx.APIError(500, "GetWebhookByID", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -161,5 +161,5 @@ func EditHook(ctx *middleware.Context, form api.EditHookOption) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, to.ApiHook(ctx.Repo.RepoLink, w))
|
||||
ctx.JSON(200, convert.ToApiHook(ctx.Repo.RepoLink, w))
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
to "github.com/gogits/gogs/routers/api/v1/utils"
|
||||
"github.com/gogits/gogs/routers/api/v1/convert"
|
||||
)
|
||||
|
||||
func composeDeployKeysAPILink(repoPath string) string {
|
||||
|
@ -34,7 +34,7 @@ func ListDeployKeys(ctx *middleware.Context) {
|
|||
ctx.APIError(500, "GetContent", err)
|
||||
return
|
||||
}
|
||||
apiKeys[i] = to.ApiDeployKey(apiLink, keys[i])
|
||||
apiKeys[i] = convert.ToApiDeployKey(apiLink, keys[i])
|
||||
}
|
||||
|
||||
ctx.JSON(200, &apiKeys)
|
||||
|
@ -58,7 +58,7 @@ func GetDeployKey(ctx *middleware.Context) {
|
|||
}
|
||||
|
||||
apiLink := composeDeployKeysAPILink(ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name)
|
||||
ctx.JSON(200, to.ApiDeployKey(apiLink, key))
|
||||
ctx.JSON(200, convert.ToApiDeployKey(apiLink, key))
|
||||
}
|
||||
|
||||
func HandleCheckKeyStringError(ctx *middleware.Context, err error) {
|
||||
|
@ -96,7 +96,7 @@ func CreateDeployKey(ctx *middleware.Context, form api.CreateKeyOption) {
|
|||
|
||||
key.Content = content
|
||||
apiLink := composeDeployKeysAPILink(ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name)
|
||||
ctx.JSON(201, to.ApiDeployKey(apiLink, key))
|
||||
ctx.JSON(201, convert.ToApiDeployKey(apiLink, key))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#remove-a-deploy-key
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
to "github.com/gogits/gogs/routers/api/v1/utils"
|
||||
"github.com/gogits/gogs/routers/api/v1/convert"
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#search-repositories
|
||||
|
@ -97,12 +97,12 @@ func ListMyRepos(ctx *middleware.Context) {
|
|||
|
||||
repos := make([]*api.Repository, numOwnRepos+len(accessibleRepos))
|
||||
for i := range ownRepos {
|
||||
repos[i] = to.ApiRepository(ctx.User, ownRepos[i], api.Permission{true, true, true})
|
||||
repos[i] = convert.ToApiRepository(ctx.User, ownRepos[i], api.Permission{true, true, true})
|
||||
}
|
||||
i := numOwnRepos
|
||||
|
||||
for repo, access := range accessibleRepos {
|
||||
repos[i] = to.ApiRepository(repo.Owner, repo, api.Permission{
|
||||
repos[i] = convert.ToApiRepository(repo.Owner, repo, api.Permission{
|
||||
Admin: access >= models.ACCESS_MODE_ADMIN,
|
||||
Push: access >= models.ACCESS_MODE_WRITE,
|
||||
Pull: true,
|
||||
|
@ -139,7 +139,7 @@ func createRepo(ctx *middleware.Context, owner *models.User, opt api.CreateRepoO
|
|||
return
|
||||
}
|
||||
|
||||
ctx.JSON(201, to.ApiRepository(owner, repo, api.Permission{true, true, true}))
|
||||
ctx.JSON(201, convert.ToApiRepository(owner, repo, api.Permission{true, true, true}))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#create
|
||||
|
@ -239,7 +239,7 @@ func Migrate(ctx *middleware.Context, form auth.MigrateRepoForm) {
|
|||
}
|
||||
|
||||
log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName)
|
||||
ctx.JSON(201, to.ApiRepository(ctxUser, repo, api.Permission{true, true, true}))
|
||||
ctx.JSON(201, convert.ToApiRepository(ctxUser, repo, api.Permission{true, true, true}))
|
||||
}
|
||||
|
||||
func parseOwnerAndRepo(ctx *middleware.Context) (*models.User, *models.Repository) {
|
||||
|
@ -273,7 +273,7 @@ func Get(ctx *middleware.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, to.ApiRepository(owner, repo, api.Permission{true, true, true}))
|
||||
ctx.JSON(200, convert.ToApiRepository(owner, repo, api.Permission{true, true, true}))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#delete
|
||||
|
|
|
@ -10,9 +10,10 @@ import (
|
|||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
to "github.com/gogits/gogs/routers/api/v1/utils"
|
||||
"github.com/gogits/gogs/routers/api/v1/convert"
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#list-email-addresses-for-a-user
|
||||
func ListEmails(ctx *middleware.Context) {
|
||||
emails, err := models.GetEmailAddresses(ctx.User.Id)
|
||||
if err != nil {
|
||||
|
@ -21,11 +22,12 @@ func ListEmails(ctx *middleware.Context) {
|
|||
}
|
||||
apiEmails := make([]*api.Email, len(emails))
|
||||
for i := range emails {
|
||||
apiEmails[i] = to.ApiEmail(emails[i])
|
||||
apiEmails[i] = convert.ToApiEmail(emails[i])
|
||||
}
|
||||
ctx.JSON(200, &apiEmails)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#add-email-addresses
|
||||
func AddEmail(ctx *middleware.Context, form api.CreateEmailOption) {
|
||||
if len(form.Emails) == 0 {
|
||||
ctx.Status(422)
|
||||
|
@ -52,11 +54,12 @@ func AddEmail(ctx *middleware.Context, form api.CreateEmailOption) {
|
|||
|
||||
apiEmails := make([]*api.Email, len(emails))
|
||||
for i := range emails {
|
||||
apiEmails[i] = to.ApiEmail(emails[i])
|
||||
apiEmails[i] = convert.ToApiEmail(emails[i])
|
||||
}
|
||||
ctx.JSON(201, &apiEmails)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#delete-email-addresses
|
||||
func DeleteEmail(ctx *middleware.Context, form api.CreateEmailOption) {
|
||||
if len(form.Emails) == 0 {
|
||||
ctx.Status(204)
|
||||
|
|
|
@ -10,13 +10,12 @@ import (
|
|||
"github.com/gogits/gogs/models"
|
||||
"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/repo"
|
||||
to "github.com/gogits/gogs/routers/api/v1/utils"
|
||||
)
|
||||
|
||||
// GetUserByParams returns user whose name is presented in URL paramenter.
|
||||
func GetUserByParams(ctx *middleware.Context) *models.User {
|
||||
user, err := models.GetUserByName(ctx.Params(":username"))
|
||||
func GetUserByParamsName(ctx *middleware.Context, name string) *models.User {
|
||||
user, err := models.GetUserByName(ctx.Params(name))
|
||||
if err != nil {
|
||||
if models.IsErrUserNotExist(err) {
|
||||
ctx.Error(404)
|
||||
|
@ -28,6 +27,11 @@ func GetUserByParams(ctx *middleware.Context) *models.User {
|
|||
return user
|
||||
}
|
||||
|
||||
// GetUserByParams returns user whose name is presented in URL paramenter.
|
||||
func GetUserByParams(ctx *middleware.Context) *models.User {
|
||||
return GetUserByParamsName(ctx, ":username")
|
||||
}
|
||||
|
||||
func composePublicKeysAPILink() string {
|
||||
return setting.AppUrl + "api/v1/user/keys/"
|
||||
}
|
||||
|
@ -42,7 +46,7 @@ func listPublicKeys(ctx *middleware.Context, uid int64) {
|
|||
apiLink := composePublicKeysAPILink()
|
||||
apiKeys := make([]*api.PublicKey, len(keys))
|
||||
for i := range keys {
|
||||
apiKeys[i] = to.ApiPublicKey(apiLink, keys[i])
|
||||
apiKeys[i] = convert.ToApiPublicKey(apiLink, keys[i])
|
||||
}
|
||||
|
||||
ctx.JSON(200, &apiKeys)
|
||||
|
@ -75,7 +79,7 @@ func GetPublicKey(ctx *middleware.Context) {
|
|||
}
|
||||
|
||||
apiLink := composePublicKeysAPILink()
|
||||
ctx.JSON(200, to.ApiPublicKey(apiLink, key))
|
||||
ctx.JSON(200, convert.ToApiPublicKey(apiLink, key))
|
||||
}
|
||||
|
||||
// CreateUserPublicKey creates new public key to given user by ID.
|
||||
|
@ -92,7 +96,7 @@ func CreateUserPublicKey(ctx *middleware.Context, form api.CreateKeyOption, uid
|
|||
return
|
||||
}
|
||||
apiLink := composePublicKeysAPILink()
|
||||
ctx.JSON(201, to.ApiPublicKey(apiLink, key))
|
||||
ctx.JSON(201, convert.ToApiPublicKey(apiLink, key))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#create-a-public-key
|
||||
|
|
|
@ -54,7 +54,7 @@ func getForkRepository(ctx *middleware.Context) *models.Repository {
|
|||
}
|
||||
ctx.Data["ForkFrom"] = forkRepo.Owner.Name + "/" + forkRepo.Name
|
||||
|
||||
if err := ctx.User.GetOrganizations(); err != nil {
|
||||
if err := ctx.User.GetOrganizations(true); err != nil {
|
||||
ctx.Handle(500, "GetOrganizations", err)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ func getDashboardContextUser(ctx *middleware.Context) *models.User {
|
|||
}
|
||||
ctx.Data["ContextUser"] = ctxUser
|
||||
|
||||
if err := ctx.User.GetOrganizations(); err != nil {
|
||||
if err := ctx.User.GetOrganizations(true); err != nil {
|
||||
ctx.Handle(500, "GetOrganizations", err)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
0.8.8.1216
|
||||
0.8.9.1217
|
Loading…
Reference in a new issue