2020-08-17 11:07:38 +08:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-28 02:20:29 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-08-17 11:07:38 +08:00
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
2022-06-30 23:55:08 +08:00
|
|
|
"errors"
|
2020-08-17 11:07:38 +08:00
|
|
|
"fmt"
|
2021-04-05 23:30:52 +08:00
|
|
|
"net/http"
|
2020-08-17 11:07:38 +08:00
|
|
|
"strings"
|
|
|
|
|
2023-11-24 11:49:41 +08:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2022-06-13 17:37:59 +08:00
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
2021-11-28 19:58:28 +08:00
|
|
|
"code.gitea.io/gitea/models/perm"
|
2022-03-29 22:16:31 +08:00
|
|
|
project_model "code.gitea.io/gitea/models/project"
|
2024-03-04 10:56:52 +08:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-10 03:57:58 +08:00
|
|
|
"code.gitea.io/gitea/models/unit"
|
2020-08-17 11:07:38 +08:00
|
|
|
"code.gitea.io/gitea/modules/base"
|
2021-12-17 09:15:02 +08:00
|
|
|
"code.gitea.io/gitea/modules/json"
|
2021-04-20 06:25:08 +08:00
|
|
|
"code.gitea.io/gitea/modules/markup"
|
2020-08-17 11:07:38 +08:00
|
|
|
"code.gitea.io/gitea/modules/markup/markdown"
|
2024-03-02 23:42:31 +08:00
|
|
|
"code.gitea.io/gitea/modules/optional"
|
2020-08-17 11:07:38 +08:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2024-05-08 21:44:57 +08:00
|
|
|
"code.gitea.io/gitea/modules/util"
|
2021-01-26 23:36:53 +08:00
|
|
|
"code.gitea.io/gitea/modules/web"
|
2024-09-12 11:53:40 +08:00
|
|
|
shared_user "code.gitea.io/gitea/routers/web/shared/user"
|
2024-02-27 15:12:22 +08:00
|
|
|
"code.gitea.io/gitea/services/context"
|
2021-04-07 03:44:05 +08:00
|
|
|
"code.gitea.io/gitea/services/forms"
|
2024-08-09 09:29:02 +08:00
|
|
|
project_service "code.gitea.io/gitea/services/projects"
|
2020-08-17 11:07:38 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2023-05-31 14:50:18 +08:00
|
|
|
tplProjects base.TplName = "repo/projects/list"
|
|
|
|
tplProjectsNew base.TplName = "repo/projects/new"
|
|
|
|
tplProjectsView base.TplName = "repo/projects/view"
|
2020-08-17 11:07:38 +08:00
|
|
|
)
|
|
|
|
|
2024-03-04 10:56:52 +08:00
|
|
|
// MustEnableRepoProjects check if repo projects are enabled in settings
|
|
|
|
func MustEnableRepoProjects(ctx *context.Context) {
|
2021-11-10 03:57:58 +08:00
|
|
|
if unit.TypeProjects.UnitGlobalDisabled() {
|
2024-05-27 16:59:54 +08:00
|
|
|
ctx.NotFound("EnableRepoProjects", nil)
|
2020-08-17 11:07:38 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.Repo.Repository != nil {
|
2024-03-04 10:56:52 +08:00
|
|
|
projectsUnit := ctx.Repo.Repository.MustGetUnit(ctx, unit.TypeProjects)
|
|
|
|
if !ctx.Repo.CanRead(unit.TypeProjects) || !projectsUnit.ProjectsConfig().IsProjectsAllowed(repo_model.ProjectsModeRepo) {
|
|
|
|
ctx.NotFound("MustEnableRepoProjects", nil)
|
2020-08-17 11:07:38 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Projects renders the home page of projects
|
|
|
|
func Projects(ctx *context.Context) {
|
2024-05-27 16:59:54 +08:00
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.projects")
|
2020-08-17 11:07:38 +08:00
|
|
|
|
2021-07-29 09:42:15 +08:00
|
|
|
sortType := ctx.FormTrim("sort")
|
2020-08-17 11:07:38 +08:00
|
|
|
|
2021-07-29 09:42:15 +08:00
|
|
|
isShowClosed := strings.ToLower(ctx.FormTrim("state")) == "closed"
|
2023-08-12 18:30:28 +08:00
|
|
|
keyword := ctx.FormTrim("q")
|
2020-08-17 11:07:38 +08:00
|
|
|
repo := ctx.Repo.Repository
|
2021-07-29 09:42:15 +08:00
|
|
|
page := ctx.FormInt("page")
|
2020-08-17 11:07:38 +08:00
|
|
|
if page <= 1 {
|
|
|
|
page = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Data["OpenCount"] = repo.NumOpenProjects
|
|
|
|
ctx.Data["ClosedCount"] = repo.NumClosedProjects
|
|
|
|
|
|
|
|
var total int
|
|
|
|
if !isShowClosed {
|
|
|
|
total = repo.NumOpenProjects
|
|
|
|
} else {
|
|
|
|
total = repo.NumClosedProjects
|
|
|
|
}
|
|
|
|
|
2023-11-24 11:49:41 +08:00
|
|
|
projects, count, err := db.FindAndCount[project_model.Project](ctx, project_model.SearchOptions{
|
|
|
|
ListOptions: db.ListOptions{
|
|
|
|
PageSize: setting.UI.IssuePagingNum,
|
|
|
|
Page: page,
|
|
|
|
},
|
2020-08-17 11:07:38 +08:00
|
|
|
RepoID: repo.ID,
|
2024-03-02 23:42:31 +08:00
|
|
|
IsClosed: optional.Some(isShowClosed),
|
2023-07-12 02:47:50 +08:00
|
|
|
OrderBy: project_model.GetSearchOrderByBySortType(sortType),
|
2022-03-29 22:16:31 +08:00
|
|
|
Type: project_model.TypeRepository,
|
2023-08-12 18:30:28 +08:00
|
|
|
Title: keyword,
|
2020-08-17 11:07:38 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("GetProjects", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range projects {
|
2021-04-20 06:25:08 +08:00
|
|
|
projects[i].RenderedContent, err = markdown.RenderString(&markup.RenderContext{
|
2024-01-15 16:49:24 +08:00
|
|
|
Links: markup.Links{
|
|
|
|
Base: ctx.Repo.RepoLink,
|
|
|
|
},
|
|
|
|
Metas: ctx.Repo.Repository.ComposeMetas(ctx),
|
|
|
|
GitRepo: ctx.Repo.GitRepo,
|
2024-05-30 15:04:01 +08:00
|
|
|
Repo: ctx.Repo.Repository,
|
2024-01-15 16:49:24 +08:00
|
|
|
Ctx: ctx,
|
2021-04-20 06:25:08 +08:00
|
|
|
}, projects[i].Description)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("RenderString", err)
|
|
|
|
return
|
|
|
|
}
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Data["Projects"] = projects
|
|
|
|
|
|
|
|
if isShowClosed {
|
|
|
|
ctx.Data["State"] = "closed"
|
|
|
|
} else {
|
|
|
|
ctx.Data["State"] = "open"
|
|
|
|
}
|
|
|
|
|
|
|
|
numPages := 0
|
|
|
|
if count > 0 {
|
2022-06-20 18:02:49 +08:00
|
|
|
numPages = (int(count) - 1/setting.UI.IssuePagingNum)
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pager := context.NewPagination(total, setting.UI.IssuePagingNum, page, numPages)
|
2024-03-16 20:07:56 +08:00
|
|
|
pager.AddParamString("state", fmt.Sprint(ctx.Data["State"]))
|
2020-08-17 11:07:38 +08:00
|
|
|
ctx.Data["Page"] = pager
|
|
|
|
|
2023-03-12 21:36:47 +08:00
|
|
|
ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects)
|
2020-08-17 11:07:38 +08:00
|
|
|
ctx.Data["IsShowClosed"] = isShowClosed
|
|
|
|
ctx.Data["IsProjectsPage"] = true
|
|
|
|
ctx.Data["SortType"] = sortType
|
|
|
|
|
2021-04-05 23:30:52 +08:00
|
|
|
ctx.HTML(http.StatusOK, tplProjects)
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
|
|
|
|
2023-05-31 14:50:18 +08:00
|
|
|
// RenderNewProject render creating a project page
|
|
|
|
func RenderNewProject(ctx *context.Context) {
|
2020-08-17 11:07:38 +08:00
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.projects.new")
|
2024-05-27 16:59:54 +08:00
|
|
|
ctx.Data["TemplateConfigs"] = project_model.GetTemplateConfigs()
|
2023-02-11 16:12:41 +08:00
|
|
|
ctx.Data["CardTypes"] = project_model.GetCardConfig()
|
2021-11-10 03:57:58 +08:00
|
|
|
ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects)
|
2023-05-31 14:50:18 +08:00
|
|
|
ctx.Data["CancelLink"] = ctx.Repo.Repository.Link() + "/projects"
|
2021-04-05 23:30:52 +08:00
|
|
|
ctx.HTML(http.StatusOK, tplProjectsNew)
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
|
|
|
|
2020-08-22 14:58:59 +08:00
|
|
|
// NewProjectPost creates a new project
|
2021-01-26 23:36:53 +08:00
|
|
|
func NewProjectPost(ctx *context.Context) {
|
2021-04-07 03:44:05 +08:00
|
|
|
form := web.GetForm(ctx).(*forms.CreateProjectForm)
|
2020-08-17 11:07:38 +08:00
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.projects.new")
|
|
|
|
|
|
|
|
if ctx.HasError() {
|
2023-05-31 14:50:18 +08:00
|
|
|
RenderNewProject(ctx)
|
2020-08-17 11:07:38 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-09-29 20:12:54 +08:00
|
|
|
if err := project_model.NewProject(ctx, &project_model.Project{
|
2024-05-27 16:59:54 +08:00
|
|
|
RepoID: ctx.Repo.Repository.ID,
|
|
|
|
Title: form.Title,
|
|
|
|
Description: form.Content,
|
|
|
|
CreatorID: ctx.Doer.ID,
|
|
|
|
TemplateType: form.TemplateType,
|
|
|
|
CardType: form.CardType,
|
|
|
|
Type: project_model.TypeRepository,
|
2020-08-17 11:07:38 +08:00
|
|
|
}); err != nil {
|
|
|
|
ctx.ServerError("NewProject", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.projects.create_success", form.Title))
|
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/projects")
|
|
|
|
}
|
|
|
|
|
|
|
|
// ChangeProjectStatus updates the status of a project between "open" and "close"
|
|
|
|
func ChangeProjectStatus(ctx *context.Context) {
|
2023-10-23 20:34:17 +08:00
|
|
|
var toClose bool
|
2024-06-19 06:32:45 +08:00
|
|
|
switch ctx.PathParam(":action") {
|
2020-08-17 11:07:38 +08:00
|
|
|
case "open":
|
|
|
|
toClose = false
|
|
|
|
case "close":
|
|
|
|
toClose = true
|
|
|
|
default:
|
2023-10-23 20:34:17 +08:00
|
|
|
ctx.JSONRedirect(ctx.Repo.RepoLink + "/projects")
|
|
|
|
return
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
2024-06-19 06:32:45 +08:00
|
|
|
id := ctx.PathParamInt64(":id")
|
2020-08-17 11:07:38 +08:00
|
|
|
|
2023-09-29 20:12:54 +08:00
|
|
|
if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx, ctx.Repo.Repository.ID, id, toClose); err != nil {
|
2024-04-14 00:17:01 +08:00
|
|
|
ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err)
|
2020-08-17 11:07:38 +08:00
|
|
|
return
|
|
|
|
}
|
2024-04-14 00:17:01 +08:00
|
|
|
ctx.JSONRedirect(fmt.Sprintf("%s/projects/%d", ctx.Repo.RepoLink, id))
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteProject delete a project
|
|
|
|
func DeleteProject(ctx *context.Context) {
|
2024-06-19 06:32:45 +08:00
|
|
|
p, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id"))
|
2020-08-17 11:07:38 +08:00
|
|
|
if err != nil {
|
2022-03-29 22:16:31 +08:00
|
|
|
if project_model.IsErrProjectNotExist(err) {
|
2020-08-17 11:07:38 +08:00
|
|
|
ctx.NotFound("", nil)
|
|
|
|
} else {
|
|
|
|
ctx.ServerError("GetProjectByID", err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if p.RepoID != ctx.Repo.Repository.ID {
|
|
|
|
ctx.NotFound("", nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-10 10:46:31 +08:00
|
|
|
if err := project_model.DeleteProjectByID(ctx, p.ID); err != nil {
|
2020-08-17 11:07:38 +08:00
|
|
|
ctx.Flash.Error("DeleteProjectByID: " + err.Error())
|
|
|
|
} else {
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.projects.deletion_success"))
|
|
|
|
}
|
|
|
|
|
2023-07-26 14:04:01 +08:00
|
|
|
ctx.JSONRedirect(ctx.Repo.RepoLink + "/projects")
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
|
|
|
|
2023-05-31 14:50:18 +08:00
|
|
|
// RenderEditProject allows a project to be edited
|
|
|
|
func RenderEditProject(ctx *context.Context) {
|
2020-08-17 11:07:38 +08:00
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.projects.edit")
|
|
|
|
ctx.Data["PageIsEditProjects"] = true
|
2021-11-10 03:57:58 +08:00
|
|
|
ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects)
|
2023-02-11 16:12:41 +08:00
|
|
|
ctx.Data["CardTypes"] = project_model.GetCardConfig()
|
2020-08-17 11:07:38 +08:00
|
|
|
|
2024-06-19 06:32:45 +08:00
|
|
|
p, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id"))
|
2020-08-17 11:07:38 +08:00
|
|
|
if err != nil {
|
2022-03-29 22:16:31 +08:00
|
|
|
if project_model.IsErrProjectNotExist(err) {
|
2020-08-17 11:07:38 +08:00
|
|
|
ctx.NotFound("", nil)
|
|
|
|
} else {
|
|
|
|
ctx.ServerError("GetProjectByID", err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if p.RepoID != ctx.Repo.Repository.ID {
|
|
|
|
ctx.NotFound("", nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-03-24 16:37:56 +08:00
|
|
|
ctx.Data["projectID"] = p.ID
|
2020-08-17 11:07:38 +08:00
|
|
|
ctx.Data["title"] = p.Title
|
|
|
|
ctx.Data["content"] = p.Description
|
2023-02-11 16:12:41 +08:00
|
|
|
ctx.Data["card_type"] = p.CardType
|
2023-03-09 22:38:29 +08:00
|
|
|
ctx.Data["redirect"] = ctx.FormString("redirect")
|
2023-05-31 14:50:18 +08:00
|
|
|
ctx.Data["CancelLink"] = fmt.Sprintf("%s/projects/%d", ctx.Repo.Repository.Link(), p.ID)
|
2020-08-17 11:07:38 +08:00
|
|
|
|
2021-04-05 23:30:52 +08:00
|
|
|
ctx.HTML(http.StatusOK, tplProjectsNew)
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// EditProjectPost response for editing a project
|
2021-01-26 23:36:53 +08:00
|
|
|
func EditProjectPost(ctx *context.Context) {
|
2021-04-07 03:44:05 +08:00
|
|
|
form := web.GetForm(ctx).(*forms.CreateProjectForm)
|
2024-06-19 06:32:45 +08:00
|
|
|
projectID := ctx.PathParamInt64(":id")
|
2023-05-31 14:50:18 +08:00
|
|
|
|
2020-08-17 11:07:38 +08:00
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.projects.edit")
|
|
|
|
ctx.Data["PageIsEditProjects"] = true
|
2021-11-10 03:57:58 +08:00
|
|
|
ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects)
|
2023-02-11 16:12:41 +08:00
|
|
|
ctx.Data["CardTypes"] = project_model.GetCardConfig()
|
2023-05-31 14:50:18 +08:00
|
|
|
ctx.Data["CancelLink"] = fmt.Sprintf("%s/projects/%d", ctx.Repo.Repository.Link(), projectID)
|
2020-08-17 11:07:38 +08:00
|
|
|
|
|
|
|
if ctx.HasError() {
|
2021-04-05 23:30:52 +08:00
|
|
|
ctx.HTML(http.StatusOK, tplProjectsNew)
|
2020-08-17 11:07:38 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-31 14:50:18 +08:00
|
|
|
p, err := project_model.GetProjectByID(ctx, projectID)
|
2020-08-17 11:07:38 +08:00
|
|
|
if err != nil {
|
2022-03-29 22:16:31 +08:00
|
|
|
if project_model.IsErrProjectNotExist(err) {
|
2020-08-17 11:07:38 +08:00
|
|
|
ctx.NotFound("", nil)
|
|
|
|
} else {
|
|
|
|
ctx.ServerError("GetProjectByID", err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if p.RepoID != ctx.Repo.Repository.ID {
|
|
|
|
ctx.NotFound("", nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
p.Title = form.Title
|
|
|
|
p.Description = form.Content
|
2023-02-11 16:12:41 +08:00
|
|
|
p.CardType = form.CardType
|
2022-05-20 22:08:52 +08:00
|
|
|
if err = project_model.UpdateProject(ctx, p); err != nil {
|
2020-08-17 11:07:38 +08:00
|
|
|
ctx.ServerError("UpdateProjects", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.projects.edit_success", p.Title))
|
2023-03-09 22:38:29 +08:00
|
|
|
if ctx.FormString("redirect") == "project" {
|
2023-09-29 20:12:54 +08:00
|
|
|
ctx.Redirect(p.Link(ctx))
|
2023-03-09 22:38:29 +08:00
|
|
|
} else {
|
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/projects")
|
|
|
|
}
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
|
|
|
|
2024-05-27 16:59:54 +08:00
|
|
|
// ViewProject renders the project with board view
|
2020-08-17 11:07:38 +08:00
|
|
|
func ViewProject(ctx *context.Context) {
|
2024-06-19 06:32:45 +08:00
|
|
|
project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id"))
|
2020-08-17 11:07:38 +08:00
|
|
|
if err != nil {
|
2022-03-29 22:16:31 +08:00
|
|
|
if project_model.IsErrProjectNotExist(err) {
|
2020-08-17 11:07:38 +08:00
|
|
|
ctx.NotFound("", nil)
|
|
|
|
} else {
|
|
|
|
ctx.ServerError("GetProjectByID", err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if project.RepoID != ctx.Repo.Repository.ID {
|
|
|
|
ctx.NotFound("", nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-05-27 16:59:54 +08:00
|
|
|
columns, err := project.GetColumns(ctx)
|
2020-08-17 11:07:38 +08:00
|
|
|
if err != nil {
|
2024-05-27 16:59:54 +08:00
|
|
|
ctx.ServerError("GetProjectColumns", err)
|
2020-08-17 11:07:38 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-09-12 11:53:40 +08:00
|
|
|
var labelIDs []int64
|
|
|
|
// 1,-2 means including label 1 and excluding label 2
|
|
|
|
// 0 means issues with no label
|
|
|
|
// blank means labels will not be filtered for issues
|
|
|
|
selectLabels := ctx.FormString("labels")
|
|
|
|
if selectLabels == "" {
|
|
|
|
ctx.Data["AllLabels"] = true
|
|
|
|
} else if selectLabels == "0" {
|
|
|
|
ctx.Data["NoLabel"] = true
|
|
|
|
}
|
|
|
|
if len(selectLabels) > 0 {
|
|
|
|
labelIDs, err = base.StringsToInt64s(strings.Split(selectLabels, ","))
|
|
|
|
if err != nil {
|
|
|
|
ctx.Flash.Error(ctx.Tr("invalid_data", selectLabels), true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assigneeID := ctx.FormInt64("assignee")
|
|
|
|
|
|
|
|
issuesMap, err := issues_model.LoadIssuesFromColumnList(ctx, columns, &issues_model.IssuesOptions{
|
|
|
|
LabelIDs: labelIDs,
|
|
|
|
AssigneeID: assigneeID,
|
|
|
|
})
|
2021-01-21 03:53:48 +08:00
|
|
|
if err != nil {
|
2024-05-27 16:59:54 +08:00
|
|
|
ctx.ServerError("LoadIssuesOfColumns", err)
|
2020-08-17 11:07:38 +08:00
|
|
|
return
|
|
|
|
}
|
2021-01-21 03:53:48 +08:00
|
|
|
|
2023-02-11 16:12:41 +08:00
|
|
|
if project.CardType != project_model.CardTypeTextOnly {
|
2024-03-04 10:56:52 +08:00
|
|
|
issuesAttachmentMap := make(map[int64][]*repo_model.Attachment)
|
2023-02-11 16:12:41 +08:00
|
|
|
for _, issuesList := range issuesMap {
|
|
|
|
for _, issue := range issuesList {
|
2024-03-04 10:56:52 +08:00
|
|
|
if issueAttachment, err := repo_model.GetAttachmentsByIssueIDImagesLatest(ctx, issue.ID); err == nil {
|
2023-02-11 16:12:41 +08:00
|
|
|
issuesAttachmentMap[issue.ID] = issueAttachment
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ctx.Data["issuesAttachmentMap"] = issuesAttachmentMap
|
|
|
|
}
|
|
|
|
|
2022-06-13 17:37:59 +08:00
|
|
|
linkedPrsMap := make(map[int64][]*issues_model.Issue)
|
2022-03-29 22:16:31 +08:00
|
|
|
for _, issuesList := range issuesMap {
|
|
|
|
for _, issue := range issuesList {
|
2024-02-15 02:19:57 +08:00
|
|
|
var referencedIDs []int64
|
2022-03-29 22:16:31 +08:00
|
|
|
for _, comment := range issue.Comments {
|
|
|
|
if comment.RefIssueID != 0 && comment.RefIsPull {
|
2024-02-15 02:19:57 +08:00
|
|
|
referencedIDs = append(referencedIDs, comment.RefIssueID)
|
2022-03-29 22:16:31 +08:00
|
|
|
}
|
2021-01-21 03:53:48 +08:00
|
|
|
}
|
|
|
|
|
2024-02-15 02:19:57 +08:00
|
|
|
if len(referencedIDs) > 0 {
|
2022-11-19 16:12:33 +08:00
|
|
|
if linkedPrs, err := issues_model.Issues(ctx, &issues_model.IssuesOptions{
|
2024-02-15 02:19:57 +08:00
|
|
|
IssueIDs: referencedIDs,
|
2024-03-02 23:42:31 +08:00
|
|
|
IsPull: optional.Some(true),
|
2022-03-29 22:16:31 +08:00
|
|
|
}); err == nil {
|
|
|
|
linkedPrsMap[issue.ID] = linkedPrs
|
|
|
|
}
|
2021-01-21 03:53:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ctx.Data["LinkedPRs"] = linkedPrsMap
|
2020-08-17 11:07:38 +08:00
|
|
|
|
2024-09-12 11:53:40 +08:00
|
|
|
labels, err := issues_model.GetLabelsByRepoID(ctx, project.RepoID, "", db.ListOptions{})
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("GetLabelsByRepoID", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.Repo.Owner.IsOrganization() {
|
|
|
|
orgLabels, err := issues_model.GetLabelsByOrgID(ctx, ctx.Repo.Owner.ID, "", db.ListOptions{})
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("GetLabelsByOrgID", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
labels = append(labels, orgLabels...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the exclusive scope for every label ID
|
|
|
|
labelExclusiveScopes := make([]string, 0, len(labelIDs))
|
|
|
|
for _, labelID := range labelIDs {
|
|
|
|
foundExclusiveScope := false
|
|
|
|
for _, label := range labels {
|
|
|
|
if label.ID == labelID || label.ID == -labelID {
|
|
|
|
labelExclusiveScopes = append(labelExclusiveScopes, label.ExclusiveScope())
|
|
|
|
foundExclusiveScope = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !foundExclusiveScope {
|
|
|
|
labelExclusiveScopes = append(labelExclusiveScopes, "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, l := range labels {
|
|
|
|
l.LoadSelectedLabelsAfterClick(labelIDs, labelExclusiveScopes)
|
|
|
|
}
|
|
|
|
ctx.Data["Labels"] = labels
|
|
|
|
ctx.Data["NumLabels"] = len(labels)
|
|
|
|
|
|
|
|
// Get assignees.
|
|
|
|
assigneeUsers, err := repo_model.GetRepoAssignees(ctx, ctx.Repo.Repository)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("GetRepoAssignees", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Data["Assignees"] = shared_user.MakeSelfOnTop(ctx.Doer, assigneeUsers)
|
|
|
|
|
|
|
|
ctx.Data["SelectLabels"] = selectLabels
|
|
|
|
ctx.Data["AssigneeID"] = assigneeID
|
|
|
|
|
2021-04-20 06:25:08 +08:00
|
|
|
project.RenderedContent, err = markdown.RenderString(&markup.RenderContext{
|
2024-01-15 16:49:24 +08:00
|
|
|
Links: markup.Links{
|
|
|
|
Base: ctx.Repo.RepoLink,
|
|
|
|
},
|
|
|
|
Metas: ctx.Repo.Repository.ComposeMetas(ctx),
|
|
|
|
GitRepo: ctx.Repo.GitRepo,
|
2024-05-30 15:04:01 +08:00
|
|
|
Repo: ctx.Repo.Repository,
|
2024-01-15 16:49:24 +08:00
|
|
|
Ctx: ctx,
|
2021-04-20 06:25:08 +08:00
|
|
|
}, project.Description)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("RenderString", err)
|
|
|
|
return
|
|
|
|
}
|
2020-11-10 11:46:19 +08:00
|
|
|
|
2021-11-22 18:57:05 +08:00
|
|
|
ctx.Data["IsProjectsPage"] = true
|
2021-11-10 03:57:58 +08:00
|
|
|
ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects)
|
2020-08-17 11:07:38 +08:00
|
|
|
ctx.Data["Project"] = project
|
2022-03-29 22:16:31 +08:00
|
|
|
ctx.Data["IssuesMap"] = issuesMap
|
2024-05-27 16:59:54 +08:00
|
|
|
ctx.Data["Columns"] = columns
|
2020-08-17 11:07:38 +08:00
|
|
|
|
2021-04-05 23:30:52 +08:00
|
|
|
ctx.HTML(http.StatusOK, tplProjectsView)
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateIssueProject change an issue's project
|
|
|
|
func UpdateIssueProject(ctx *context.Context) {
|
|
|
|
issues := getActionIssues(ctx)
|
|
|
|
if ctx.Written() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-06-24 23:31:28 +08:00
|
|
|
if err := issues.LoadProjects(ctx); err != nil {
|
|
|
|
ctx.ServerError("LoadProjects", err)
|
|
|
|
return
|
|
|
|
}
|
2024-05-08 21:44:57 +08:00
|
|
|
if _, err := issues.LoadRepositories(ctx); err != nil {
|
|
|
|
ctx.ServerError("LoadProjects", err)
|
|
|
|
return
|
|
|
|
}
|
2023-06-24 23:31:28 +08:00
|
|
|
|
2021-07-29 09:42:15 +08:00
|
|
|
projectID := ctx.FormInt64("id")
|
2020-08-17 11:07:38 +08:00
|
|
|
for _, issue := range issues {
|
2024-05-08 21:44:57 +08:00
|
|
|
if issue.Project != nil && issue.Project.ID == projectID {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if err := issues_model.IssueAssignOrRemoveProject(ctx, issue, ctx.Doer, projectID, 0); err != nil {
|
|
|
|
if errors.Is(err, util.ErrPermissionDenied) {
|
2023-07-04 18:26:24 +08:00
|
|
|
continue
|
|
|
|
}
|
2024-05-08 21:44:57 +08:00
|
|
|
ctx.ServerError("IssueAssignOrRemoveProject", err)
|
2020-08-17 11:07:38 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-26 14:04:01 +08:00
|
|
|
ctx.JSONOK()
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
|
|
|
|
2024-05-27 16:59:54 +08:00
|
|
|
// DeleteProjectColumn allows for the deletion of a project column
|
|
|
|
func DeleteProjectColumn(ctx *context.Context) {
|
2022-03-22 15:03:22 +08:00
|
|
|
if ctx.Doer == nil {
|
2021-04-05 23:30:52 +08:00
|
|
|
ctx.JSON(http.StatusForbidden, map[string]string{
|
2020-08-17 11:07:38 +08:00
|
|
|
"message": "Only signed in users are allowed to perform this action.",
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-11-28 19:58:28 +08:00
|
|
|
if !ctx.Repo.IsOwner() && !ctx.Repo.IsAdmin() && !ctx.Repo.CanAccess(perm.AccessModeWrite, unit.TypeProjects) {
|
2021-04-05 23:30:52 +08:00
|
|
|
ctx.JSON(http.StatusForbidden, map[string]string{
|
2020-08-17 11:07:38 +08:00
|
|
|
"message": "Only authorized users are allowed to perform this action.",
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-06-19 06:32:45 +08:00
|
|
|
project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id"))
|
2020-08-17 11:07:38 +08:00
|
|
|
if err != nil {
|
2022-03-29 22:16:31 +08:00
|
|
|
if project_model.IsErrProjectNotExist(err) {
|
2020-08-17 11:07:38 +08:00
|
|
|
ctx.NotFound("", nil)
|
|
|
|
} else {
|
|
|
|
ctx.ServerError("GetProjectByID", err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-06-19 06:32:45 +08:00
|
|
|
pb, err := project_model.GetColumn(ctx, ctx.PathParamInt64(":columnID"))
|
2020-08-17 11:07:38 +08:00
|
|
|
if err != nil {
|
2024-05-27 16:59:54 +08:00
|
|
|
ctx.ServerError("GetProjectColumn", err)
|
2020-08-17 11:07:38 +08:00
|
|
|
return
|
|
|
|
}
|
2024-06-19 06:32:45 +08:00
|
|
|
if pb.ProjectID != ctx.PathParamInt64(":id") {
|
2021-04-05 23:30:52 +08:00
|
|
|
ctx.JSON(http.StatusUnprocessableEntity, map[string]string{
|
2024-05-27 16:59:54 +08:00
|
|
|
"message": fmt.Sprintf("ProjectColumn[%d] is not in Project[%d] as expected", pb.ID, project.ID),
|
2020-08-17 11:07:38 +08:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if project.RepoID != ctx.Repo.Repository.ID {
|
2021-04-05 23:30:52 +08:00
|
|
|
ctx.JSON(http.StatusUnprocessableEntity, map[string]string{
|
2024-05-27 16:59:54 +08:00
|
|
|
"message": fmt.Sprintf("ProjectColumn[%d] is not in Repository[%d] as expected", pb.ID, ctx.Repo.Repository.ID),
|
2020-08-17 11:07:38 +08:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-06-19 06:32:45 +08:00
|
|
|
if err := project_model.DeleteColumnByID(ctx, ctx.PathParamInt64(":columnID")); err != nil {
|
2024-05-27 16:59:54 +08:00
|
|
|
ctx.ServerError("DeleteProjectColumnByID", err)
|
2020-08-17 11:07:38 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-07-26 14:04:01 +08:00
|
|
|
ctx.JSONOK()
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
|
|
|
|
2024-05-27 16:59:54 +08:00
|
|
|
// AddColumnToProjectPost allows a new column to be added to a project.
|
|
|
|
func AddColumnToProjectPost(ctx *context.Context) {
|
|
|
|
form := web.GetForm(ctx).(*forms.EditProjectColumnForm)
|
2021-11-28 19:58:28 +08:00
|
|
|
if !ctx.Repo.IsOwner() && !ctx.Repo.IsAdmin() && !ctx.Repo.CanAccess(perm.AccessModeWrite, unit.TypeProjects) {
|
2021-04-05 23:30:52 +08:00
|
|
|
ctx.JSON(http.StatusForbidden, map[string]string{
|
2020-08-17 11:07:38 +08:00
|
|
|
"message": "Only authorized users are allowed to perform this action.",
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-06-19 06:32:45 +08:00
|
|
|
project, err := project_model.GetProjectForRepoByID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":id"))
|
2020-08-17 11:07:38 +08:00
|
|
|
if err != nil {
|
2022-03-29 22:16:31 +08:00
|
|
|
if project_model.IsErrProjectNotExist(err) {
|
2020-08-17 11:07:38 +08:00
|
|
|
ctx.NotFound("", nil)
|
|
|
|
} else {
|
|
|
|
ctx.ServerError("GetProjectByID", err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-05-27 16:59:54 +08:00
|
|
|
if err := project_model.NewColumn(ctx, &project_model.Column{
|
2020-08-17 11:07:38 +08:00
|
|
|
ProjectID: project.ID,
|
|
|
|
Title: form.Title,
|
2021-09-30 04:53:12 +08:00
|
|
|
Color: form.Color,
|
2022-03-22 15:03:22 +08:00
|
|
|
CreatorID: ctx.Doer.ID,
|
2020-08-17 11:07:38 +08:00
|
|
|
}); err != nil {
|
2024-05-27 16:59:54 +08:00
|
|
|
ctx.ServerError("NewProjectColumn", err)
|
2020-08-17 11:07:38 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-07-26 14:04:01 +08:00
|
|
|
ctx.JSONOK()
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
|
|
|
|
2024-05-27 16:59:54 +08:00
|
|
|
func checkProjectColumnChangePermissions(ctx *context.Context) (*project_model.Project, *project_model.Column) {
|
2022-03-22 15:03:22 +08:00
|
|
|
if ctx.Doer == nil {
|
2021-04-05 23:30:52 +08:00
|
|
|
ctx.JSON(http.StatusForbidden, map[string]string{
|
2020-08-17 11:07:38 +08:00
|
|
|
"message": "Only signed in users are allowed to perform this action.",
|
|
|
|
})
|
2021-01-16 04:29:32 +08:00
|
|
|
return nil, nil
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
|
|
|
|
2021-11-28 19:58:28 +08:00
|
|
|
if !ctx.Repo.IsOwner() && !ctx.Repo.IsAdmin() && !ctx.Repo.CanAccess(perm.AccessModeWrite, unit.TypeProjects) {
|
2021-04-05 23:30:52 +08:00
|
|
|
ctx.JSON(http.StatusForbidden, map[string]string{
|
2020-08-17 11:07:38 +08:00
|
|
|
"message": "Only authorized users are allowed to perform this action.",
|
|
|
|
})
|
2021-01-16 04:29:32 +08:00
|
|
|
return nil, nil
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
|
|
|
|
2024-06-19 06:32:45 +08:00
|
|
|
project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id"))
|
2020-08-17 11:07:38 +08:00
|
|
|
if err != nil {
|
2022-03-29 22:16:31 +08:00
|
|
|
if project_model.IsErrProjectNotExist(err) {
|
2020-08-17 11:07:38 +08:00
|
|
|
ctx.NotFound("", nil)
|
|
|
|
} else {
|
|
|
|
ctx.ServerError("GetProjectByID", err)
|
|
|
|
}
|
2021-01-16 04:29:32 +08:00
|
|
|
return nil, nil
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
|
|
|
|
2024-06-19 06:32:45 +08:00
|
|
|
column, err := project_model.GetColumn(ctx, ctx.PathParamInt64(":columnID"))
|
2020-08-17 11:07:38 +08:00
|
|
|
if err != nil {
|
2024-05-27 16:59:54 +08:00
|
|
|
ctx.ServerError("GetProjectColumn", err)
|
2021-01-16 04:29:32 +08:00
|
|
|
return nil, nil
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
2024-06-19 06:32:45 +08:00
|
|
|
if column.ProjectID != ctx.PathParamInt64(":id") {
|
2021-04-05 23:30:52 +08:00
|
|
|
ctx.JSON(http.StatusUnprocessableEntity, map[string]string{
|
2024-05-27 16:59:54 +08:00
|
|
|
"message": fmt.Sprintf("ProjectColumn[%d] is not in Project[%d] as expected", column.ID, project.ID),
|
2020-08-17 11:07:38 +08:00
|
|
|
})
|
2021-01-16 04:29:32 +08:00
|
|
|
return nil, nil
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if project.RepoID != ctx.Repo.Repository.ID {
|
2021-04-05 23:30:52 +08:00
|
|
|
ctx.JSON(http.StatusUnprocessableEntity, map[string]string{
|
2024-05-27 16:59:54 +08:00
|
|
|
"message": fmt.Sprintf("ProjectColumn[%d] is not in Repository[%d] as expected", column.ID, ctx.Repo.Repository.ID),
|
2020-08-17 11:07:38 +08:00
|
|
|
})
|
2021-01-16 04:29:32 +08:00
|
|
|
return nil, nil
|
|
|
|
}
|
2024-05-27 16:59:54 +08:00
|
|
|
return project, column
|
2021-01-16 04:29:32 +08:00
|
|
|
}
|
|
|
|
|
2024-05-27 16:59:54 +08:00
|
|
|
// EditProjectColumn allows a project column's to be updated
|
|
|
|
func EditProjectColumn(ctx *context.Context) {
|
|
|
|
form := web.GetForm(ctx).(*forms.EditProjectColumnForm)
|
|
|
|
_, column := checkProjectColumnChangePermissions(ctx)
|
2021-01-16 04:29:32 +08:00
|
|
|
if ctx.Written() {
|
2020-08-17 11:07:38 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if form.Title != "" {
|
2024-05-27 16:59:54 +08:00
|
|
|
column.Title = form.Title
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
2024-05-27 16:59:54 +08:00
|
|
|
column.Color = form.Color
|
2021-02-12 00:32:27 +08:00
|
|
|
if form.Sorting != 0 {
|
2024-05-27 16:59:54 +08:00
|
|
|
column.Sorting = form.Sorting
|
2021-02-12 00:32:27 +08:00
|
|
|
}
|
|
|
|
|
2024-05-27 16:59:54 +08:00
|
|
|
if err := project_model.UpdateColumn(ctx, column); err != nil {
|
|
|
|
ctx.ServerError("UpdateProjectColumn", err)
|
2021-01-16 04:29:32 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-07-26 14:04:01 +08:00
|
|
|
ctx.JSONOK()
|
2021-01-16 04:29:32 +08:00
|
|
|
}
|
|
|
|
|
2024-05-27 16:59:54 +08:00
|
|
|
// SetDefaultProjectColumn set default column for uncategorized issues/pulls
|
|
|
|
func SetDefaultProjectColumn(ctx *context.Context) {
|
|
|
|
project, column := checkProjectColumnChangePermissions(ctx)
|
2021-01-16 04:29:32 +08:00
|
|
|
if ctx.Written() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-05-27 16:59:54 +08:00
|
|
|
if err := project_model.SetDefaultColumn(ctx, project.ID, column.ID); err != nil {
|
|
|
|
ctx.ServerError("SetDefaultColumn", err)
|
2020-08-17 11:07:38 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-07-26 14:04:01 +08:00
|
|
|
ctx.JSONOK()
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
|
|
|
|
2021-12-08 14:57:18 +08:00
|
|
|
// MoveIssues moves or keeps issues in a column and sorts them inside that column
|
|
|
|
func MoveIssues(ctx *context.Context) {
|
2022-03-22 15:03:22 +08:00
|
|
|
if ctx.Doer == nil {
|
2021-04-05 23:30:52 +08:00
|
|
|
ctx.JSON(http.StatusForbidden, map[string]string{
|
2020-08-17 11:07:38 +08:00
|
|
|
"message": "Only signed in users are allowed to perform this action.",
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-11-28 19:58:28 +08:00
|
|
|
if !ctx.Repo.IsOwner() && !ctx.Repo.IsAdmin() && !ctx.Repo.CanAccess(perm.AccessModeWrite, unit.TypeProjects) {
|
2021-04-05 23:30:52 +08:00
|
|
|
ctx.JSON(http.StatusForbidden, map[string]string{
|
2020-08-17 11:07:38 +08:00
|
|
|
"message": "Only authorized users are allowed to perform this action.",
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-06-19 06:32:45 +08:00
|
|
|
project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id"))
|
2020-08-17 11:07:38 +08:00
|
|
|
if err != nil {
|
2022-03-29 22:16:31 +08:00
|
|
|
if project_model.IsErrProjectNotExist(err) {
|
2021-12-08 14:57:18 +08:00
|
|
|
ctx.NotFound("ProjectNotExist", nil)
|
2020-08-17 11:07:38 +08:00
|
|
|
} else {
|
|
|
|
ctx.ServerError("GetProjectByID", err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2021-12-08 14:57:18 +08:00
|
|
|
if project.RepoID != ctx.Repo.Repository.ID {
|
|
|
|
ctx.NotFound("InvalidRepoID", nil)
|
2020-08-17 11:07:38 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-06-19 06:32:45 +08:00
|
|
|
column, err := project_model.GetColumn(ctx, ctx.PathParamInt64(":columnID"))
|
2024-03-28 04:54:32 +08:00
|
|
|
if err != nil {
|
2024-05-27 16:59:54 +08:00
|
|
|
if project_model.IsErrProjectColumnNotExist(err) {
|
|
|
|
ctx.NotFound("ProjectColumnNotExist", nil)
|
2024-03-28 04:54:32 +08:00
|
|
|
} else {
|
2024-05-27 16:59:54 +08:00
|
|
|
ctx.ServerError("GetProjectColumn", err)
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
2024-03-28 04:54:32 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-05-27 16:59:54 +08:00
|
|
|
if column.ProjectID != project.ID {
|
|
|
|
ctx.NotFound("ColumnNotInProject", nil)
|
2024-03-28 04:54:32 +08:00
|
|
|
return
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|
|
|
|
|
2021-12-08 14:57:18 +08:00
|
|
|
type movedIssuesForm struct {
|
|
|
|
Issues []struct {
|
|
|
|
IssueID int64 `json:"issueID"`
|
|
|
|
Sorting int64 `json:"sorting"`
|
|
|
|
} `json:"issues"`
|
|
|
|
}
|
|
|
|
|
|
|
|
form := &movedIssuesForm{}
|
|
|
|
if err = json.NewDecoder(ctx.Req.Body).Decode(&form); err != nil {
|
|
|
|
ctx.ServerError("DecodeMovedIssuesForm", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
issueIDs := make([]int64, 0, len(form.Issues))
|
|
|
|
sortedIssueIDs := make(map[int64]int64)
|
|
|
|
for _, issue := range form.Issues {
|
|
|
|
issueIDs = append(issueIDs, issue.IssueID)
|
|
|
|
sortedIssueIDs[issue.Sorting] = issue.IssueID
|
|
|
|
}
|
2022-06-13 17:37:59 +08:00
|
|
|
movedIssues, err := issues_model.GetIssuesByIDs(ctx, issueIDs)
|
2020-08-17 11:07:38 +08:00
|
|
|
if err != nil {
|
2022-06-13 17:37:59 +08:00
|
|
|
if issues_model.IsErrIssueNotExist(err) {
|
2021-12-08 14:57:18 +08:00
|
|
|
ctx.NotFound("IssueNotExisting", nil)
|
2020-08-17 11:07:38 +08:00
|
|
|
} else {
|
|
|
|
ctx.ServerError("GetIssueByID", err)
|
|
|
|
}
|
2021-12-08 14:57:18 +08:00
|
|
|
return
|
|
|
|
}
|
2020-08-17 11:07:38 +08:00
|
|
|
|
2021-12-08 14:57:18 +08:00
|
|
|
if len(movedIssues) != len(form.Issues) {
|
2022-06-30 23:55:08 +08:00
|
|
|
ctx.ServerError("some issues do not exist", errors.New("some issues do not exist"))
|
2020-08-17 11:07:38 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-06-30 23:55:08 +08:00
|
|
|
for _, issue := range movedIssues {
|
|
|
|
if issue.RepoID != project.RepoID {
|
|
|
|
ctx.ServerError("Some issue's repoID is not equal to project's repoID", errors.New("Some issue's repoID is not equal to project's repoID"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-09 09:29:02 +08:00
|
|
|
if err = project_service.MoveIssuesOnProjectColumn(ctx, ctx.Doer, column, sortedIssueIDs); err != nil {
|
2024-05-27 16:59:54 +08:00
|
|
|
ctx.ServerError("MoveIssuesOnProjectColumn", err)
|
2020-08-17 11:07:38 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-07-26 14:04:01 +08:00
|
|
|
ctx.JSONOK()
|
2020-08-17 11:07:38 +08:00
|
|
|
}
|