Skip to content

Commit 906514e

Browse files
splitt3rCalK16
authored andcommitted
Check pr creator permissions
1 parent 452828a commit 906514e

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

routers/web/repo/issue.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,8 +1225,9 @@ func ValidateRepoMetas(ctx *context.Context, form forms.CreateIssueForm, isPull
12251225
return nil, nil, nil, 0, 0
12261226
}
12271227

1228-
// Check if the passed reviewers actually exist
1228+
// Check if the passed reviewers (user/team) actually exist
12291229
for _, rID := range reviewerIDs {
1230+
// negative reviewIDs represent team requests
12301231
if rID < 0 {
12311232
_, err := organization.GetTeamByID(ctx, -rID)
12321233
if err != nil {

routers/web/repo/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ func CompareAndPullRequestPost(ctx *context.Context) {
12681268
return
12691269
}
12701270

1271-
labelIDs, assigneeIDs, reviewerIDs, milestoneID, _ := ValidateRepoMetas(ctx, *form, true)
1271+
labelIDs, assigneeIDs, reviewerIDs, milestoneID, projectID := ValidateRepoMetas(ctx, *form, true)
12721272
if ctx.Written() {
12731273
return
12741274
}

services/pull/pull.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func getPullWorkingLockKey(prID int64) string {
4343
}
4444

4545
// NewPullRequest creates new pull request with labels for repository.
46-
func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *issues_model.Issue, labelIDs []int64, uuids []string, pr *issues_model.PullRequest, assigneeIDs []int64, reviewerIDs []int64) error {
46+
func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *issues_model.Issue, labelIDs []int64, uuids []string, pr *issues_model.PullRequest, assigneeIDs, reviewerIDs []int64) error {
4747
if err := issue.LoadPoster(ctx); err != nil {
4848
return err
4949
}
@@ -118,11 +118,16 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *iss
118118
}
119119

120120
for _, reviewerID := range reviewerIDs {
121+
// negative reviewIDs represent team requests
121122
if reviewerID < 0 {
122123
team, err := organization.GetTeamByID(ctx, -reviewerID)
123124
if err != nil {
124125
return err
125126
}
127+
err = issue_service.IsValidTeamReviewRequest(ctx, team, issue.Poster, true, issue)
128+
if err != nil {
129+
return err
130+
}
126131
_, err = issue_service.TeamReviewRequest(ctx, issue, issue.Poster, team, true)
127132
if err != nil {
128133
return err
@@ -134,6 +139,14 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *iss
134139
if err != nil {
135140
return err
136141
}
142+
permDoer, err := access_model.GetUserRepoPermission(ctx, issue.Repo, issue.Poster)
143+
if err != nil {
144+
return err
145+
}
146+
err = issue_service.IsValidReviewRequest(ctx, reviewer, issue.Poster, true, issue, &permDoer)
147+
if err != nil {
148+
return err
149+
}
137150
_, err = issue_service.ReviewRequest(ctx, issue, issue.Poster, reviewer, true)
138151
if err != nil {
139152
return err

templates/repo/issue/new_form.tmpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@
6969
{{ctx.AvatarUtils.Avatar .User 28 "gt-mr-3"}}{{template "repo/search_name" .User}}
7070
</span>
7171
</a>
72-
{{else if .Team}}
72+
{{end}}
73+
{{end}}
74+
<div class="divider"></div>
75+
{{range .Reviewers}}
76+
{{if .Team}}
7377
<a class="item muted" data-id="{{.ItemID}}" data-id-selector="#reviewer_{{.ItemID}}">
7478
<span class="octicon-check invisible">{{svg "octicon-check" 16}}</span>
7579
<span class="text">

0 commit comments

Comments
 (0)