Skip to content

Commit 5242e52

Browse files
authored
Make owner/repo/pulls handlers use "PR reader" permission (#32254)
Fix #32253 (partially)
1 parent c4b2808 commit 5242e52

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

routers/web/web.go

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,35 @@ func registerRoutes(m *web.Router) {
14611461
)
14621462
// end "/{username}/{reponame}/activity"
14631463

1464+
m.Group("/{username}/{reponame}", func() {
1465+
m.Group("/pulls/{index}", func() {
1466+
m.Get("", repo.SetWhitespaceBehavior, repo.GetPullDiffStats, repo.ViewIssue)
1467+
m.Get(".diff", repo.DownloadPullDiff)
1468+
m.Get(".patch", repo.DownloadPullPatch)
1469+
m.Group("/commits", func() {
1470+
m.Get("", context.RepoRef(), repo.SetWhitespaceBehavior, repo.GetPullDiffStats, repo.ViewPullCommits)
1471+
m.Get("/list", context.RepoRef(), repo.GetPullCommits)
1472+
m.Get("/{sha:[a-f0-9]{7,40}}", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesForSingleCommit)
1473+
})
1474+
m.Post("/merge", context.RepoMustNotBeArchived(), web.Bind(forms.MergePullRequestForm{}), repo.MergePullRequest)
1475+
m.Post("/cancel_auto_merge", context.RepoMustNotBeArchived(), repo.CancelAutoMergePullRequest)
1476+
m.Post("/update", repo.UpdatePullRequest)
1477+
m.Post("/set_allow_maintainer_edit", web.Bind(forms.UpdateAllowEditsForm{}), repo.SetAllowEdits)
1478+
m.Post("/cleanup", context.RepoMustNotBeArchived(), context.RepoRef(), repo.CleanUpPullRequest)
1479+
m.Group("/files", func() {
1480+
m.Get("", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesForAllCommitsOfPr)
1481+
m.Get("/{sha:[a-f0-9]{7,40}}", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesStartingFromCommit)
1482+
m.Get("/{shaFrom:[a-f0-9]{7,40}}..{shaTo:[a-f0-9]{7,40}}", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesForRange)
1483+
m.Group("/reviews", func() {
1484+
m.Get("/new_comment", repo.RenderNewCodeCommentForm)
1485+
m.Post("/comments", web.Bind(forms.CodeCommentForm{}), repo.SetShowOutdatedComments, repo.CreateCodeComment)
1486+
m.Post("/submit", web.Bind(forms.SubmitReviewForm{}), repo.SubmitReview)
1487+
}, context.RepoMustNotBeArchived())
1488+
})
1489+
})
1490+
}, ignSignIn, context.RepoAssignment, repo.MustAllowPulls, reqRepoPullsReader)
1491+
// end "/{username}/{reponame}/pulls/{index}": repo pull request
1492+
14641493
m.Group("/{username}/{reponame}", func() {
14651494
m.Group("/activity_author_data", func() {
14661495
m.Get("", repo.ActivityAuthors)
@@ -1499,32 +1528,6 @@ func registerRoutes(m *web.Router) {
14991528
return cancel
15001529
})
15011530

1502-
m.Group("/pulls/{index}", func() {
1503-
m.Get("", repo.SetWhitespaceBehavior, repo.GetPullDiffStats, repo.ViewIssue)
1504-
m.Get(".diff", repo.DownloadPullDiff)
1505-
m.Get(".patch", repo.DownloadPullPatch)
1506-
m.Group("/commits", func() {
1507-
m.Get("", context.RepoRef(), repo.SetWhitespaceBehavior, repo.GetPullDiffStats, repo.ViewPullCommits)
1508-
m.Get("/list", context.RepoRef(), repo.GetPullCommits)
1509-
m.Get("/{sha:[a-f0-9]{7,40}}", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesForSingleCommit)
1510-
})
1511-
m.Post("/merge", context.RepoMustNotBeArchived(), web.Bind(forms.MergePullRequestForm{}), repo.MergePullRequest)
1512-
m.Post("/cancel_auto_merge", context.RepoMustNotBeArchived(), repo.CancelAutoMergePullRequest)
1513-
m.Post("/update", repo.UpdatePullRequest)
1514-
m.Post("/set_allow_maintainer_edit", web.Bind(forms.UpdateAllowEditsForm{}), repo.SetAllowEdits)
1515-
m.Post("/cleanup", context.RepoMustNotBeArchived(), context.RepoRef(), repo.CleanUpPullRequest)
1516-
m.Group("/files", func() {
1517-
m.Get("", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesForAllCommitsOfPr)
1518-
m.Get("/{sha:[a-f0-9]{7,40}}", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesStartingFromCommit)
1519-
m.Get("/{shaFrom:[a-f0-9]{7,40}}..{shaTo:[a-f0-9]{7,40}}", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesForRange)
1520-
m.Group("/reviews", func() {
1521-
m.Get("/new_comment", repo.RenderNewCodeCommentForm)
1522-
m.Post("/comments", web.Bind(forms.CodeCommentForm{}), repo.SetShowOutdatedComments, repo.CreateCodeComment)
1523-
m.Post("/submit", web.Bind(forms.SubmitReviewForm{}), repo.SubmitReview)
1524-
}, context.RepoMustNotBeArchived())
1525-
})
1526-
}, repo.MustAllowPulls)
1527-
15281531
m.Group("/media", func() {
15291532
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.SingleDownloadOrLFS)
15301533
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.SingleDownloadOrLFS)

0 commit comments

Comments
 (0)