From a467184e13e4e3867031c191263dc0adaec2673c Mon Sep 17 00:00:00 2001 From: Download-Fritz Date: Fri, 19 Feb 2016 20:33:06 +0100 Subject: [PATCH 1/2] #2505 Allow to fork and disallow to create PRs for mirrors. --- models/repo.go | 12 +++++++++++- modules/middleware/repo.go | 2 +- routers/repo/issue.go | 4 +++- templates/repo/header.tmpl | 2 +- templates/repo/settings/options.tmpl | 16 +++++++++------- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/models/repo.go b/models/repo.go index 57014beb0a..98bb1107b3 100644 --- a/models/repo.go +++ b/models/repo.go @@ -332,7 +332,17 @@ func (repo *Repository) IsOwnedBy(userID int64) bool { // CanBeForked returns true if repository meets the requirements of being forked. func (repo *Repository) CanBeForked() bool { - return !repo.IsBare && !repo.IsMirror + return !repo.IsBare +} + +// CanEnablePulls returns true if repository meets the requirements of accepting pulls. +func (repo *Repository) CanEnablePulls() bool { + return !repo.IsMirror +} + +// AllowPulls returns true if repository meets the requirements of accepting pulls and has them enabled. +func (repo *Repository) AllowsPulls() bool { + return repo.CanEnablePulls() && repo.EnablePulls; } func (repo *Repository) NextIssueIndex() int64 { diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index 9ceb9903dd..fb636d93fa 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -167,7 +167,7 @@ func RepoAssignment(args ...bool) macaron.Handler { ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner() ctx.Data["IsRepositoryAdmin"] = ctx.Repo.IsAdmin() ctx.Data["IsRepositoryPusher"] = ctx.Repo.IsPusher() - ctx.Data["CanPullRequest"] = ctx.Repo.IsAdmin() && repo.BaseRepo != nil && repo.BaseRepo.EnablePulls + ctx.Data["CanPullRequest"] = ctx.Repo.IsAdmin() && repo.BaseRepo != nil && repo.BaseRepo.AllowsPulls() ctx.Data["DisableSSH"] = setting.DisableSSH ctx.Data["CloneLink"] = repo.CloneLink() diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 635dee930e..76822eb05e 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -48,7 +48,9 @@ func MustEnableIssues(ctx *middleware.Context) { } func MustEnablePulls(ctx *middleware.Context) { - if !ctx.Repo.Repository.EnablePulls { + if !ctx.Repo.Repository.CanEnablePulls() { + ctx.Handle(404, "Unsupported", nil) + } else if !ctx.Repo.Repository.EnablePulls { ctx.Handle(404, "MustEnablePulls", nil) } diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index 3002ff4b38..34ef9fafa1 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -57,7 +57,7 @@ {{.i18n.Tr "repo.issues"}} {{.Repository.NumOpenIssues}} {{end}} - {{if .Repository.EnablePulls}} + {{if .Repository.AllowsPulls}} {{.i18n.Tr "repo.pulls"}} {{.Repository.NumOpenPulls}} diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 985779fae3..977d841cf5 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -117,15 +117,17 @@

{{.i18n.Tr "repo.settings.tracker_url_format_desc" | Str2html}}

-
+ {{if .Repository.CanEnablePulls}} +
-
- -
- - +
+ +
+ + +
-
+ {{end}}
From a1b28fc33c4a685ffe9a07f67fa6786ec27524bb Mon Sep 17 00:00:00 2001 From: Download-Fritz Date: Fri, 19 Feb 2016 20:48:32 +0100 Subject: [PATCH 2/2] Rename MustEnablePulls() to MustAllowPulls() and simplify the contained check to AllowsPulls(). --- cmd/web.go | 4 ++-- routers/repo/issue.go | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cmd/web.go b/cmd/web.go index 5bfbdb4495..072d31917a 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -470,7 +470,7 @@ func runWeb(ctx *cli.Context) { m.Post("/delete", repo.DeleteRelease) }, reqRepoAdmin, middleware.RepoRef()) - m.Combo("/compare/*", repo.MustEnablePulls).Get(repo.CompareAndPullRequest). + m.Combo("/compare/*", repo.MustAllowPulls).Get(repo.CompareAndPullRequest). Post(bindIgnErr(auth.CreateIssueForm{}), repo.CompareAndPullRequestPost) }, reqSignIn, middleware.RepoAssignment(), repo.MustBeNotBare) @@ -503,7 +503,7 @@ func runWeb(ctx *cli.Context) { m.Get("/commits", middleware.RepoRef(), repo.ViewPullCommits) m.Get("/files", middleware.RepoRef(), repo.ViewPullFiles) m.Post("/merge", reqRepoAdmin, repo.MergePullRequest) - }, repo.MustEnablePulls) + }, repo.MustAllowPulls) m.Group("", func() { m.Get("/src/*", repo.Home) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 76822eb05e..400da72029 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -47,11 +47,9 @@ func MustEnableIssues(ctx *middleware.Context) { } } -func MustEnablePulls(ctx *middleware.Context) { - if !ctx.Repo.Repository.CanEnablePulls() { - ctx.Handle(404, "Unsupported", nil) - } else if !ctx.Repo.Repository.EnablePulls { - ctx.Handle(404, "MustEnablePulls", nil) +func MustAllowPulls(ctx *middleware.Context) { + if !ctx.Repo.Repository.AllowsPulls() { + ctx.Handle(404, "MustAllowPulls", nil) } ctx.Data["HasForkedRepo"] = ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID) @@ -73,7 +71,7 @@ func RetrieveLabels(ctx *middleware.Context) { func Issues(ctx *middleware.Context) { isPullList := ctx.Params(":type") == "pulls" if isPullList { - MustEnablePulls(ctx) + MustAllowPulls(ctx) if ctx.Written() { return }