diff --git a/server/app/boards_test.go b/server/app/boards_test.go index 0c72ec4be..1ff160477 100644 --- a/server/app/boards_test.go +++ b/server/app/boards_test.go @@ -434,6 +434,7 @@ func TestBoardCategory(t *testing.T) { Name: "Boards", }, nil) th.Store.EXPECT().GetMembersForUser("user_id").Return([]*model.BoardMember{}, nil) + th.Store.EXPECT().GetBoardsForUserAndTeam("user_id", "team_id", false).Return([]*model.Board{}, nil) th.Store.EXPECT().AddUpdateCategoryBoard("user_id", map[string]string{ "board_id_1": "default_category_id", "board_id_2": "default_category_id", diff --git a/server/app/category_boards.go b/server/app/category_boards.go index fc7d5970f..79728716f 100644 --- a/server/app/category_boards.go +++ b/server/app/category_boards.go @@ -11,6 +11,7 @@ const defaultCategoryBoards = "Boards" var errCategoryBoardsLengthMismatch = errors.New("cannot update category boards order, passed list of categories boards different size than in database") var errBoardNotFoundInCategory = errors.New("specified board ID not found in specified category ID") +var errBoardMembershipNotFound = errors.New("board membership not found for user's board") func (a *App) GetUserCategoryBoards(userID, teamID string) ([]model.CategoryBoards, error) { categoryBoards, err := a.store.GetUserCategoryBoards(userID, teamID) @@ -66,23 +67,40 @@ func (a *App) createBoardsCategory(userID, teamID string, existingCategoryBoards // once the category is created, we need to move all boards which do not // belong to any category, into this category. + boardMembers, err := a.GetMembersForUser(userID) if err != nil { return nil, fmt.Errorf("createBoardsCategory error fetching user's board memberships: %w", err) } + boardMemberByBoardID := map[string]*model.BoardMember{} + for _, boardMember := range boardMembers { + boardMemberByBoardID[boardMember.BoardID] = boardMember + } + createdCategoryBoards := &model.CategoryBoards{ Category: *createdCategory, BoardIDs: []string{}, } - for _, bm := range boardMembers { + // get user's current team's baords + userTeamBoards, err := a.GetBoardsForUserAndTeam(userID, teamID, false) + if err != nil { + return nil, fmt.Errorf("createBoardsCategory error fetching user's team's boards: %w", err) + } + + for _, board := range userTeamBoards { + boardMembership, ok := boardMemberByBoardID[board.ID] + if !ok { + return nil, fmt.Errorf("createBoardsCategory: %w", errBoardMembershipNotFound) + } + // boards with implicit access (aka synthetic membership), // should show up in LHS only when openign them explicitelly. // So we don't process any synthetic membership boards // and only add boards with explicit access to, to the the LHS, // for example, if a user explicitelly added another user to a board. - if bm.Synthetic { + if boardMembership.Synthetic { continue } @@ -90,7 +108,7 @@ func (a *App) createBoardsCategory(userID, teamID string, existingCategoryBoards for _, categoryBoard := range existingCategoryBoards { for _, boardID := range categoryBoard.BoardIDs { - if boardID == bm.BoardID { + if boardID == board.ID { belongsToCategory = true break } @@ -104,11 +122,11 @@ func (a *App) createBoardsCategory(userID, teamID string, existingCategoryBoards } if !belongsToCategory { - if err := a.AddUpdateUserCategoryBoard(teamID, userID, map[string]string{bm.BoardID: createdCategory.ID}); err != nil { + if err := a.AddUpdateUserCategoryBoard(teamID, userID, map[string]string{board.ID: createdCategory.ID}); err != nil { return nil, fmt.Errorf("createBoardsCategory failed to add category-less board to the default category, defaultCategoryID: %s, error: %w", createdCategory.ID, err) } - createdCategoryBoards.BoardIDs = append(createdCategoryBoards.BoardIDs, bm.BoardID) + createdCategoryBoards.BoardIDs = append(createdCategoryBoards.BoardIDs, board.ID) } } diff --git a/server/app/category_boards_test.go b/server/app/category_boards_test.go index 1117a7cca..e495a8ff2 100644 --- a/server/app/category_boards_test.go +++ b/server/app/category_boards_test.go @@ -21,6 +21,20 @@ func TestGetUserCategoryBoards(t *testing.T) { Name: "Boards", }, nil) + board1 := &model.Board{ + ID: "board_id_1", + } + + board2 := &model.Board{ + ID: "board_id_2", + } + + board3 := &model.Board{ + ID: "board_id_3", + } + + th.Store.EXPECT().GetBoardsForUserAndTeam("user_id", "team_id", false).Return([]*model.Board{board1, board2, board3}, nil) + th.Store.EXPECT().GetMembersForUser("user_id").Return([]*model.BoardMember{ { BoardID: "board_id_1", @@ -58,6 +72,7 @@ func TestGetUserCategoryBoards(t *testing.T) { }, nil) th.Store.EXPECT().GetMembersForUser("user_id").Return([]*model.BoardMember{}, nil) + th.Store.EXPECT().GetBoardsForUserAndTeam("user_id", "team_id", false).Return([]*model.Board{}, nil) categoryBoards, err := th.App.GetUserCategoryBoards("user_id", "team_id") assert.NoError(t, err) @@ -93,6 +108,7 @@ func TestCreateBoardsCategory(t *testing.T) { Type: "system", Name: "Boards", }, nil) + th.Store.EXPECT().GetBoardsForUserAndTeam("user_id", "team_id", false).Return([]*model.Board{}, nil) th.Store.EXPECT().GetMembersForUser("user_id").Return([]*model.BoardMember{}, nil) existingCategoryBoards := []model.CategoryBoards{} @@ -110,6 +126,7 @@ func TestCreateBoardsCategory(t *testing.T) { Type: "system", Name: "Boards", }, nil) + th.Store.EXPECT().GetBoardsForUserAndTeam("user_id", "team_id", false).Return([]*model.Board{}, nil) th.Store.EXPECT().GetMembersForUser("user_id").Return([]*model.BoardMember{ { BoardID: "board_id_1", @@ -143,6 +160,17 @@ func TestCreateBoardsCategory(t *testing.T) { Type: "system", Name: "Boards", }, nil) + + board1 := &model.Board{ + ID: "board_id_1", + } + board2 := &model.Board{ + ID: "board_id_2", + } + board3 := &model.Board{ + ID: "board_id_3", + } + th.Store.EXPECT().GetBoardsForUserAndTeam("user_id", "team_id", false).Return([]*model.Board{board1, board2, board3}, nil) th.Store.EXPECT().GetMembersForUser("user_id").Return([]*model.BoardMember{ { BoardID: "board_id_1", @@ -179,6 +207,11 @@ func TestCreateBoardsCategory(t *testing.T) { Type: "system", Name: "Boards", }, nil) + + board1 := &model.Board{ + ID: "board_id_1", + } + th.Store.EXPECT().GetBoardsForUserAndTeam("user_id", "team_id", false).Return([]*model.Board{board1}, nil) th.Store.EXPECT().GetMembersForUser("user_id").Return([]*model.BoardMember{ { BoardID: "board_id_1", diff --git a/server/app/category_test.go b/server/app/category_test.go index 9d2bc427d..34588aad5 100644 --- a/server/app/category_test.go +++ b/server/app/category_test.go @@ -375,6 +375,7 @@ func TestMoveBoardsToDefaultCategory(t *testing.T) { Type: "system", }, nil) th.Store.EXPECT().GetMembersForUser("user_id").Return([]*model.BoardMember{}, nil) + th.Store.EXPECT().GetBoardsForUserAndTeam("user_id", "team_id", false).Return([]*model.Board{}, nil) th.Store.EXPECT().AddUpdateCategoryBoard("user_id", utils.Anything).Return(nil) err := th.App.moveBoardsToDefaultCategory("user_id", "team_id", "category_id_2") diff --git a/server/app/import_test.go b/server/app/import_test.go index 7ae01f9b3..6ec7e63de 100644 --- a/server/app/import_test.go +++ b/server/app/import_test.go @@ -55,6 +55,7 @@ func TestApp_ImportArchive(t *testing.T) { ID: "boards_category_id", Name: "Boards", }, nil) + th.Store.EXPECT().GetBoardsForUserAndTeam("user", "test-team", false).Return([]*model.Board{}, nil) th.Store.EXPECT().GetMembersForUser("user").Return([]*model.BoardMember{}, nil) th.Store.EXPECT().AddUpdateCategoryBoard("user", utils.Anything).Return(nil) diff --git a/server/app/onboarding_test.go b/server/app/onboarding_test.go index 76c2044c2..29c2597e2 100644 --- a/server/app/onboarding_test.go +++ b/server/app/onboarding_test.go @@ -77,6 +77,7 @@ func TestPrepareOnboardingTour(t *testing.T) { ID: "boards_category", Name: "Boards", }, nil) + th.Store.EXPECT().GetBoardsForUserAndTeam("user_id_1", teamID, false).Return([]*model.Board{}, nil) th.Store.EXPECT().AddUpdateCategoryBoard("user_id_1", map[string]string{"board_id_2": "boards_category_id"}).Return(nil) teamID, boardID, err := th.App.PrepareOnboardingTour(userID, teamID)