]> source.dussan.org Git - gitea.git/commitdiff
Fix 500 when review pull request with anonymous (#17594)
authorLunny Xiao <xiaolunwen@gmail.com>
Tue, 9 Nov 2021 13:14:12 +0000 (21:14 +0800)
committerGitHub <noreply@github.com>
Tue, 9 Nov 2021 13:14:12 +0000 (13:14 +0000)
routers/web/repo/issue.go

index 8f09f95172ba490d3bc8a692656a38b38562a697..2782e8d62990bdc56ac87fac0d920ef69f128086 100644 (file)
@@ -1545,6 +1545,10 @@ func ViewIssue(ctx *context.Context) {
                }
                ctx.Data["ShowMergeInstructions"] = true
                if pull.ProtectedBranch != nil {
+                       var showMergeInstructions bool
+                       if ctx.User != nil {
+                               showMergeInstructions = pull.ProtectedBranch.CanUserPush(ctx.User.ID)
+                       }
                        cnt := pull.ProtectedBranch.GetGrantedApprovalsCount(pull)
                        ctx.Data["IsBlockedByApprovals"] = !pull.ProtectedBranch.HasEnoughApprovals(pull)
                        ctx.Data["IsBlockedByRejection"] = pull.ProtectedBranch.MergeBlockedByRejectedReview(pull)
@@ -1555,7 +1559,7 @@ func ViewIssue(ctx *context.Context) {
                        ctx.Data["ChangedProtectedFiles"] = pull.ChangedProtectedFiles
                        ctx.Data["IsBlockedByChangedProtectedFiles"] = len(pull.ChangedProtectedFiles) != 0
                        ctx.Data["ChangedProtectedFilesNum"] = len(pull.ChangedProtectedFiles)
-                       ctx.Data["ShowMergeInstructions"] = pull.ProtectedBranch.CanUserPush(ctx.User.ID)
+                       ctx.Data["ShowMergeInstructions"] = showMergeInstructions
                }
                ctx.Data["WillSign"] = false
                if ctx.User != nil {