diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go index 483598d558..b0116726b7 100644 --- a/routers/web/repo/projects.go +++ b/routers/web/repo/projects.go @@ -36,11 +36,6 @@ const ( tplProjectsView templates.TplName = "repo/projects/view" ) -type projectColumnInfo struct { - ID int64 `json:"id"` - Title string `json:"title"` -} - // MustEnableRepoProjects check if repo projects are enabled in settings func MustEnableRepoProjects(ctx *context.Context) { if unit.TypeProjects.UnitGlobalDisabled() { @@ -465,96 +460,39 @@ func UpdateIssueProject(ctx *context.Context) { return } } - - result := map[string]any{"ok": true} - if projectID > 0 { - project, err := project_model.GetProjectByID(ctx, projectID) - if err != nil { - ctx.ServerError("GetProjectByID", err) - return - } - columns, err := project.GetColumns(ctx) - if err != nil { - ctx.ServerError("GetProjectColumns", err) - return - } - cols := make([]projectColumnInfo, 0, len(columns)) - for _, c := range columns { - cols = append(cols, projectColumnInfo{ID: c.ID, Title: c.Title}) - } - // The issue was assigned to the default column - var selectedColumnID int64 - if len(issues) > 0 { - selectedColumnID, err = issues[0].ProjectColumnID(ctx) - if err != nil { - ctx.ServerError("ProjectColumnID", err) - return - } - if selectedColumnID == 0 { - defaultColumn, err := project.MustDefaultColumn(ctx) - if err != nil { - ctx.ServerError("MustDefaultColumn", err) - return - } - selectedColumnID = defaultColumn.ID - } - } - result["columns"] = cols - result["selected_column_id"] = selectedColumnID - } else { - result["columns"] = []projectColumnInfo{} - result["selected_column_id"] = 0 - } - ctx.JSON(http.StatusOK, result) + ctx.JSONOK() } -// UpdateIssueProjectColumn moves an issue to a different column within its current project -func UpdateIssueProjectColumn(ctx *context.Context) { - issueID := ctx.FormInt64("issue_id") - columnID := ctx.FormInt64("id") - - issue, err := issues_model.GetIssueByID(ctx, issueID) - if err != nil { - if issues_model.IsErrIssueNotExist(err) { - ctx.NotFound(nil) - return - } - ctx.ServerError("GetIssueByID", err) +// UpdateIssueProjectSetColumn moves an issue to a different column within its current project +func UpdateIssueProjectSetColumn(ctx *context.Context) { + issues := getActionIssues(ctx) + if ctx.Written() { return } - if issue.RepoID != ctx.Repo.Repository.ID { + + if err := issues.LoadProjects(ctx); err != nil { + ctx.ServerError("LoadProjects", err) + return + } + + column, err := project_model.GetColumn(ctx, ctx.FormInt64("id")) + if errors.Is(err, util.ErrNotExist) { ctx.NotFound(nil) return - } - - if err := issue.LoadProject(ctx); err != nil { - ctx.ServerError("LoadProject", err) - return - } - if issue.Project == nil { - ctx.NotFound(nil) - return - } - - column, err := project_model.GetColumn(ctx, columnID) - if err != nil { - if project_model.IsErrProjectColumnNotExist(err) { - ctx.NotFound(nil) - return - } + } else if err != nil { ctx.ServerError("GetColumn", err) return } - if column.ProjectID != issue.Project.ID { - ctx.NotFound(nil) - return - } - if err := project_service.MoveIssuesOnProjectColumn(ctx, ctx.Doer, column, map[int64]int64{0: issue.ID}); err != nil { - ctx.ServerError("MoveIssuesOnProjectColumn", err) - return + for _, issue := range issues { + if column.ProjectID != issue.Project.ID { + continue + } + if err := project_service.MoveIssuesOnProjectColumn(ctx, ctx.Doer, column, map[int64]int64{0 /*sorting=0*/ : issue.ID}); err != nil { + ctx.ServerError("MoveIssuesOnProjectColumn", err) + return + } } - ctx.JSONOK() } diff --git a/routers/web/web.go b/routers/web/web.go index 89635bfa71..14762db904 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1354,7 +1354,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) { m.Post("/labels", reqRepoIssuesOrPullsWriter, repo.UpdateIssueLabel) m.Post("/milestone", reqRepoIssuesOrPullsWriter, repo.UpdateIssueMilestone) m.Post("/projects", reqRepoIssuesOrPullsWriter, reqRepoProjectsReader, repo.UpdateIssueProject) - m.Post("/projects/column", reqRepoIssuesOrPullsWriter, reqRepoProjectsReader, repo.UpdateIssueProjectColumn) + m.Post("/projects/set-column", reqRepoIssuesOrPullsWriter, reqRepoProjectsWriter, repo.UpdateIssueProjectSetColumn) m.Post("/assignee", reqRepoIssuesOrPullsWriter, repo.UpdateIssueAssignee) m.Post("/status", reqRepoIssuesOrPullsWriter, repo.UpdateIssueStatus) m.Post("/delete", reqRepoAdmin, repo.BatchDeleteIssues) diff --git a/templates/repo/issue/sidebar/project_column.tmpl b/templates/repo/issue/sidebar/project_column.tmpl index 4601aa1486..8b06c93f21 100644 --- a/templates/repo/issue/sidebar/project_column.tmpl +++ b/templates/repo/issue/sidebar/project_column.tmpl @@ -5,8 +5,8 @@ {{if $pageMeta.CanModifyIssueOrPull}}