fix #1302
This commit is contained in:
parent
1d57f0d64f
commit
f8ae161c74
|
@ -67,9 +67,8 @@ func HasAccess(u *User, repo *Repository, testMode AccessMode) (bool, error) {
|
|||
return hasAccess(x, u, repo, testMode)
|
||||
}
|
||||
|
||||
// GetAccessibleRepositories finds all repositories where a user has access to,
|
||||
// besides he/she owns.
|
||||
func (u *User) GetAccessibleRepositories() (map[*Repository]AccessMode, error) {
|
||||
// GetRepositoryAccesses finds all repositories with their access mode where a user has access but does not own.
|
||||
func (u *User) GetRepositoryAccesses() (map[*Repository]AccessMode, error) {
|
||||
accesses := make([]*Access, 0, 10)
|
||||
if err := x.Find(&accesses, &Access{UserID: u.Id}); err != nil {
|
||||
return nil, err
|
||||
|
@ -80,7 +79,7 @@ func (u *User) GetAccessibleRepositories() (map[*Repository]AccessMode, error) {
|
|||
repo, err := GetRepositoryByID(access.RepoID)
|
||||
if err != nil {
|
||||
if IsErrRepoNotExist(err) {
|
||||
log.Error(4, "%v", err)
|
||||
log.Error(4, "GetRepositoryByID: %v", err)
|
||||
continue
|
||||
}
|
||||
return nil, err
|
||||
|
@ -92,11 +91,24 @@ func (u *User) GetAccessibleRepositories() (map[*Repository]AccessMode, error) {
|
|||
}
|
||||
repos[repo] = access.Mode
|
||||
}
|
||||
|
||||
// FIXME: should we generate an ordered list here? Random looks weird.
|
||||
return repos, nil
|
||||
}
|
||||
|
||||
// GetAccessibleRepositories finds all repositories where a user has access but does not own.
|
||||
func (u *User) GetAccessibleRepositories() ([]*Repository, error) {
|
||||
accesses := make([]*Access, 0, 10)
|
||||
if err := x.Find(&accesses, &Access{UserID: u.Id}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
repoIDs := make([]int64, 0, len(accesses))
|
||||
for _, access := range accesses {
|
||||
repoIDs = append(repoIDs, access.RepoID)
|
||||
}
|
||||
repos := make([]*Repository, 0, len(repoIDs))
|
||||
return repos, x.Where("owner_id != ?", u.Id).In("id", repoIDs).Desc("updated").Find(&repos)
|
||||
}
|
||||
|
||||
func maxAccessMode(modes ...AccessMode) AccessMode {
|
||||
max := ACCESS_MODE_NONE
|
||||
for _, mode := range modes {
|
||||
|
|
|
@ -106,9 +106,9 @@ func ListMyRepos(ctx *middleware.Context) {
|
|||
}
|
||||
numOwnRepos := len(ownRepos)
|
||||
|
||||
accessibleRepos, err := ctx.User.GetAccessibleRepositories()
|
||||
accessibleRepos, err := ctx.User.GetRepositoryAccesses()
|
||||
if err != nil {
|
||||
ctx.APIError(500, "GetAccessibleRepositories", err)
|
||||
ctx.APIError(500, "GetRepositoryAccesses", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -62,23 +62,21 @@ func Dashboard(ctx *middleware.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
// Check context type.
|
||||
if !ctxUser.IsOrganization() {
|
||||
// Normal user.
|
||||
ctxUser = ctx.User
|
||||
collaborates, err := ctx.User.GetAccessibleRepositories()
|
||||
collaborateRepos, err := ctx.User.GetAccessibleRepositories()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetAccessibleRepositories", err)
|
||||
return
|
||||
}
|
||||
|
||||
repositories := make([]*models.Repository, 0, len(collaborates))
|
||||
for repo := range collaborates {
|
||||
repositories = append(repositories, repo)
|
||||
for i := range collaborateRepos {
|
||||
if err = collaborateRepos[i].GetOwner(); err != nil {
|
||||
ctx.Handle(500, "GetOwner: "+collaborateRepos[i].Name, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["CollaborateCount"] = len(repositories)
|
||||
ctx.Data["CollaborativeRepos"] = repositories
|
||||
}
|
||||
ctx.Data["CollaborateCount"] = len(collaborateRepos)
|
||||
ctx.Data["CollaborativeRepos"] = collaborateRepos
|
||||
}
|
||||
|
||||
repos, err := models.GetRepositories(ctxUser.Id, true)
|
||||
|
@ -89,7 +87,7 @@ func Dashboard(ctx *middleware.Context) {
|
|||
ctx.Data["Repos"] = repos
|
||||
|
||||
// Get mirror repositories.
|
||||
mirrors := make([]*models.Repository, 0, len(repos)/2)
|
||||
mirrors := make([]*models.Repository, 0, 5)
|
||||
for _, repo := range repos {
|
||||
if repo.IsMirror {
|
||||
if err = repo.GetMirror(); err != nil {
|
||||
|
|
Loading…
Reference in New Issue