From ac4dd80935d9895782e18f65ef7e474eef44f633 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Mon, 5 Sep 2022 15:10:29 +0800 Subject: [PATCH 1/2] feat: poster can choose reviewer --- routers/web/repo/issue.go | 15 ++++++++++----- services/issue/assignee.go | 5 ++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 06e003bff282d..c4a3e34be6d24 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 aefd8cff9a7fb..d594f409ecea0 100644 --- a/services/issue/assignee.go +++ b/services/issue/assignee.go @@ -132,6 +132,9 @@ func IsValidReviewRequest(ctx context.Context, reviewer, doer *user_model.User, } pemResult = permDoer.CanAccessAny(perm.AccessModeWrite, unit.TypePullRequests) + if !pemResult { + pemResult = doer.ID == issue.PosterID + } 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) From 1d6aea1f8c4857d051679ddc4aaf5ad44ea56ed7 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Tue, 6 Sep 2022 21:06:58 +0800 Subject: [PATCH 2/2] fix: adjust the order of judgment --- services/issue/assignee.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/issue/assignee.go b/services/issue/assignee.go index d594f409ecea0..e24f8500c9ae2 100644 --- a/services/issue/assignee.go +++ b/services/issue/assignee.go @@ -131,9 +131,9 @@ 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 = doer.ID == issue.PosterID + pemResult = permDoer.CanAccessAny(perm.AccessModeWrite, unit.TypePullRequests) } if !pemResult { pemResult, err = issues_model.IsOfficialReviewer(ctx, issue, doer)