From 5558fcf2bbde14c28112fe9976bd5ab9d00c39bf Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 20 Oct 2023 17:55:05 +0200 Subject: [PATCH 1/3] Allow pull requests Manually Merged option to be used by non-admins Currently this feature is only available to admins. but there is no clear reason why. If a user can merge pull requests, then doing this should be fine as well. --- routers/web/repo/issue.go | 2 +- templates/repo/issue/view_content/pull.tmpl | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 96fce4887821..10e3b5f5a25b 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -1927,7 +1927,7 @@ func ViewIssue(ctx *context.Context) { if pull.CanAutoMerge() || pull.IsWorkInProgress(ctx) || pull.IsChecking() { return false } - if (ctx.Doer.IsAdmin || ctx.Repo.IsAdmin()) && prConfig.AllowManualMerge { + if ctx.Repo.CanWrite(unit.TypeCode) && prConfig.AllowManualMerge { return true } diff --git a/templates/repo/issue/view_content/pull.tmpl b/templates/repo/issue/view_content/pull.tmpl index a4f7ede74d06..0bc9a567e976 100644 --- a/templates/repo/issue/view_content/pull.tmpl +++ b/templates/repo/issue/view_content/pull.tmpl @@ -263,7 +263,7 @@ }, { 'name': 'manually-merged', - 'allowed': {{and $prUnit.PullRequestsConfig.AllowManualMerge $.IsRepoAdmin}}, + 'allowed': {{and $prUnit.PullRequestsConfig.AllowManualMerge}}, 'textDoMerge': {{ctx.Locale.Tr "repo.pulls.merge_manually"}}, 'hideMergeMessageTexts': true, 'hideAutoMerge': true, @@ -349,13 +349,13 @@ {{end}}{{/* end if: pull request status */}} {{/* - Manually Merged is not a well-known feature, it helps repo admins to mark a non-mergeable PR (already merged, conflicted) as merged + Manually Merged is not a well-known feature, it is used to mark a non-mergeable PR (already merged, conflicted) as merged To test it: * Enable "Manually Merged" feature in the Repository Settings * Create a pull request, either: * - Merge the pull request branch locally and push the merged commit to Gitea * - Make some conflicts between the base branch and the pull request branch - * Then the Manually Merged form will be shown to repo admin users + * Then the Manually Merged form will be shown in the merge form */}} {{if and $.StillCanManualMerge (not $showGeneralMergeForm)}}
From a2d2629900116753873d1b96be2ef13d304e01f5 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 24 Oct 2023 23:10:47 +0200 Subject: [PATCH 2/3] Remove unneeded and Co-authored-by: delvh --- templates/repo/issue/view_content/pull.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/issue/view_content/pull.tmpl b/templates/repo/issue/view_content/pull.tmpl index 0bc9a567e976..9396a9fc3b9b 100644 --- a/templates/repo/issue/view_content/pull.tmpl +++ b/templates/repo/issue/view_content/pull.tmpl @@ -263,7 +263,7 @@ }, { 'name': 'manually-merged', - 'allowed': {{and $prUnit.PullRequestsConfig.AllowManualMerge}}, + 'allowed': {{$prUnit.PullRequestsConfig.AllowManualMerge}}, 'textDoMerge': {{ctx.Locale.Tr "repo.pulls.merge_manually"}}, 'hideMergeMessageTexts': true, 'hideAutoMerge': true, From 67cbeda71a5e5937b67d8a14485cc6bb1086448a Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 25 Oct 2023 16:23:59 +0200 Subject: [PATCH 3/3] Fix missing permission check for protected branches --- routers/web/repo/issue.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 10e3b5f5a25b..94300da86833 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -1773,7 +1773,7 @@ func ViewIssue(ctx *context.Context) { pull := issue.PullRequest pull.Issue = issue canDelete := false - ctx.Data["AllowMerge"] = false + allowMerge := false if ctx.IsSigned { if err := pull.LoadHeadRepo(ctx); err != nil { @@ -1806,7 +1806,7 @@ func ViewIssue(ctx *context.Context) { ctx.ServerError("GetUserRepoPermission", err) return } - ctx.Data["AllowMerge"], err = pull_service.IsUserAllowedToMerge(ctx, pull, perm, ctx.Doer) + allowMerge, err = pull_service.IsUserAllowedToMerge(ctx, pull, perm, ctx.Doer) if err != nil { ctx.ServerError("IsUserAllowedToMerge", err) return @@ -1818,6 +1818,8 @@ func ViewIssue(ctx *context.Context) { } } + ctx.Data["AllowMerge"] = allowMerge + prUnit, err := repo.GetUnit(ctx, unit.TypePullRequests) if err != nil { ctx.ServerError("GetUnit", err) @@ -1927,7 +1929,7 @@ func ViewIssue(ctx *context.Context) { if pull.CanAutoMerge() || pull.IsWorkInProgress(ctx) || pull.IsChecking() { return false } - if ctx.Repo.CanWrite(unit.TypeCode) && prConfig.AllowManualMerge { + if allowMerge && prConfig.AllowManualMerge { return true }