mirror of
https://github.com/mattermost/focalboard.git
synced 2024-12-24 13:43:12 +02:00
Adding only boards with explicit access to default category
This commit is contained in:
parent
4051e1eb05
commit
733dca08b6
@ -61,10 +61,9 @@ 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.
|
||||
|
||||
userBoards, err := a.GetBoardsForUserAndTeam(userID, teamID, false)
|
||||
boardMembers, err := a.GetMembersForUser(userID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("createBoardsCategory error fetching user's team's boards: %w", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
createdCategoryBoards := &model.CategoryBoards{
|
||||
@ -72,12 +71,21 @@ func (a *App) createBoardsCategory(userID, teamID string, existingCategoryBoards
|
||||
BoardIDs: []string{},
|
||||
}
|
||||
|
||||
for _, board := range userBoards {
|
||||
for _, bm := range boardMembers {
|
||||
// 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 {
|
||||
continue
|
||||
}
|
||||
|
||||
belongsToCategory := false
|
||||
|
||||
for _, categoryBoard := range existingCategoryBoards {
|
||||
for _, boardID := range categoryBoard.BoardIDs {
|
||||
if boardID == board.ID {
|
||||
if boardID == bm.BoardID {
|
||||
belongsToCategory = true
|
||||
break
|
||||
}
|
||||
@ -91,11 +99,11 @@ func (a *App) createBoardsCategory(userID, teamID string, existingCategoryBoards
|
||||
}
|
||||
|
||||
if !belongsToCategory {
|
||||
if err := a.AddUpdateUserCategoryBoard(teamID, userID, createdCategory.ID, board.ID); err != nil {
|
||||
if err := a.AddUpdateUserCategoryBoard(teamID, userID, createdCategory.ID, bm.BoardID); 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, board.ID)
|
||||
createdCategoryBoards.BoardIDs = append(createdCategoryBoards.BoardIDs, bm.BoardID)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,3 +80,129 @@ func TestGetUserCategoryBoards(t *testing.T) {
|
||||
assert.Equal(t, 2, len(categoryBoards[0].BoardIDs))
|
||||
})
|
||||
}
|
||||
|
||||
func TestCreateBoardsCategory(t *testing.T) {
|
||||
th, tearDown := SetupTestHelper(t)
|
||||
defer tearDown()
|
||||
|
||||
t.Run("user doesn't have any boards - implicit or explicit", func(t *testing.T) {
|
||||
th.Store.EXPECT().CreateCategory(utils.Anything).Return(nil)
|
||||
th.Store.EXPECT().GetCategory(utils.Anything).Return(&model.Category{
|
||||
ID: "boards_category_id",
|
||||
Type: "system",
|
||||
Name: "Boards",
|
||||
}, nil)
|
||||
th.Store.EXPECT().GetMembersForUser("user_id").Return([]*model.BoardMember{}, nil)
|
||||
|
||||
existingCategoryBoards := []model.CategoryBoards{}
|
||||
boardsCategory, err := th.App.createBoardsCategory("user_id", "team_id", existingCategoryBoards)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, boardsCategory)
|
||||
assert.Equal(t, "Boards", boardsCategory.Name)
|
||||
assert.Equal(t, 0, len(boardsCategory.BoardIDs))
|
||||
})
|
||||
|
||||
t.Run("user has implicit access to some board", func(t *testing.T) {
|
||||
th.Store.EXPECT().CreateCategory(utils.Anything).Return(nil)
|
||||
th.Store.EXPECT().GetCategory(utils.Anything).Return(&model.Category{
|
||||
ID: "boards_category_id",
|
||||
Type: "system",
|
||||
Name: "Boards",
|
||||
}, nil)
|
||||
th.Store.EXPECT().GetMembersForUser("user_id").Return([]*model.BoardMember{
|
||||
{
|
||||
BoardID: "board_id_1",
|
||||
Synthetic: true,
|
||||
},
|
||||
{
|
||||
BoardID: "board_id_2",
|
||||
Synthetic: true,
|
||||
},
|
||||
{
|
||||
BoardID: "board_id_3",
|
||||
Synthetic: true,
|
||||
},
|
||||
}, nil)
|
||||
|
||||
existingCategoryBoards := []model.CategoryBoards{}
|
||||
boardsCategory, err := th.App.createBoardsCategory("user_id", "team_id", existingCategoryBoards)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, boardsCategory)
|
||||
assert.Equal(t, "Boards", boardsCategory.Name)
|
||||
|
||||
// there should still be no boards in the default category as
|
||||
// the user had only implicit access to boards
|
||||
assert.Equal(t, 0, len(boardsCategory.BoardIDs))
|
||||
})
|
||||
|
||||
t.Run("user has explicit access to some board", func(t *testing.T) {
|
||||
th.Store.EXPECT().CreateCategory(utils.Anything).Return(nil)
|
||||
th.Store.EXPECT().GetCategory(utils.Anything).Return(&model.Category{
|
||||
ID: "boards_category_id",
|
||||
Type: "system",
|
||||
Name: "Boards",
|
||||
}, nil)
|
||||
th.Store.EXPECT().GetMembersForUser("user_id").Return([]*model.BoardMember{
|
||||
{
|
||||
BoardID: "board_id_1",
|
||||
Synthetic: false,
|
||||
},
|
||||
{
|
||||
BoardID: "board_id_2",
|
||||
Synthetic: false,
|
||||
},
|
||||
{
|
||||
BoardID: "board_id_3",
|
||||
Synthetic: false,
|
||||
},
|
||||
}, nil)
|
||||
th.Store.EXPECT().AddUpdateCategoryBoard("user_id", "boards_category_id", "board_id_1").Return(nil)
|
||||
th.Store.EXPECT().AddUpdateCategoryBoard("user_id", "boards_category_id", "board_id_2").Return(nil)
|
||||
th.Store.EXPECT().AddUpdateCategoryBoard("user_id", "boards_category_id", "board_id_3").Return(nil)
|
||||
|
||||
existingCategoryBoards := []model.CategoryBoards{}
|
||||
boardsCategory, err := th.App.createBoardsCategory("user_id", "team_id", existingCategoryBoards)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, boardsCategory)
|
||||
assert.Equal(t, "Boards", boardsCategory.Name)
|
||||
|
||||
// since user has explicit access to three boards,
|
||||
// they should all end up in the default category
|
||||
assert.Equal(t, 3, len(boardsCategory.BoardIDs))
|
||||
})
|
||||
|
||||
t.Run("user has both implicit and explicit access to some board", func(t *testing.T) {
|
||||
th.Store.EXPECT().CreateCategory(utils.Anything).Return(nil)
|
||||
th.Store.EXPECT().GetCategory(utils.Anything).Return(&model.Category{
|
||||
ID: "boards_category_id",
|
||||
Type: "system",
|
||||
Name: "Boards",
|
||||
}, nil)
|
||||
th.Store.EXPECT().GetMembersForUser("user_id").Return([]*model.BoardMember{
|
||||
{
|
||||
BoardID: "board_id_1",
|
||||
Synthetic: false,
|
||||
},
|
||||
{
|
||||
BoardID: "board_id_2",
|
||||
Synthetic: true,
|
||||
},
|
||||
{
|
||||
BoardID: "board_id_3",
|
||||
Synthetic: true,
|
||||
},
|
||||
}, nil)
|
||||
th.Store.EXPECT().AddUpdateCategoryBoard("user_id", "boards_category_id", "board_id_1").Return(nil)
|
||||
|
||||
existingCategoryBoards := []model.CategoryBoards{}
|
||||
boardsCategory, err := th.App.createBoardsCategory("user_id", "team_id", existingCategoryBoards)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, boardsCategory)
|
||||
assert.Equal(t, "Boards", boardsCategory.Name)
|
||||
|
||||
// there was only one explicit board access,
|
||||
// and so only that one should end up in the
|
||||
// default category
|
||||
assert.Equal(t, 1, len(boardsCategory.BoardIDs))
|
||||
})
|
||||
}
|
||||
|
@ -264,6 +264,9 @@ func (s *SQLStore) getBoardsForUserAndTeam(db sq.BaseRunner, userID, teamID stri
|
||||
})
|
||||
}
|
||||
|
||||
q, p, _ := query.ToSql()
|
||||
s.logger.Error(fmt.Sprintf("%s %v", q, p))
|
||||
|
||||
rows, err := query.Query()
|
||||
if err != nil {
|
||||
s.logger.Error(`getBoardsForUserAndTeam ERROR`, mlog.Err(err))
|
||||
|
Loading…
Reference in New Issue
Block a user