summaryrefslogtreecommitdiffstats
path: root/routers/repo/pull.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/repo/pull.go')
-rw-r--r--routers/repo/pull.go43
1 files changed, 26 insertions, 17 deletions
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index 0eea5fcbe6..8269717e57 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -51,8 +51,8 @@ var (
}
)
-func getForkRepository(ctx *context.Context) *models.Repository {
- forkRepo, err := models.GetRepositoryByID(ctx.ParamsInt64(":repoid"))
+func getRepository(ctx *context.Context, repoID int64) *models.Repository {
+ repo, err := models.GetRepositoryByID(repoID)
if err != nil {
if models.IsErrRepoNotExist(err) {
ctx.NotFound("GetRepositoryByID", nil)
@@ -62,25 +62,33 @@ func getForkRepository(ctx *context.Context) *models.Repository {
return nil
}
- perm, err := models.GetUserRepoPermission(forkRepo, ctx.User)
+ perm, err := models.GetUserRepoPermission(repo, ctx.User)
if err != nil {
ctx.ServerError("GetUserRepoPermission", err)
return nil
}
- if forkRepo.IsEmpty || !perm.CanRead(models.UnitTypeCode) {
- if log.IsTrace() {
- if forkRepo.IsEmpty {
- log.Trace("Empty fork repository %-v", forkRepo)
- } else {
- log.Trace("Permission Denied: User %-v cannot read %-v of forkRepo %-v\n"+
- "User in forkRepo has Permissions: %-+v",
- ctx.User,
- models.UnitTypeCode,
- ctx.Repo,
- perm)
- }
- }
+ if !perm.CanRead(models.UnitTypeCode) {
+ log.Trace("Permission Denied: User %-v cannot read %-v of repo %-v\n"+
+ "User in repo has Permissions: %-+v",
+ ctx.User,
+ models.UnitTypeCode,
+ ctx.Repo,
+ perm)
+ ctx.NotFound("getRepository", nil)
+ return nil
+ }
+ return repo
+}
+
+func getForkRepository(ctx *context.Context) *models.Repository {
+ forkRepo := getRepository(ctx, ctx.ParamsInt64(":repoid"))
+ if ctx.Written() {
+ return nil
+ }
+
+ if forkRepo.IsEmpty {
+ log.Trace("Empty repository %-v", forkRepo)
ctx.NotFound("getForkRepository", nil)
return nil
}
@@ -90,7 +98,7 @@ func getForkRepository(ctx *context.Context) *models.Repository {
ctx.Data["IsPrivate"] = forkRepo.IsPrivate
canForkToUser := forkRepo.OwnerID != ctx.User.ID && !ctx.User.HasForkedRepo(forkRepo.ID)
- if err = forkRepo.GetOwner(); err != nil {
+ if err := forkRepo.GetOwner(); err != nil {
ctx.ServerError("GetOwner", err)
return nil
}
@@ -109,6 +117,7 @@ func getForkRepository(ctx *context.Context) *models.Repository {
}
var traverseParentRepo = forkRepo
+ var err error
for {
if ctx.User.ID == traverseParentRepo.OwnerID {
canForkToUser = false