From 831e981357dc24e45383b7d495227011a7b8f23e Mon Sep 17 00:00:00 2001 From: Jason Song Date: Sat, 10 Sep 2022 01:27:47 +0800 Subject: [PATCH] Allow poster to choose reviewers (#21084) Allow the poster of a PR to choose reviewers (add only). Solve #20746 --- routers/web/repo/issue.go | 15 ++++++++++----- services/issue/assignee.go | 7 +++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 592f7eac8..5dab770d5 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -1336,11 +1336,16 @@ func ViewIssue(ctx *context.Context) { if issue.IsPull { canChooseReviewer := ctx.Repo.CanWrite(unit.TypePullRequests) - if !canChooseReviewer && ctx.Doer != nil && ctx.IsSigned { - canChooseReviewer, err = issues_model.IsOfficialReviewer(ctx, issue, ctx.Doer) - if err != nil { - ctx.ServerError("IsOfficialReviewer", err) - return + if ctx.Doer != nil && ctx.IsSigned { + if !canChooseReviewer { + canChooseReviewer = ctx.Doer.ID == issue.PosterID + } + if !canChooseReviewer { + canChooseReviewer, err = issues_model.IsOfficialReviewer(ctx, issue, ctx.Doer) + if err != nil { + ctx.ServerError("IsOfficialReviewer", err) + return + } } } diff --git a/services/issue/assignee.go b/services/issue/assignee.go index aefd8cff9..e24f8500c 100644 --- a/services/issue/assignee.go +++ b/services/issue/assignee.go @@ -131,7 +131,10 @@ func IsValidReviewRequest(ctx context.Context, reviewer, doer *user_model.User, return nil } - pemResult = permDoer.CanAccessAny(perm.AccessModeWrite, unit.TypePullRequests) + pemResult = doer.ID == issue.PosterID + if !pemResult { + pemResult = permDoer.CanAccessAny(perm.AccessModeWrite, unit.TypePullRequests) + } if !pemResult { pemResult, err = issues_model.IsOfficialReviewer(ctx, issue, doer) if err != nil { @@ -201,7 +204,7 @@ func IsValidTeamReviewRequest(ctx context.Context, reviewer *organization.Team, } doerCanWrite := permission.CanAccessAny(perm.AccessModeWrite, unit.TypePullRequests) - if !doerCanWrite { + if !doerCanWrite && doer.ID != issue.PosterID { official, err := issues_model.IsOfficialReviewer(ctx, issue, doer) if err != nil { log.Error("Unable to Check if IsOfficialReviewer for %-v in %-v#%d", doer, issue.Repo, issue.Index)