Skip to content

Commit

Permalink
move GetPerm to IsUserAllowedToUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 committed Jan 16, 2020
1 parent 88fa4c5 commit 7776738
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
8 changes: 1 addition & 7 deletions routers/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,13 +620,7 @@ func UpdatePullRequest(ctx *context.Context) {
return
}

headRepoPerm, err := models.GetUserRepoPermission(issue.PullRequest.HeadRepo, ctx.User)
if err != nil {
ctx.ServerError("GetUserRepoPermission", err)
return
}

allowedUpdate, err := pull_service.IsUserAllowedToUpdate(issue.PullRequest, headRepoPerm, ctx.User)
allowedUpdate, err := pull_service.IsUserAllowedToUpdate(issue.PullRequest, ctx.User)
if err != nil {
ctx.ServerError("IsUserAllowedToMerge", err)
return
Expand Down
9 changes: 7 additions & 2 deletions services/pull/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,19 @@ func Update(pull *models.PullRequest, doer *models.User, message string) (err er
}

// IsUserAllowedToUpdate check if user is allowed to update PR with given permissions and branch protections
func IsUserAllowedToUpdate(pull *models.PullRequest, p models.Permission, user *models.User) (bool, error) {
func IsUserAllowedToUpdate(pull *models.PullRequest, user *models.User) (bool, error) {
headRepoPerm, err := models.GetUserRepoPermission(pull.HeadRepo, user)
if err != nil {
return false, err
}

pr := &models.PullRequest{
HeadRepoID: pull.BaseRepoID,
BaseRepoID: pull.HeadRepoID,
HeadBranch: pull.BaseBranch,
BaseBranch: pull.HeadBranch,
}
return IsUserAllowedToMerge(pr, p, user)
return IsUserAllowedToMerge(pr, headRepoPerm, user)
}

// GetDiverging determines how many commits a PR is ahead or behind the PR base branch
Expand Down

0 comments on commit 7776738

Please sign in to comment.