This commit is contained in:
wxiaoguang 2024-05-06 13:16:08 +08:00
parent 94cb84d16e
commit 6ecdbb6aca
2 changed files with 14 additions and 29 deletions

View File

@ -5,7 +5,6 @@ package project
import (
"context"
"database/sql"
"errors"
"fmt"
"regexp"
@ -89,7 +88,7 @@ func (b *Board) GetIssues(ctx context.Context) ([]*ProjectIssue, error) {
issues := make([]*ProjectIssue, 0, 5)
if err := db.GetEngine(ctx).Where("project_id=?", b.ProjectID).
And("project_board_id=?", b.ID).
OrderBy("sorting").
OrderBy("sorting, id").
Find(&issues); err != nil {
return nil, err
}
@ -173,29 +172,19 @@ func NewBoard(ctx context.Context, board *Board) error {
if len(board.Color) != 0 && !BoardColorPattern.MatchString(board.Color) {
return fmt.Errorf("bad color code: %s", board.Color)
}
totalColumns, err := db.GetEngine(ctx).Table("project_board").
Where("project_id=?", board.ProjectID).Count()
if err != nil {
res := struct {
MaxSorting int64
ColumnCount int64
}{}
if _, err := db.GetEngine(ctx).Select("max(sorting) as MaxSorting, count(*) as ColumnCount").Table("project_board").
Where("project_id=?", board.ProjectID).Get(&res); err != nil {
return err
}
if totalColumns >= maxProjectColumns {
if res.ColumnCount >= maxProjectColumns {
return fmt.Errorf("NewBoard: maximum number of columns reached")
}
if totalColumns > 0 {
var maxSorting sql.NullByte
if _, err := db.GetEngine(ctx).Select("Max(sorting)").Table("project_board").
Where("project_id=?", board.ProjectID).Get(&maxSorting); err != nil {
return err
}
if maxSorting.Valid {
board.Sorting = int8(maxSorting.Byte) + 1
}
}
_, err = db.GetEngine(ctx).Insert(board)
board.Sorting = int8(util.Iif(res.MaxSorting > 0, res.MaxSorting+1, 0))
_, err := db.GetEngine(ctx).Insert(board)
return err
}
@ -291,7 +280,7 @@ func UpdateBoard(ctx context.Context, board *Board) error {
// GetBoards fetches all boards related to a project
func (p *Project) GetBoards(ctx context.Context) (BoardList, error) {
boards := make([]*Board, 0, 5)
if err := db.GetEngine(ctx).Where("project_id=?", p.ID).OrderBy("sorting").Find(&boards); err != nil {
if err := db.GetEngine(ctx).Where("project_id=?", p.ID).OrderBy("sorting, id").Find(&boards); err != nil {
return nil, err
}

View File

@ -5,21 +5,17 @@ package integration
import (
"net/http"
"slices"
"testing"
unit_model "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/tests"
)
func TestOrgProjectAccess(t *testing.T) {
defer tests.PrepareTestEnv(t)()
oldDisabledRepoUnits := unit_model.DisabledRepoUnits
// disable repo project unit
unit_model.DisabledRepoUnits = []unit_model.Type{unit_model.TypeProjects}
defer func() {
unit_model.DisabledRepoUnits = oldDisabledRepoUnits
}()
defer test.MockVariableValue(&unit_model.DisabledRepoUnits, append(slices.Clone(unit_model.DisabledRepoUnits), unit_model.TypeProjects))()
// repo project, 404
req := NewRequest(t, "GET", "/user2/repo1/projects")