Browse Source

minor fix on API response

tags/v0.9.99
Unknwon 8 years ago
parent
commit
1453e91f41
5 changed files with 13 additions and 16 deletions
  1. 2
    0
      cmd/web.go
  2. 1
    1
      models/access.go
  3. 1
    1
      models/migrations/migrations.go
  4. 6
    12
      routers/api/v1/repo.go
  5. 3
    2
      routers/api/v1/user.go

+ 2
- 0
cmd/web.go View File

m.Combo("/user/repos", middleware.ApiReqToken()).Get(v1.ListMyRepos). m.Combo("/user/repos", middleware.ApiReqToken()).Get(v1.ListMyRepos).
Post(bind(api.CreateRepoOption{}), v1.CreateRepo) Post(bind(api.CreateRepoOption{}), v1.CreateRepo)
m.Post("/org/:org/repos", middleware.ApiReqToken(), bind(api.CreateRepoOption{}), v1.CreateOrgRepo) 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.Group("/repos", func() {
m.Get("/search", v1.SearchRepos) m.Get("/search", v1.SearchRepos)
m.Post("/migrate", bindIgnErr(auth.MigrateRepoForm{}), v1.MigrateRepo) m.Post("/migrate", bindIgnErr(auth.MigrateRepoForm{}), v1.MigrateRepo)

+ 1
- 1
models/access.go View File

} }


// GetAccessibleRepositories finds all repositories where a user has access to, // 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) { func (u *User) GetAccessibleRepositories() (map[*Repository]AccessMode, error) {
accesses := make([]*Access, 0, 10) accesses := make([]*Access, 0, 10)
if err := x.Find(&accesses, &Access{UserID: u.Id}); err != nil { if err := x.Find(&accesses, &Access{UserID: u.Id}); err != nil {

+ 1
- 1
models/migrations/migrations.go View File

if _, err = sess.Id(actID).Update(&Action{ if _, err = sess.Id(actID).Update(&Action{
Content: string(p), Content: string(p),
}); err != nil { }); err != nil {
return fmt.Errorf("update action[%s]: %v", actID, err)
return fmt.Errorf("update action[%d]: %v", actID, err)
} }
} }
return sess.Commit() return sess.Commit()

+ 6
- 12
routers/api/v1/repo.go View File

return 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 // POST /user/repos
i := numOwnRepos i := numOwnRepos


for repo, access := range accessibleRepos { 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++ i++
} }



+ 3
- 2
routers/api/v1/user.go View File

"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
) )


// ToApiUser converts user to API format. // ToApiUser converts user to API format.
return &api.User{ return &api.User{
ID: u.Id, ID: u.Id,
UserName: u.Name, UserName: u.Name,
AvatarUrl: string(setting.Protocol) + u.AvatarLink(),
FullName: u.FullName,
Email: u.Email,
AvatarUrl: u.AvatarLink(),
} }
} }



Loading…
Cancel
Save