#1692 add organization APIs

This commit is contained in:
Unknwon 2015-12-17 02:28:47 -05:00
parent 6673dcb038
commit 9cd16c5b12
20 changed files with 204 additions and 55 deletions

View File

@ -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) ![](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 | | Web | UI | Preview |
|:-------------:|:-------:|:-------:| |:-------------:|:-------:|:-------:|

View File

@ -110,7 +110,7 @@ func handleUpdateTask(uuid string, user, repoUser *models.User, reponame string,
} }
// Ask for running deliver hook and test pull request tasks. // 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) strings.TrimPrefix(task.RefName, "refs/heads/") + "&secret=" + base.EncodeMD5(repoUser.Salt)
log.GitLogger.Trace("Trigger task: %s", reqURL) log.GitLogger.Trace("Trigger task: %s", reqURL)

View File

@ -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. - **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`. - **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. - **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. - **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/`). - **Application URL**: Use combination of **Domain** and **exposed HTTP Port** values(e.g. `http://192.168.99.100:10080/`).

View File

@ -18,7 +18,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.8.8.1216" const APP_VER = "0.8.9.1217"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

View File

@ -274,10 +274,15 @@ func GetOwnedOrgsByUserIDDesc(userID int64, desc string) ([]*User, error) {
return getOwnedOrgsByUserID(sess.Desc(desc), userID) return getOwnedOrgsByUserID(sess.Desc(desc), userID)
} }
// GetOrgUsersByUserId returns all organization-user relations by user ID. // GetOrgUsersByUserID returns all organization-user relations by user ID.
func GetOrgUsersByUserId(uid int64) ([]*OrgUser, error) { func GetOrgUsersByUserID(uid int64, all bool) ([]*OrgUser, error) {
ous := make([]*OrgUser, 0, 10) 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 return ous, err
} }

View File

@ -376,8 +376,8 @@ func (u *User) GetOwnedOrganizations() (err error) {
} }
// GetOrganizations returns all organizations that user belongs to. // GetOrganizations returns all organizations that user belongs to.
func (u *User) GetOrganizations() error { func (u *User) GetOrganizations(all bool) error {
ous, err := GetOrgUsersByUserId(u.Id) ous, err := GetOrgUsersByUserID(u.Id, all)
if err != nil { if err != nil {
return err return err
} }

View File

@ -59,7 +59,7 @@ var (
Protocol Scheme Protocol Scheme
Domain string Domain string
HttpAddr, HttpPort string HttpAddr, HttpPort string
LocalUrl string LocalURL string
DisableSSH bool DisableSSH bool
StartSSHServer bool StartSSHServer bool
SSHDomain string SSHDomain string
@ -302,7 +302,7 @@ func NewContext() {
Domain = sec.Key("DOMAIN").MustString("localhost") Domain = sec.Key("DOMAIN").MustString("localhost")
HttpAddr = sec.Key("HTTP_ADDR").MustString("0.0.0.0") HttpAddr = sec.Key("HTTP_ADDR").MustString("0.0.0.0")
HttpPort = sec.Key("HTTP_PORT").MustString("3000") 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() DisableSSH = sec.Key("DISABLE_SSH").MustBool()
if !DisableSSH { if !DisableSSH {
StartSSHServer = sec.Key("START_SSH_SERVER").MustBool() StartSSHServer = sec.Key("START_SSH_SERVER").MustBool()

View 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))
}

View File

@ -12,8 +12,8 @@ import (
"github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/routers/api/v1/convert"
"github.com/gogits/gogs/routers/api/v1/user" "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) { 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) 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 // 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) 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 // https://github.com/gogits/go-gogs-client/wiki/Administration-Users#delete-a-user

View File

@ -17,6 +17,7 @@ import (
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/routers/api/v1/admin" "github.com/gogits/gogs/routers/api/v1/admin"
"github.com/gogits/gogs/routers/api/v1/misc" "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/repo"
"github.com/gogits/gogs/routers/api/v1/user" "github.com/gogits/gogs/routers/api/v1/user"
) )
@ -179,6 +180,11 @@ func RegisterRoutes(m *macaron.Macaron) {
}, RepoAssignment()) }, RepoAssignment())
}, ReqToken()) }, 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) { m.Any("/*", func(ctx *middleware.Context) {
ctx.Error(404) ctx.Error(404)
}) })
@ -191,6 +197,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Combo("").Patch(bind(api.EditUserOption{}), admin.EditUser). m.Combo("").Patch(bind(api.EditUserOption{}), admin.EditUser).
Delete(admin.DeleteUser) Delete(admin.DeleteUser)
m.Post("/keys", admin.CreatePublicKey) m.Post("/keys", admin.CreatePublicKey)
m.Post("/orgs", bind(api.CreateOrgOption{}), admin.CreateOrg)
}) })
}) })
}, ReqAdmin()) }, ReqAdmin())

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package utils package convert
import ( import (
"fmt" "fmt"
@ -15,8 +15,8 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
// ApiUser converts user to its API format. // ToApiUser converts user to its API format.
func ApiUser(u *models.User) *api.User { func ToApiUser(u *models.User) *api.User {
return &api.User{ return &api.User{
ID: u.Id, ID: u.Id,
UserName: u.Name, 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{ return &api.Email{
Email: email.Email, Email: email.Email,
Verified: email.IsActivated, Verified: email.IsActivated,
@ -34,12 +34,12 @@ func ApiEmail(email *models.EmailAddress) *api.Email {
} }
} }
// ApiRepository converts repository to API format. // ToApiRepository converts repository to API format.
func ApiRepository(owner *models.User, repo *models.Repository, permission api.Permission) *api.Repository { func ToApiRepository(owner *models.User, repo *models.Repository, permission api.Permission) *api.Repository {
cl := repo.CloneLink() cl := repo.CloneLink()
return &api.Repository{ return &api.Repository{
Id: repo.ID, Id: repo.ID,
Owner: *ApiUser(owner), Owner: *ToApiUser(owner),
FullName: owner.Name + "/" + repo.Name, FullName: owner.Name + "/" + repo.Name,
Private: repo.IsPrivate, Private: repo.IsPrivate,
Fork: repo.IsFork, 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. // ToApiPublicKey converts public key to its API format.
func ApiPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey { func ToApiPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey {
return &api.PublicKey{ return &api.PublicKey{
ID: key.ID, ID: key.ID,
Key: key.Content, Key: key.Content,
@ -61,8 +61,8 @@ func ApiPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey {
} }
} }
// ApiHook converts webhook to its API format. // ToApiHook converts webhook to its API format.
func ApiHook(repoLink string, w *models.Webhook) *api.Hook { func ToApiHook(repoLink string, w *models.Webhook) *api.Hook {
config := map[string]string{ config := map[string]string{
"url": w.URL, "url": w.URL,
"content_type": w.ContentType.Name(), "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. // ToApiDeployKey converts deploy key to its API format.
func ApiDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey { func ToApiDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
return &api.DeployKey{ return &api.DeployKey{
ID: key.ID, ID: key.ID,
Key: key.Content, Key: key.Content,
@ -98,3 +98,15 @@ func ApiDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
ReadOnly: true, // All deploy keys are read-only. 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
View 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))
}

View File

@ -13,7 +13,7 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/middleware" "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 // 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)) apiHooks := make([]*api.Hook, len(hooks))
for i := range 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) ctx.JSON(200, &apiHooks)
@ -94,7 +94,7 @@ func CreateHook(ctx *middleware.Context, form api.CreateHookOption) {
return 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 // 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) { if models.IsErrWebhookNotExist(err) {
ctx.Error(404) ctx.Error(404)
} else { } else {
ctx.APIError(500, "GetWebhookById", err) ctx.APIError(500, "GetWebhookByID", err)
} }
return return
} }
@ -161,5 +161,5 @@ func EditHook(ctx *middleware.Context, form api.EditHookOption) {
return return
} }
ctx.JSON(200, to.ApiHook(ctx.Repo.RepoLink, w)) ctx.JSON(200, convert.ToApiHook(ctx.Repo.RepoLink, w))
} }

View File

@ -12,7 +12,7 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "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 { func composeDeployKeysAPILink(repoPath string) string {
@ -34,7 +34,7 @@ func ListDeployKeys(ctx *middleware.Context) {
ctx.APIError(500, "GetContent", err) ctx.APIError(500, "GetContent", err)
return return
} }
apiKeys[i] = to.ApiDeployKey(apiLink, keys[i]) apiKeys[i] = convert.ToApiDeployKey(apiLink, keys[i])
} }
ctx.JSON(200, &apiKeys) ctx.JSON(200, &apiKeys)
@ -58,7 +58,7 @@ func GetDeployKey(ctx *middleware.Context) {
} }
apiLink := composeDeployKeysAPILink(ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name) 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) { func HandleCheckKeyStringError(ctx *middleware.Context, err error) {
@ -96,7 +96,7 @@ func CreateDeployKey(ctx *middleware.Context, form api.CreateKeyOption) {
key.Content = content key.Content = content
apiLink := composeDeployKeysAPILink(ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name) 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 // https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#remove-a-deploy-key

View File

@ -16,7 +16,7 @@ import (
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "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 // 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)) repos := make([]*api.Repository, numOwnRepos+len(accessibleRepos))
for i := range ownRepos { 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 i := numOwnRepos
for repo, access := range accessibleRepos { 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, Admin: access >= models.ACCESS_MODE_ADMIN,
Push: access >= models.ACCESS_MODE_WRITE, Push: access >= models.ACCESS_MODE_WRITE,
Pull: true, Pull: true,
@ -139,7 +139,7 @@ func createRepo(ctx *middleware.Context, owner *models.User, opt api.CreateRepoO
return 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 // 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) 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) { func parseOwnerAndRepo(ctx *middleware.Context) (*models.User, *models.Repository) {
@ -273,7 +273,7 @@ func Get(ctx *middleware.Context) {
return 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 // https://github.com/gogits/go-gogs-client/wiki/Repositories#delete

View File

@ -10,9 +10,10 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "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) { func ListEmails(ctx *middleware.Context) {
emails, err := models.GetEmailAddresses(ctx.User.Id) emails, err := models.GetEmailAddresses(ctx.User.Id)
if err != nil { if err != nil {
@ -21,11 +22,12 @@ func ListEmails(ctx *middleware.Context) {
} }
apiEmails := make([]*api.Email, len(emails)) apiEmails := make([]*api.Email, len(emails))
for i := range emails { for i := range emails {
apiEmails[i] = to.ApiEmail(emails[i]) apiEmails[i] = convert.ToApiEmail(emails[i])
} }
ctx.JSON(200, &apiEmails) 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) { func AddEmail(ctx *middleware.Context, form api.CreateEmailOption) {
if len(form.Emails) == 0 { if len(form.Emails) == 0 {
ctx.Status(422) ctx.Status(422)
@ -52,11 +54,12 @@ func AddEmail(ctx *middleware.Context, form api.CreateEmailOption) {
apiEmails := make([]*api.Email, len(emails)) apiEmails := make([]*api.Email, len(emails))
for i := range emails { for i := range emails {
apiEmails[i] = to.ApiEmail(emails[i]) apiEmails[i] = convert.ToApiEmail(emails[i])
} }
ctx.JSON(201, &apiEmails) 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) { func DeleteEmail(ctx *middleware.Context, form api.CreateEmailOption) {
if len(form.Emails) == 0 { if len(form.Emails) == 0 {
ctx.Status(204) ctx.Status(204)

View File

@ -10,13 +10,12 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/routers/api/v1/convert"
"github.com/gogits/gogs/routers/api/v1/repo" "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 GetUserByParamsName(ctx *middleware.Context, name string) *models.User {
func GetUserByParams(ctx *middleware.Context) *models.User { user, err := models.GetUserByName(ctx.Params(name))
user, err := models.GetUserByName(ctx.Params(":username"))
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Error(404) ctx.Error(404)
@ -28,6 +27,11 @@ func GetUserByParams(ctx *middleware.Context) *models.User {
return 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 { func composePublicKeysAPILink() string {
return setting.AppUrl + "api/v1/user/keys/" return setting.AppUrl + "api/v1/user/keys/"
} }
@ -42,7 +46,7 @@ func listPublicKeys(ctx *middleware.Context, uid int64) {
apiLink := composePublicKeysAPILink() apiLink := composePublicKeysAPILink()
apiKeys := make([]*api.PublicKey, len(keys)) apiKeys := make([]*api.PublicKey, len(keys))
for i := range keys { for i := range keys {
apiKeys[i] = to.ApiPublicKey(apiLink, keys[i]) apiKeys[i] = convert.ToApiPublicKey(apiLink, keys[i])
} }
ctx.JSON(200, &apiKeys) ctx.JSON(200, &apiKeys)
@ -75,7 +79,7 @@ func GetPublicKey(ctx *middleware.Context) {
} }
apiLink := composePublicKeysAPILink() 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. // CreateUserPublicKey creates new public key to given user by ID.
@ -92,7 +96,7 @@ func CreateUserPublicKey(ctx *middleware.Context, form api.CreateKeyOption, uid
return return
} }
apiLink := composePublicKeysAPILink() 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 // https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#create-a-public-key

View File

@ -54,7 +54,7 @@ func getForkRepository(ctx *middleware.Context) *models.Repository {
} }
ctx.Data["ForkFrom"] = forkRepo.Owner.Name + "/" + forkRepo.Name 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) ctx.Handle(500, "GetOrganizations", err)
return nil return nil
} }

View File

@ -44,7 +44,7 @@ func getDashboardContextUser(ctx *middleware.Context) *models.User {
} }
ctx.Data["ContextUser"] = ctxUser ctx.Data["ContextUser"] = ctxUser
if err := ctx.User.GetOrganizations(); err != nil { if err := ctx.User.GetOrganizations(true); err != nil {
ctx.Handle(500, "GetOrganizations", err) ctx.Handle(500, "GetOrganizations", err)
return nil return nil
} }

View File

@ -1 +1 @@
0.8.8.1216 0.8.9.1217