Skip to content

Commit 5285b30

Browse files
committed
routers
1 parent 2cca177 commit 5285b30

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

routers/repo/projects.go

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -410,21 +410,19 @@ func AddBoardToProjectPost(ctx *context.Context, form auth.EditProjectBoardTitle
410410
})
411411
}
412412

413-
// EditProjectBoardTitle allows a project board's title to be updated
414-
func EditProjectBoardTitle(ctx *context.Context, form auth.EditProjectBoardTitleForm) {
415-
413+
func checkProjectBoardChangePermissions(ctx *context.Context) (*models.Project, *models.ProjectBoard) {
416414
if ctx.User == nil {
417415
ctx.JSON(403, map[string]string{
418416
"message": "Only signed in users are allowed to perform this action.",
419417
})
420-
return
418+
return nil, nil
421419
}
422420

423421
if !ctx.Repo.IsOwner() && !ctx.Repo.IsAdmin() && !ctx.Repo.CanAccess(models.AccessModeWrite, models.UnitTypeProjects) {
424422
ctx.JSON(403, map[string]string{
425423
"message": "Only authorized users are allowed to perform this action.",
426424
})
427-
return
425+
return nil, nil
428426
}
429427

430428
project, err := models.GetProjectByID(ctx.ParamsInt64(":id"))
@@ -434,33 +432,43 @@ func EditProjectBoardTitle(ctx *context.Context, form auth.EditProjectBoardTitle
434432
} else {
435433
ctx.ServerError("GetProjectByID", err)
436434
}
437-
return
435+
return nil, nil
438436
}
439437

440438
board, err := models.GetProjectBoard(ctx.ParamsInt64(":boardID"))
441439
if err != nil {
442440
ctx.InternalServerError(err)
443-
return
441+
return nil, nil
444442
}
445443
if board.ProjectID != ctx.ParamsInt64(":id") {
446444
ctx.JSON(422, map[string]string{
447445
"message": fmt.Sprintf("ProjectBoard[%d] is not in Project[%d] as expected", board.ID, project.ID),
448446
})
449-
return
447+
return nil, nil
450448
}
451449

452450
if project.RepoID != ctx.Repo.Repository.ID {
453451
ctx.JSON(422, map[string]string{
454452
"message": fmt.Sprintf("ProjectBoard[%d] is not in Repository[%d] as expected", board.ID, ctx.Repo.Repository.ID),
455453
})
454+
return nil, nil
455+
}
456+
return project, board
457+
}
458+
459+
// EditProjectBoardTitle allows a project board's title to be updated
460+
func EditProjectBoardTitle(ctx *context.Context, form auth.EditProjectBoardTitleForm) {
461+
462+
_, board := checkProjectBoardChangePermissions(ctx)
463+
if ctx.Written() {
456464
return
457465
}
458466

459467
if form.Title != "" {
460468
board.Title = form.Title
461469
}
462470

463-
if err = models.UpdateProjectBoard(board); err != nil {
471+
if err := models.UpdateProjectBoard(board); err != nil {
464472
ctx.ServerError("UpdateProjectBoard", err)
465473
return
466474
}
@@ -470,6 +478,24 @@ func EditProjectBoardTitle(ctx *context.Context, form auth.EditProjectBoardTitle
470478
})
471479
}
472480

481+
// SetDefaultProjectBoard set default board for uncategorized issues/pulls
482+
func SetDefaultProjectBoard(ctx *context.Context) {
483+
484+
project, board := checkProjectBoardChangePermissions(ctx)
485+
if ctx.Written() {
486+
return
487+
}
488+
489+
if err := models.SetDefaultBoard(project.ID, board.ID); err != nil {
490+
ctx.InternalServerError(err)
491+
return
492+
}
493+
494+
ctx.JSON(200, map[string]interface{}{
495+
"ok": true,
496+
})
497+
}
498+
473499
// MoveIssueAcrossBoards move a card from one board to another in a project
474500
func MoveIssueAcrossBoards(ctx *context.Context) {
475501

routers/routes/macaron.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ func RegisterMacaronRoutes(m *macaron.Macaron) {
790790
m.Group("/:boardID", func() {
791791
m.Put("", bindIgnErr(auth.EditProjectBoardTitleForm{}), repo.EditProjectBoardTitle)
792792
m.Delete("", repo.DeleteProjectBoard)
793+
m.Post("/default", repo.SetDefaultProjectBoard)
793794

794795
m.Post("/:index", repo.MoveIssueAcrossBoards)
795796
})

0 commit comments

Comments
 (0)