summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-08-19 20:08:57 +0800
committerUnknwon <u@gogs.io>2015-08-19 20:08:57 +0800
commit1453e91f419e52fc74e3ec51b47a080a27a33342 (patch)
treee8bb9e381999b6a8a09685af003ed7580da2a116
parent2b393f5b039db177a58be03f1c5c746eac501686 (diff)
downloadgitea-1453e91f419e52fc74e3ec51b47a080a27a33342.tar.gz
gitea-1453e91f419e52fc74e3ec51b47a080a27a33342.zip
minor fix on API response
-rw-r--r--cmd/web.go2
-rw-r--r--models/access.go2
-rw-r--r--models/migrations/migrations.go2
-rw-r--r--routers/api/v1/repo.go18
-rw-r--r--routers/api/v1/user.go5
5 files changed, 13 insertions, 16 deletions
diff --git a/cmd/web.go b/cmd/web.go
index ae4403c0ca..05daf558b0 100644
--- a/cmd/web.go
+++ b/cmd/web.go
@@ -232,6 +232,8 @@ func runWeb(ctx *cli.Context) {
m.Combo("/user/repos", middleware.ApiReqToken()).Get(v1.ListMyRepos).
Post(bind(api.CreateRepoOption{}), v1.CreateRepo)
m.Post("/org/:org/repos", middleware.ApiReqToken(), bind(api.CreateRepoOption{}), v1.CreateOrgRepo)
+
+ // TODO: https://github.com/gogits/go-gogs-client/wiki
m.Group("/repos", func() {
m.Get("/search", v1.SearchRepos)
m.Post("/migrate", bindIgnErr(auth.MigrateRepoForm{}), v1.MigrateRepo)
diff --git a/models/access.go b/models/access.go
index 8d698f151d..917f1c280d 100644
--- a/models/access.go
+++ b/models/access.go
@@ -68,7 +68,7 @@ func HasAccess(u *User, repo *Repository, testMode AccessMode) (bool, error) {
}
// GetAccessibleRepositories finds all repositories where a user has access to,
-// besides his own.
+// besides he/she owns.
func (u *User) GetAccessibleRepositories() (map[*Repository]AccessMode, error) {
accesses := make([]*Access, 0, 10)
if err := x.Find(&accesses, &Access{UserID: u.Id}); err != nil {
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index f1d6c91af5..08a503e6da 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -470,7 +470,7 @@ func trimCommitActionAppUrlPrefix(x *xorm.Engine) error {
if _, err = sess.Id(actID).Update(&Action{
Content: string(p),
}); err != nil {
- return fmt.Errorf("update action[%s]: %v", actID, err)
+ return fmt.Errorf("update action[%d]: %v", actID, err)
}
}
return sess.Commit()
diff --git a/routers/api/v1/repo.go b/routers/api/v1/repo.go
index c6dabfcb86..3f5394172a 100644
--- a/routers/api/v1/repo.go
+++ b/routers/api/v1/repo.go
@@ -120,7 +120,7 @@ func createRepo(ctx *middleware.Context, owner *models.User, opt api.CreateRepoO
return
}
- ctx.JSON(200, ToApiRepository(owner, repo, api.Permission{true, true, true}))
+ ctx.JSON(201, ToApiRepository(owner, repo, api.Permission{true, true, true}))
}
// POST /user/repos
@@ -254,17 +254,11 @@ func ListMyRepos(ctx *middleware.Context) {
i := numOwnRepos
for repo, access := range accessibleRepos {
- if err = repo.GetOwner(); err != nil {
- ctx.JSON(500, &base.ApiJsonErr{"GetOwner: " + err.Error(), base.DOC_URL})
- return
- }
-
- repos[i] = ToApiRepository(repo.Owner, repo, api.Permission{false, access >= models.ACCESS_MODE_WRITE, true})
-
- // FIXME: cache result to reduce DB query?
- if repo.Owner.IsOrganization() && repo.Owner.IsOwnedBy(ctx.User.Id) {
- repos[i].Permissions.Admin = true
- }
+ repos[i] = ToApiRepository(repo.Owner, repo, api.Permission{
+ Admin: access >= models.ACCESS_MODE_ADMIN,
+ Push: access >= models.ACCESS_MODE_WRITE,
+ Pull: true,
+ })
i++
}
diff --git a/routers/api/v1/user.go b/routers/api/v1/user.go
index 60b6adcd12..57bf68bb56 100644
--- a/routers/api/v1/user.go
+++ b/routers/api/v1/user.go
@@ -12,7 +12,6 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware"
- "github.com/gogits/gogs/modules/setting"
)
// ToApiUser converts user to API format.
@@ -20,7 +19,9 @@ func ToApiUser(u *models.User) *api.User {
return &api.User{
ID: u.Id,
UserName: u.Name,
- AvatarUrl: string(setting.Protocol) + u.AvatarLink(),
+ FullName: u.FullName,
+ Email: u.Email,
+ AvatarUrl: u.AvatarLink(),
}
}