Skip to content

Commit 6ecdbb6

Browse files
committed
fix
1 parent 94cb84d commit 6ecdbb6

File tree

2 files changed

+14
-29
lines changed

2 files changed

+14
-29
lines changed

models/project/board.go

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package project
55

66
import (
77
"context"
8-
"database/sql"
98
"errors"
109
"fmt"
1110
"regexp"
@@ -89,7 +88,7 @@ func (b *Board) GetIssues(ctx context.Context) ([]*ProjectIssue, error) {
8988
issues := make([]*ProjectIssue, 0, 5)
9089
if err := db.GetEngine(ctx).Where("project_id=?", b.ProjectID).
9190
And("project_board_id=?", b.ID).
92-
OrderBy("sorting").
91+
OrderBy("sorting, id").
9392
Find(&issues); err != nil {
9493
return nil, err
9594
}
@@ -173,29 +172,19 @@ func NewBoard(ctx context.Context, board *Board) error {
173172
if len(board.Color) != 0 && !BoardColorPattern.MatchString(board.Color) {
174173
return fmt.Errorf("bad color code: %s", board.Color)
175174
}
176-
177-
totalColumns, err := db.GetEngine(ctx).Table("project_board").
178-
Where("project_id=?", board.ProjectID).Count()
179-
if err != nil {
175+
res := struct {
176+
MaxSorting int64
177+
ColumnCount int64
178+
}{}
179+
if _, err := db.GetEngine(ctx).Select("max(sorting) as MaxSorting, count(*) as ColumnCount").Table("project_board").
180+
Where("project_id=?", board.ProjectID).Get(&res); err != nil {
180181
return err
181182
}
182-
183-
if totalColumns >= maxProjectColumns {
183+
if res.ColumnCount >= maxProjectColumns {
184184
return fmt.Errorf("NewBoard: maximum number of columns reached")
185185
}
186-
187-
if totalColumns > 0 {
188-
var maxSorting sql.NullByte
189-
if _, err := db.GetEngine(ctx).Select("Max(sorting)").Table("project_board").
190-
Where("project_id=?", board.ProjectID).Get(&maxSorting); err != nil {
191-
return err
192-
}
193-
if maxSorting.Valid {
194-
board.Sorting = int8(maxSorting.Byte) + 1
195-
}
196-
}
197-
198-
_, err = db.GetEngine(ctx).Insert(board)
186+
board.Sorting = int8(util.Iif(res.MaxSorting > 0, res.MaxSorting+1, 0))
187+
_, err := db.GetEngine(ctx).Insert(board)
199188
return err
200189
}
201190

@@ -291,7 +280,7 @@ func UpdateBoard(ctx context.Context, board *Board) error {
291280
// GetBoards fetches all boards related to a project
292281
func (p *Project) GetBoards(ctx context.Context) (BoardList, error) {
293282
boards := make([]*Board, 0, 5)
294-
if err := db.GetEngine(ctx).Where("project_id=?", p.ID).OrderBy("sorting").Find(&boards); err != nil {
283+
if err := db.GetEngine(ctx).Where("project_id=?", p.ID).OrderBy("sorting, id").Find(&boards); err != nil {
295284
return nil, err
296285
}
297286

tests/integration/org_project_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,17 @@ package integration
55

66
import (
77
"net/http"
8+
"slices"
89
"testing"
910

1011
unit_model "code.gitea.io/gitea/models/unit"
12+
"code.gitea.io/gitea/modules/test"
1113
"code.gitea.io/gitea/tests"
1214
)
1315

1416
func TestOrgProjectAccess(t *testing.T) {
1517
defer tests.PrepareTestEnv(t)()
16-
17-
oldDisabledRepoUnits := unit_model.DisabledRepoUnits
18-
// disable repo project unit
19-
unit_model.DisabledRepoUnits = []unit_model.Type{unit_model.TypeProjects}
20-
defer func() {
21-
unit_model.DisabledRepoUnits = oldDisabledRepoUnits
22-
}()
18+
defer test.MockVariableValue(&unit_model.DisabledRepoUnits, append(slices.Clone(unit_model.DisabledRepoUnits), unit_model.TypeProjects))()
2319

2420
// repo project, 404
2521
req := NewRequest(t, "GET", "/user2/repo1/projects")

0 commit comments

Comments
 (0)