mirror of
https://github.com/gogs/gogs.git
synced 2026-02-05 14:09:21 +01:00
api: fix nil pointer dereference when listing user repos (#8069)
Co-authored-by: Joe Chen <jc@unknwon.io>
This commit is contained in:
@@ -116,19 +116,28 @@ func listUserRepositories(c *context.APIContext, username string) {
|
||||
return
|
||||
}
|
||||
|
||||
accessibleRepos, err := db.Repos.GetByCollaboratorIDWithAccessMode(c.Req.Context(), user.ID)
|
||||
accessibleReposWithAccessMode, err := db.Repos.GetByCollaboratorIDWithAccessMode(c.Req.Context(), user.ID)
|
||||
if err != nil {
|
||||
c.Error(err, "get repositories accesses by collaborator")
|
||||
return
|
||||
}
|
||||
|
||||
accessibleRepos := make([]*db.Repository, 0, len(accessibleReposWithAccessMode))
|
||||
for repo := range accessibleReposWithAccessMode {
|
||||
accessibleRepos = append(accessibleRepos, repo)
|
||||
}
|
||||
if err = db.RepositoryList(accessibleRepos).LoadAttributes(); err != nil {
|
||||
c.Error(err, "load attributes for accessible repositories")
|
||||
return
|
||||
}
|
||||
|
||||
numOwnRepos := len(ownRepos)
|
||||
repos := make([]*api.Repository, 0, numOwnRepos+len(accessibleRepos))
|
||||
repos := make([]*api.Repository, 0, numOwnRepos+len(accessibleReposWithAccessMode))
|
||||
for _, r := range ownRepos {
|
||||
repos = append(repos, r.APIFormatLegacy(&api.Permission{Admin: true, Push: true, Pull: true}))
|
||||
}
|
||||
|
||||
for repo, access := range accessibleRepos {
|
||||
for repo, access := range accessibleReposWithAccessMode {
|
||||
repos = append(repos,
|
||||
repo.APIFormatLegacy(&api.Permission{
|
||||
Admin: access >= db.AccessModeAdmin,
|
||||
|
||||
Reference in New Issue
Block a user