Explorar o código

[api] Deep forking should be possible

With forks deeper then 1 (meaning forks of forks) the api breaks as it will
recursively ask for parents which in turn have not been fetched from the db.

Limiting the depth of the parent retrieval works around this.
cgars %!s(int64=7) %!d(string=hai) anos
pai
achega
9f57801ab7
Modificáronse 1 ficheiros con 3 adicións e 7 borrados
  1. 3 7
      models/repo.go

+ 3 - 7
models/repo.go

@@ -383,13 +383,9 @@ func (repo *Repository) APIFormat(permission *api.Permission, user ...*User) *ap
 		// Reserved for go-gogs-client change
 		//		AvatarUrl:     repo.AvatarLink(),
 	}
-	if repo.IsFork {
-		p := &api.Permission{Pull: true}
-		if len(user) != 0 {
-			p.Admin = user[0].IsAdminOfRepo(repo)
-			p.Push = user[0].IsWriterOfRepo(repo)
-		}
-		apiRepo.Parent = repo.BaseRepo.APIFormat(p)
+	if repo.IsFork && repo.BaseRepo != nil {
+		// FIXME: check precise permission for base repository
+		apiRepo.Parent = repo.BaseRepo.APIFormat(nil)
 	}
 	return apiRepo
 }