diff options
author | Lauris BH <lauris@nix.lv> | 2017-10-15 18:06:07 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-15 18:06:07 +0300 |
commit | 1ec4dc6c1dec3814d8956bcd1157a51bfe53eb0e (patch) | |
tree | 742d82bceac48af7f5088be3c70bdb6d000728ea /routers/repo | |
parent | 32ca299650277829b93994eca1508f9d84a5b667 (diff) | |
download | gitea-1ec4dc6c1dec3814d8956bcd1157a51bfe53eb0e.tar.gz gitea-1ec4dc6c1dec3814d8956bcd1157a51bfe53eb0e.zip |
Fix so that user can still fork his own repository to owned organizations (#2699)
* Fix so that user can still fork his own repository to his organizations
* Fix to only use owned organizations
* Add integration test for forking own repository to owned organization
Diffstat (limited to 'routers/repo')
-rw-r--r-- | routers/repo/pull.go | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/routers/repo/pull.go b/routers/repo/pull.go index 48e17665da..f80e8cb1e5 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -61,6 +61,8 @@ func getForkRepository(ctx *context.Context) *models.Repository { ctx.Data["repo_name"] = forkRepo.Name ctx.Data["description"] = forkRepo.Description ctx.Data["IsPrivate"] = forkRepo.IsPrivate + canForkToUser := forkRepo.OwnerID != ctx.User.ID && !ctx.User.HasForkedRepo(forkRepo.ID) + ctx.Data["CanForkToUser"] = canForkToUser if err = forkRepo.GetOwner(); err != nil { ctx.Handle(500, "GetOwner", err) @@ -69,11 +71,23 @@ func getForkRepository(ctx *context.Context) *models.Repository { ctx.Data["ForkFrom"] = forkRepo.Owner.Name + "/" + forkRepo.Name ctx.Data["ForkFromOwnerID"] = forkRepo.Owner.ID - if err := ctx.User.GetOrganizations(true); err != nil { - ctx.Handle(500, "GetOrganizations", err) + if err := ctx.User.GetOwnedOrganizations(); err != nil { + ctx.Handle(500, "GetOwnedOrganizations", err) return nil } - ctx.Data["Orgs"] = ctx.User.Orgs + var orgs []*models.User + for _, org := range ctx.User.OwnedOrgs { + if forkRepo.OwnerID != org.ID && !org.HasForkedRepo(forkRepo.ID) { + orgs = append(orgs, org) + } + } + ctx.Data["Orgs"] = orgs + + if canForkToUser { + ctx.Data["ContextUser"] = ctx.User + } else if len(orgs) > 0 { + ctx.Data["ContextUser"] = orgs[0] + } return forkRepo } @@ -87,7 +101,6 @@ func Fork(ctx *context.Context) { return } - ctx.Data["ContextUser"] = ctx.User ctx.HTML(200, tplFork) } @@ -95,15 +108,16 @@ func Fork(ctx *context.Context) { func ForkPost(ctx *context.Context, form auth.CreateRepoForm) { ctx.Data["Title"] = ctx.Tr("new_fork") - forkRepo := getForkRepository(ctx) + ctxUser := checkContextUser(ctx, form.UID) if ctx.Written() { return } - ctxUser := checkContextUser(ctx, form.UID) + forkRepo := getForkRepository(ctx) if ctx.Written() { return } + ctx.Data["ContextUser"] = ctxUser if ctx.HasError() { |