Fixed bug where boards would move to category of a different team (#4284)
This commit is contained in:
parent
60cafbe6eb
commit
e075f408d3
6 changed files with 60 additions and 5 deletions
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue