diff options
author | Download-Fritz <download-fritz@outlook.com> | 2016-02-19 20:33:06 +0100 |
---|---|---|
committer | Download-Fritz <download-fritz@outlook.com> | 2016-02-19 20:33:06 +0100 |
commit | a467184e13e4e3867031c191263dc0adaec2673c (patch) | |
tree | e01e62d7085e72e4a8f02142c1a5fe3571e56c4d | |
parent | 2fdf8fc938295b95cbe6efb7cddb1b87c2fb81ee (diff) | |
download | gitea-a467184e13e4e3867031c191263dc0adaec2673c.tar.gz gitea-a467184e13e4e3867031c191263dc0adaec2673c.zip |
#2505 Allow to fork and disallow to create PRs for mirrors.
-rw-r--r-- | models/repo.go | 12 | ||||
-rw-r--r-- | modules/middleware/repo.go | 2 | ||||
-rw-r--r-- | routers/repo/issue.go | 4 | ||||
-rw-r--r-- | templates/repo/header.tmpl | 2 | ||||
-rw-r--r-- | 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 @@ <i class="icon octicon octicon-issue-opened"></i> {{.i18n.Tr "repo.issues"}} <span class="ui {{if not .Repository.NumOpenIssues}}gray{{else}}blue{{end}} small label">{{.Repository.NumOpenIssues}}</span> </a> {{end}} - {{if .Repository.EnablePulls}} + {{if .Repository.AllowsPulls}} <a class="{{if .PageIsPullList}}active{{end}} item" href="{{.RepoLink}}/pulls"> <i class="icon octicon octicon-git-pull-request"></i> {{.i18n.Tr "repo.pulls"}} <span class="ui {{if not .Repository.NumOpenPulls}}gray{{else}}blue{{end}} small label">{{.Repository.NumOpenPulls}}</span> </a> 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 @@ <p class="help">{{.i18n.Tr "repo.settings.tracker_url_format_desc" | Str2html}}</p> </div> - <div class="ui divider"></div> + {{if .Repository.CanEnablePulls}} + <div class="ui divider"></div> - <div class="inline field"> - <label>{{.i18n.Tr "repo.pulls"}}</label> - <div class="ui checkbox"> - <input name="enable_pulls" type="checkbox" {{if .Repository.EnablePulls}}checked{{end}}> - <label>{{.i18n.Tr "repo.settings.pulls_desc"}}</label> + <div class="inline field"> + <label>{{.i18n.Tr "repo.pulls"}}</label> + <div class="ui checkbox"> + <input name="enable_pulls" type="checkbox" {{if .Repository.EnablePulls}}checked{{end}}> + <label>{{.i18n.Tr "repo.settings.pulls_desc"}}</label> + </div> </div> - </div> + {{end}} <div class="ui divider"></div> <div class="field"> |