Skip to content

Commit 69291c7

Browse files
committed
routers: make /compare route available to unauthenticated users
Remove some bits of the compare interface if the user isn't signed in. Notably, they don't need to see the "New Pull Request" button box nor the hidden form that would fail to submit due to the POST request continuing to require proper privileges. Follow-up commits will improve the UI a bit around this, removing some "Pull Request" verbiage in favor of "Compare."
1 parent 940ed92 commit 69291c7

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

routers/routes/routes.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,9 @@ func RegisterRoutes(m *macaron.Macaron) {
709709
m.Group("/milestone", func() {
710710
m.Get("/:id", repo.MilestoneIssuesAndPulls)
711711
}, reqRepoIssuesOrPullsReader, context.RepoRef())
712+
m.Combo("/compare/*", repo.MustBeNotEmpty, reqRepoCodeReader, repo.SetEditorconfigIfExists).
713+
Get(repo.SetDiffViewStyle, repo.CompareDiff).
714+
Post(reqSignIn, context.RepoMustNotBeArchived(), reqRepoPullsReader, repo.MustAllowPulls, bindIgnErr(auth.CreateIssueForm{}), repo.CompareAndPullRequestPost)
712715
}, context.RepoAssignment(), context.UnitTypes())
713716

714717
// Grouping for those endpoints that do require authentication
@@ -769,9 +772,6 @@ func RegisterRoutes(m *macaron.Macaron) {
769772
m.Post("/:id/:action", repo.ChangeMilestonStatus)
770773
m.Post("/delete", repo.DeleteMilestone)
771774
}, context.RepoMustNotBeArchived(), reqRepoIssuesOrPullsWriter, context.RepoRef())
772-
m.Combo("/compare/*", repo.MustBeNotEmpty, reqRepoCodeReader, repo.SetEditorconfigIfExists).
773-
Get(repo.SetDiffViewStyle, repo.CompareDiff).
774-
Post(context.RepoMustNotBeArchived(), reqRepoPullsReader, repo.MustAllowPulls, bindIgnErr(auth.CreateIssueForm{}), repo.CompareAndPullRequestPost)
775775
m.Group("/pull", func() {
776776
m.Post("/:index/target_branch", repo.UpdatePullRequestTarget)
777777
}, context.RepoMustNotBeArchived())

templates/repo/diff/compare.tmpl

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
{{if .PageIsComparePull}}
77
<h2 class="ui header">
8-
{{if not .Repository.IsArchived}}
8+
{{if and $.IsSigned (not .Repository.IsArchived)}}
99
{{.i18n.Tr "repo.pulls.compare_changes"}}
1010
<div class="sub header">{{.i18n.Tr "repo.pulls.compare_changes_desc"}}</div>
1111
{{ else }}
@@ -64,22 +64,24 @@
6464
<div class="ui segment">
6565
{{.i18n.Tr "repo.pulls.has_pull_request" $.RepoLink $.RepoRelPath .PullRequest.Index | Safe}}
6666
</div>
67-
{{else}}
68-
{{if not .Repository.IsArchived}}
69-
<div class="ui info message show-form-container">
70-
<button class="ui button green show-form">{{.i18n.Tr "repo.pulls.new"}}</button>
71-
</div>
72-
{{ else }}
73-
<div class="ui warning message">
74-
{{.i18n.Tr "repo.archive.title"}}
75-
</div>
76-
{{ end }}
77-
<div class="pullrequest-form" style="display: none">
78-
{{template "repo/issue/new_form" .}}
79-
</div>
80-
{{template "repo/commits_table" .}}
81-
{{template "repo/diff/box" .}}
82-
{{end}}
67+
{{else}}
68+
{{if and $.IsSigned (not .Repository.IsArchived)}}
69+
<div class="ui info message show-form-container">
70+
<button class="ui button green show-form">{{.i18n.Tr "repo.pulls.new"}}</button>
71+
</div>
72+
{{else if .Repository.IsArchived}}
73+
<div class="ui warning message">
74+
{{.i18n.Tr "repo.archive.title"}}
75+
</div>
76+
{{end}}
77+
{{if $.IsSigned}}
78+
<div class="pullrequest-form" style="display: none">
79+
{{template "repo/issue/new_form" .}}
80+
</div>
81+
{{end}}
82+
{{template "repo/commits_table" .}}
83+
{{template "repo/diff/box" .}}
84+
{{end}}
8385
{{else}}
8486
{{template "repo/commits_table" .}}
8587
{{template "repo/diff/box" .}}

0 commit comments

Comments
 (0)