This commit is contained in:
hiifong 2025-01-09 22:51:27 +08:00
parent cab9bbccf2
commit 35a2b9b3a5
No known key found for this signature in database
GPG Key ID: 0814559E2F97194D
2 changed files with 13 additions and 8 deletions

View File

@ -4,6 +4,7 @@
package private
import (
"errors"
"fmt"
"net/http"
"os"
@ -472,24 +473,27 @@ func preReceiveFor(ctx *preReceiveContext, refFullName git.RefName) {
}
}
func canUpdateAgitPull(ctx *preReceiveContext, pull *issues_model.PullRequest) bool {
func canUpdateAgitPull(ctx *preReceiveContext, pull *issues_model.PullRequest) error {
if pull.Flow != issues_model.PullRequestFlowAGit {
return false
return errors.New("Pull request that are not created through agit cannot be updated using agit")
}
if ctx.opts.UserID == pull.Issue.PosterID {
return true
return nil
}
if !pull.AllowMaintainerEdit {
return false
return fmt.Errorf("The author does not allow maintainers to edit this pull request")
}
if !ctx.loadPusherAndPermission() {
return false
return fmt.Errorf("Internal Server Error (no specific error)")
}
return ctx.userPerm.CanWrite(unit.TypeCode)
if ctx.userPerm.CanWrite(unit.TypeCode) {
return errors.New("You have no permission to update this pull request")
}
return nil
}
func preReceiveForReview(ctx *preReceiveContext, refFullName git.RefName) {
@ -535,9 +539,9 @@ func preReceiveForReview(ctx *preReceiveContext, refFullName git.RefName) {
return
}
if !canUpdateAgitPull(ctx, pull) {
if err := canUpdateAgitPull(ctx, pull); err != nil {
ctx.JSON(http.StatusForbidden, private.Response{
UserMsg: "Unknow pull request.",
UserMsg: err.Error(),
})
return
}

View File

@ -137,6 +137,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
})
continue
}
log.Trace("Pull request index: %d", pullIndex)
pull, err := issues_model.GetPullRequestByIndex(ctx, repo.ID, pullIndex)
if err != nil {
results = append(results, private.HookProcReceiveRefResult{