diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index ad4d3da294..7c67d614f6 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -1390,6 +1390,7 @@ func CompareAndPullRequestPost(ctx *context.Context) { AssigneeIDs: assigneeIDs, Reviewers: validateRet.Reviewers, TeamReviewers: validateRet.TeamReviewers, + ProjectID: projectID, } if err := pull_service.NewPullRequest(ctx, prOpts); err != nil { switch { @@ -1441,15 +1442,6 @@ func CompareAndPullRequestPost(ctx *context.Context) { return } - if projectID > 0 && ctx.Repo.CanWrite(unit.TypeProjects) { - if err := issues_model.IssueAssignOrRemoveProject(ctx, pullIssue, ctx.Doer, projectID, 0); err != nil { - if !errors.Is(err, util.ErrPermissionDenied) { - ctx.ServerError("IssueAssignOrRemoveProject", err) - return - } - } - } - log.Trace("Pull request created: %d/%d", repo.ID, pullIssue.ID) ctx.JSONRedirect(pullIssue.Link()) } diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index 2d33d2b42b..e4545570c8 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -405,13 +405,6 @@ func (f *NewPackagistHookForm) Validate(req *http.Request, errs binding.Errors) return middleware.Validate(errs, ctx.Data, f, ctx.Locale) } -// .___ -// | | ______ ________ __ ____ -// | |/ ___// ___/ | \_/ __ \ -// | |\___ \ \___ \| | /\ ___/ -// |___/____ >____ >____/ \___ > -// \/ \/ \/ - // CreateIssueForm form for creating issue type CreateIssueForm struct { Title string `binding:"Required;MaxSize(255)"` diff --git a/services/pull/pull.go b/services/pull/pull.go index f8f64dd650..7038285bd1 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -52,6 +52,7 @@ type NewPullRequestOptions struct { AssigneeIDs []int64 Reviewers []*user_model.User TeamReviewers []*organization.Team + ProjectID int64 } // NewPullRequest creates new pull request with labels for repository. @@ -67,11 +68,13 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error { // user should be a collaborator or a member of the organization for base repo canCreate := issue.Poster.IsAdmin || pr.Flow == issues_model.PullRequestFlowAGit + canAssignProject := canCreate if !canCreate { canCreate, err := repo_model.IsOwnerMemberCollaborator(ctx, repo, issue.Poster.ID) if err != nil { return err } + canAssignProject = canCreate if !canCreate { // or user should have write permission in the head repo @@ -85,6 +88,7 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error { if !perm.CanWrite(unit.TypeCode) { return issues_model.ErrMustCollaborator } + canAssignProject = perm.CanWrite(unit.TypeProjects) } } @@ -117,6 +121,12 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error { assigneeCommentMap[assigneeID] = comment } + if opts.ProjectID > 0 && canAssignProject { + if err := issues_model.IssueAssignOrRemoveProject(ctx, issue, issue.Poster, opts.ProjectID, 0); err != nil { + return err + } + } + pr.Issue = issue issue.PullRequest = pr