From 7ec532ce85fbcc8e28b665ff70fefdbfa6caeb65 Mon Sep 17 00:00:00 2001 From: lng2020 Date: Sun, 17 Mar 2024 23:32:15 +0800 Subject: [PATCH] Fix 500 when sorting the default project board --- routers/web/org/projects.go | 32 ++++++++++++++++++++++---------- routers/web/repo/projects.go | 32 ++++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/routers/web/org/projects.go b/routers/web/org/projects.go index 928676a52b531..f613540c33bf0 100644 --- a/routers/web/org/projects.go +++ b/routers/web/org/projects.go @@ -574,16 +574,28 @@ func CheckProjectBoardChangePermissions(ctx *context.Context) (*project_model.Pr return nil, nil } - board, err := project_model.GetBoard(ctx, ctx.ParamsInt64(":boardID")) - if err != nil { - ctx.ServerError("GetProjectBoard", err) - return nil, nil - } - if board.ProjectID != ctx.ParamsInt64(":id") { - ctx.JSON(http.StatusUnprocessableEntity, map[string]string{ - "message": fmt.Sprintf("ProjectBoard[%d] is not in Project[%d] as expected", board.ID, project.ID), - }) - return nil, nil + var board *project_model.Board + + if ctx.ParamsInt64(":boardID") == 0 { + board = &project_model.Board{ + ID: 0, + ProjectID: project.ID, + Title: ctx.Locale.TrString("repo.projects.type.uncategorized"), + } + } else { + board, err = project_model.GetBoard(ctx, ctx.ParamsInt64(":boardID")) + if err != nil { + if project_model.IsErrProjectBoardNotExist(err) { + ctx.NotFound("ProjectBoardNotExist", nil) + } else { + ctx.ServerError("GetProjectBoard", err) + } + return nil, nil + } + if board.ProjectID != project.ID { + ctx.NotFound("BoardNotInProject", nil) + return nil, nil + } } if project.OwnerID != ctx.ContextUser.ID { diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go index 2cba5c0970b73..ac9f24b15ef68 100644 --- a/routers/web/repo/projects.go +++ b/routers/web/repo/projects.go @@ -521,16 +521,28 @@ func checkProjectBoardChangePermissions(ctx *context.Context) (*project_model.Pr return nil, nil } - board, err := project_model.GetBoard(ctx, ctx.ParamsInt64(":boardID")) - if err != nil { - ctx.ServerError("GetProjectBoard", err) - return nil, nil - } - if board.ProjectID != ctx.ParamsInt64(":id") { - ctx.JSON(http.StatusUnprocessableEntity, map[string]string{ - "message": fmt.Sprintf("ProjectBoard[%d] is not in Project[%d] as expected", board.ID, project.ID), - }) - return nil, nil + var board *project_model.Board + + if ctx.ParamsInt64(":boardID") == 0 { + board = &project_model.Board{ + ID: 0, + ProjectID: project.ID, + Title: ctx.Locale.TrString("repo.projects.type.uncategorized"), + } + } else { + board, err = project_model.GetBoard(ctx, ctx.ParamsInt64(":boardID")) + if err != nil { + if project_model.IsErrProjectBoardNotExist(err) { + ctx.NotFound("ProjectBoardNotExist", nil) + } else { + ctx.ServerError("GetProjectBoard", err) + } + return nil, nil + } + if board.ProjectID != project.ID { + ctx.NotFound("BoardNotInProject", nil) + return nil, nil + } } if project.RepoID != ctx.Repo.Repository.ID {