MM-63728: simplify category store with graphql gone (#30848)
* move category permissions to api In https://github.com/mattermost/mattermost/pull/21038, we changed the behaviour of the channel category store to filter out deleted teams and teams for which the user was not a member. This was necessary in part due to querying multiple teams via GraphQL. With GraphQL no longer supported, let's move the permissions to the API instead and remove the `JOIN` to filter out teams in the store. Note that we /don't/ prevent access to deleted teams. For better or worse, deleted teams remain largely accessible via other API endpoints anyway. * remove ExcludeTeam / GraphQL support As part of https://github.com/mattermost/mattermost/pull/20353, we added `ExcludeTeam` and the associated logic to support a GraphQL API. With GraphQL no longer supported, let's simplify this logic and remove the filtering and associated complexity. * Fix shadow variable declaration in channel_store_categories.go Fixed golangci-lint error by reusing existing err variable rather than shadowing it. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix build issue * Remove SidebarCategorySearchOpts and simplify API to use teamID string Per code review feedback, this change removes the SidebarCategorySearchOpts struct entirely since the Type field was never used in the store implementation. All methods now accept a simple teamID string parameter instead of the struct, which simplifies the API and makes the code clearer. Changes: - Remove SidebarCategorySearchOpts struct from store.go - Update CreateInitialSidebarCategories and GetSidebarCategories signatures - Update all implementations (sqlstore, retrylayer, timerlayer, mocks) - Update all callers to pass teamID string directly - Clean up unused imports 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b69412d23f
Коммит
dcc72c4c61
@@ -1193,11 +1193,11 @@ func (s *RetryLayerChannelStore) CreateDirectChannel(ctx request.CTX, userID *mo
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerChannelStore) CreateInitialSidebarCategories(c request.CTX, userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
|
||||
func (s *RetryLayerChannelStore) CreateInitialSidebarCategories(c request.CTX, userID string, teamID string) (*model.OrderedSidebarCategories, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.ChannelStore.CreateInitialSidebarCategories(c, userID, opts)
|
||||
result, err := s.ChannelStore.CreateInitialSidebarCategories(c, userID, teamID)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
@@ -2354,11 +2354,11 @@ func (s *RetryLayerChannelStore) GetPublicChannelsForTeam(teamID string, offset
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerChannelStore) GetSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
|
||||
func (s *RetryLayerChannelStore) GetSidebarCategories(userID string, teamID string) (*model.OrderedSidebarCategories, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.ChannelStore.GetSidebarCategories(userID, opts)
|
||||
result, err := s.ChannelStore.GetSidebarCategories(userID, teamID)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -16,27 +16,18 @@ import (
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
)
|
||||
|
||||
func (s SqlChannelStore) CreateInitialSidebarCategories(c request.CTX, userId string, opts *store.SidebarCategorySearchOpts) (_ *model.OrderedSidebarCategories, err error) {
|
||||
func (s SqlChannelStore) CreateInitialSidebarCategories(c request.CTX, userId string, teamID string) (_ *model.OrderedSidebarCategories, err error) {
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "CreateInitialSidebarCategories: begin_transaction")
|
||||
}
|
||||
defer finalizeTransactionX(transaction, &err)
|
||||
|
||||
teamsWithExclude, err := s.SqlStore.stores.team.GetTeamsForUser(c, userId, opts.TeamID, false)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "CreateInitialSidebarCategories: GetTeamsForUser")
|
||||
}
|
||||
excludedTeamIDs := make([]string, 0, len(teamsWithExclude))
|
||||
for _, tm := range teamsWithExclude {
|
||||
excludedTeamIDs = append(excludedTeamIDs, tm.TeamId)
|
||||
}
|
||||
|
||||
if err = s.createInitialSidebarCategoriesT(transaction, userId, excludedTeamIDs, opts); err != nil {
|
||||
if err = s.createInitialSidebarCategoriesT(transaction, userId, teamID); err != nil {
|
||||
return nil, errors.Wrap(err, "CreateInitialSidebarCategories: createInitialSidebarCategoriesT")
|
||||
}
|
||||
|
||||
oc, err := s.getSidebarCategoriesT(transaction, userId, opts)
|
||||
oc, err := s.getSidebarCategoriesT(transaction, userId, teamID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "CreateInitialSidebarCategories: getSidebarCategoriesT")
|
||||
}
|
||||
@@ -48,9 +39,9 @@ func (s SqlChannelStore) CreateInitialSidebarCategories(c request.CTX, userId st
|
||||
return oc, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) createInitialSidebarCategoriesT(transaction *sqlxTxWrapper, userId string, excludedTeamIDs []string, opts *store.SidebarCategorySearchOpts) error {
|
||||
func (s SqlChannelStore) createInitialSidebarCategoriesT(transaction *sqlxTxWrapper, userId, teamId string) error {
|
||||
query := s.getQueryBuilder().
|
||||
Select("SidebarCategories.Type, SidebarCategories.TeamId").
|
||||
Select("SidebarCategories.Type").
|
||||
From("SidebarCategories").
|
||||
Where(sq.Eq{
|
||||
"SidebarCategories.UserId": userId,
|
||||
@@ -59,34 +50,18 @@ func (s SqlChannelStore) createInitialSidebarCategoriesT(transaction *sqlxTxWrap
|
||||
model.SidebarCategoryChannels,
|
||||
model.SidebarCategoryDirectMessages,
|
||||
},
|
||||
"SidebarCategories.TeamId": teamId,
|
||||
})
|
||||
|
||||
if !opts.ExcludeTeam {
|
||||
query = query.Where(sq.Eq{"SidebarCategories.TeamId": opts.TeamID})
|
||||
} else {
|
||||
query = query.Where(sq.NotEq{"SidebarCategories.TeamId": opts.TeamID})
|
||||
}
|
||||
|
||||
selectQuery, selectParams, err := query.ToSql()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "createInitialSidebarCategoriesT_Tosql")
|
||||
}
|
||||
|
||||
existingTypes := []struct {
|
||||
Type model.SidebarCategoryType
|
||||
TeamId string
|
||||
}{}
|
||||
err = transaction.Select(&existingTypes, selectQuery, selectParams...)
|
||||
existingTypes := []model.SidebarCategoryType{}
|
||||
err := transaction.SelectBuilder(&existingTypes, query)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "createInitialSidebarCategoriesT: failed to select existing categories")
|
||||
}
|
||||
|
||||
hasCategoryOfType := make(map[model.SidebarCategoryType]map[string]bool, len(existingTypes))
|
||||
hasCategoryOfType := make(map[model.SidebarCategoryType]bool, len(existingTypes))
|
||||
for _, existingType := range existingTypes {
|
||||
if hasCategoryOfType[existingType.Type] == nil {
|
||||
hasCategoryOfType[existingType.Type] = make(map[string]bool)
|
||||
hasCategoryOfType[existingType.Type][existingType.TeamId] = true
|
||||
}
|
||||
hasCategoryOfType[existingType] = true
|
||||
}
|
||||
|
||||
insertBuilder := s.getQueryBuilder().Insert("SidebarCategories").
|
||||
@@ -94,71 +69,33 @@ func (s SqlChannelStore) createInitialSidebarCategoriesT(transaction *sqlxTxWrap
|
||||
|
||||
hasInsert := false
|
||||
|
||||
getRequiredTeamIDs := func(category model.SidebarCategoryType, opts *store.SidebarCategorySearchOpts) []string {
|
||||
// if category == nil - nothing
|
||||
// if not exclude - just that team
|
||||
// otherwise get all teams excluding that team
|
||||
// if != nil - then partial
|
||||
// if not exclude, and team exists in map then skip.
|
||||
// otherwise, get all teams excluding that team, subtract all items from map.
|
||||
if hasCategoryOfType[category] == nil {
|
||||
// If not exclude, do for only single team
|
||||
// if exclude, get all teams, excluding that team
|
||||
if !opts.ExcludeTeam {
|
||||
return []string{opts.TeamID}
|
||||
}
|
||||
return excludedTeamIDs
|
||||
}
|
||||
mapEntry := hasCategoryOfType[category]
|
||||
if !opts.ExcludeTeam && mapEntry[opts.TeamID] {
|
||||
// continue, nothing to do since entry already exists.
|
||||
} else {
|
||||
for i, tID := range excludedTeamIDs {
|
||||
if mapEntry[tID] {
|
||||
// remove from slice
|
||||
copy(excludedTeamIDs[i:], excludedTeamIDs[i+1:])
|
||||
excludedTeamIDs[len(excludedTeamIDs)-1] = ""
|
||||
excludedTeamIDs = excludedTeamIDs[:len(excludedTeamIDs)-1]
|
||||
}
|
||||
}
|
||||
return excludedTeamIDs
|
||||
}
|
||||
return []string{}
|
||||
}
|
||||
|
||||
teamIDs := getRequiredTeamIDs(model.SidebarCategoryFavorites, opts)
|
||||
for _, teamID := range teamIDs {
|
||||
if !hasCategoryOfType[model.SidebarCategoryFavorites] {
|
||||
// Use deterministic IDs for default categories to prevent potentially creating multiple copies of a default category
|
||||
favoritesCategoryId := fmt.Sprintf("%s_%s_%s", model.SidebarCategoryFavorites, userId, teamID)
|
||||
favoritesCategoryId := fmt.Sprintf("%s_%s_%s", model.SidebarCategoryFavorites, userId, teamId)
|
||||
// Create the SidebarChannels first since there's more opportunity for something to fail here
|
||||
if err := s.migrateFavoritesToSidebarT(transaction, userId, teamID, favoritesCategoryId); err != nil {
|
||||
err = s.migrateFavoritesToSidebarT(transaction, userId, teamId, favoritesCategoryId)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "createInitialSidebarCategoriesT: failed to migrate favorites to sidebar")
|
||||
}
|
||||
|
||||
insertBuilder = insertBuilder.Values(favoritesCategoryId, userId, teamID, model.DefaultSidebarSortOrderFavorites, model.SidebarCategorySortDefault, model.SidebarCategoryFavorites, "Favorites" /* This will be retranslated by the client into the user's locale */, false, false)
|
||||
insertBuilder = insertBuilder.Values(favoritesCategoryId, userId, teamId, model.DefaultSidebarSortOrderFavorites, model.SidebarCategorySortDefault, model.SidebarCategoryFavorites, "Favorites" /* This will be retranslated by the client into the user's locale */, false, false)
|
||||
hasInsert = true
|
||||
}
|
||||
|
||||
teamIDs = getRequiredTeamIDs(model.SidebarCategoryChannels, opts)
|
||||
for _, teamID := range teamIDs {
|
||||
channelsCategoryId := fmt.Sprintf("%s_%s_%s", model.SidebarCategoryChannels, userId, teamID)
|
||||
insertBuilder = insertBuilder.Values(channelsCategoryId, userId, teamID, model.DefaultSidebarSortOrderChannels, model.SidebarCategorySortDefault, model.SidebarCategoryChannels, "Channels" /* This will be retranslated by the client into the user's locale */, false, false)
|
||||
if !hasCategoryOfType[model.SidebarCategoryChannels] {
|
||||
channelsCategoryId := fmt.Sprintf("%s_%s_%s", model.SidebarCategoryChannels, userId, teamId)
|
||||
insertBuilder = insertBuilder.Values(channelsCategoryId, userId, teamId, model.DefaultSidebarSortOrderChannels, model.SidebarCategorySortDefault, model.SidebarCategoryChannels, "Channels" /* This will be retranslated by the client into the user's locale */, false, false)
|
||||
hasInsert = true
|
||||
}
|
||||
|
||||
teamIDs = getRequiredTeamIDs(model.SidebarCategoryDirectMessages, opts)
|
||||
for _, teamID := range teamIDs {
|
||||
directMessagesCategoryId := fmt.Sprintf("%s_%s_%s", model.SidebarCategoryDirectMessages, userId, teamID)
|
||||
insertBuilder = insertBuilder.Values(directMessagesCategoryId, userId, teamID, model.DefaultSidebarSortOrderDMs, model.SidebarCategorySortRecent, model.SidebarCategoryDirectMessages, "Direct Messages" /* This will be retranslated by the client into the user's locale */, false, false)
|
||||
if !hasCategoryOfType[model.SidebarCategoryDirectMessages] {
|
||||
directMessagesCategoryId := fmt.Sprintf("%s_%s_%s", model.SidebarCategoryDirectMessages, userId, teamId)
|
||||
insertBuilder = insertBuilder.Values(directMessagesCategoryId, userId, teamId, model.DefaultSidebarSortOrderDMs, model.SidebarCategorySortRecent, model.SidebarCategoryDirectMessages, "Direct Messages" /* This will be retranslated by the client into the user's locale */, false, false)
|
||||
hasInsert = true
|
||||
}
|
||||
|
||||
if hasInsert {
|
||||
sql, args, err := insertBuilder.ToSql()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "insertSidebarCategories_Tosql")
|
||||
}
|
||||
_, err = transaction.Exec(sql, args...)
|
||||
_, err = transaction.ExecBuilder(insertBuilder)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "createInitialSidebarCategoriesT: failed to insert categories")
|
||||
}
|
||||
@@ -300,11 +237,7 @@ func (s SqlChannelStore) CreateSidebarCategory(userId, teamId string, newCategor
|
||||
|
||||
defer finalizeTransactionX(transaction, &err)
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
categoriesWithOrder, err := s.getSidebarCategoriesT(transaction, userId, opts)
|
||||
categoriesWithOrder, err := s.getSidebarCategoriesT(transaction, userId, teamId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if len(categoriesWithOrder.Categories) == 0 {
|
||||
@@ -590,7 +523,7 @@ func (s SqlChannelStore) getSidebarCategoryT(db sqlxExecutor, categoryId string)
|
||||
return s.completePopulatingCategoryT(db, result)
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) getSidebarCategoriesT(db sqlxExecutor, userId string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
|
||||
func (s SqlChannelStore) getSidebarCategoriesT(db sqlxExecutor, userId, teamId string) (*model.OrderedSidebarCategories, error) {
|
||||
oc := model.OrderedSidebarCategories{
|
||||
Categories: make(model.SidebarCategoriesWithChannels, 0),
|
||||
Order: make([]string, 0),
|
||||
@@ -600,35 +533,18 @@ func (s SqlChannelStore) getSidebarCategoriesT(db sqlxExecutor, userId string, o
|
||||
query := s.sidebarCategorySelectQuery.
|
||||
Columns("SidebarChannels.ChannelId").
|
||||
LeftJoin("SidebarChannels ON SidebarChannels.CategoryId=SidebarCategories.Id").
|
||||
InnerJoin("Teams ON Teams.Id=SidebarCategories.TeamId").
|
||||
InnerJoin("TeamMembers ON TeamMembers.TeamId=SidebarCategories.TeamId").
|
||||
Where(sq.And{
|
||||
sq.Eq{"TeamMembers.UserId": userId},
|
||||
sq.Eq{"TeamMembers.DeleteAt": 0},
|
||||
sq.Eq{"Teams.DeleteAt": 0},
|
||||
}).
|
||||
Where(sq.And{
|
||||
sq.Eq{"SidebarCategories.UserId": userId},
|
||||
sq.Eq{"SidebarCategories.TeamId": teamId},
|
||||
}).
|
||||
OrderBy("SidebarCategories.SortOrder ASC, SidebarChannels.SortOrder ASC")
|
||||
|
||||
if opts.ExcludeTeam {
|
||||
query = query.Where(sq.NotEq{"SidebarCategories.TeamId": opts.TeamID})
|
||||
} else {
|
||||
query = query.Where(sq.Eq{"SidebarCategories.TeamId": opts.TeamID})
|
||||
}
|
||||
|
||||
if opts.Type != "" {
|
||||
query = query.Where(sq.Eq{"SidebarCategories.Type": opts.Type})
|
||||
}
|
||||
|
||||
sql, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "sidebar_categories_tosql")
|
||||
}
|
||||
|
||||
if err := db.Select(&categories, sql, args...); err != nil {
|
||||
return nil, errors.Wrap(err, fmt.Sprintf("failed to get categories for userId=%s, teamId=%s", userId, opts.TeamID))
|
||||
return nil, errors.Wrap(err, fmt.Sprintf("failed to get categories for userId=%s, teamId=%s", userId, teamId))
|
||||
}
|
||||
|
||||
for _, category := range categories {
|
||||
@@ -660,15 +576,11 @@ func (s SqlChannelStore) getSidebarCategoriesT(db sqlxExecutor, userId string, o
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetSidebarCategoriesForTeamForUser(userId, teamId string) (*model.OrderedSidebarCategories, error) {
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
return s.getSidebarCategoriesT(s.GetReplica(), userId, opts)
|
||||
return s.getSidebarCategoriesT(s.GetReplica(), userId, teamId)
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
|
||||
return s.getSidebarCategoriesT(s.GetReplica(), userID, opts)
|
||||
func (s SqlChannelStore) GetSidebarCategories(userID string, teamID string) (*model.OrderedSidebarCategories, error) {
|
||||
return s.getSidebarCategoriesT(s.GetReplica(), userID, teamID)
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetSidebarCategoryOrder(userId, teamId string) ([]string, error) {
|
||||
|
||||
@@ -289,9 +289,9 @@ type ChannelStore interface {
|
||||
MigrateChannelMembers(fromChannelID string, fromUserID string) (map[string]string, error)
|
||||
ResetAllChannelSchemes() error
|
||||
ClearAllCustomRoleAssignments() error
|
||||
CreateInitialSidebarCategories(c request.CTX, userID string, opts *SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error)
|
||||
CreateInitialSidebarCategories(c request.CTX, userID string, teamID string) (*model.OrderedSidebarCategories, error)
|
||||
GetSidebarCategoriesForTeamForUser(userID, teamID string) (*model.OrderedSidebarCategories, error)
|
||||
GetSidebarCategories(userID string, opts *SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error)
|
||||
GetSidebarCategories(userID string, teamID string) (*model.OrderedSidebarCategories, error)
|
||||
GetSidebarCategory(categoryID string) (*model.SidebarCategoryWithChannels, error)
|
||||
GetSidebarCategoryOrder(userID, teamID string) ([]string, error)
|
||||
CreateSidebarCategory(userID, teamID string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, error)
|
||||
@@ -1220,14 +1220,6 @@ type PostReminderMetadata struct {
|
||||
Username string
|
||||
}
|
||||
|
||||
// SidebarCategorySearchOpts contains the options for a graphQL query
|
||||
// to get the sidebar categories.
|
||||
type SidebarCategorySearchOpts struct {
|
||||
TeamID string
|
||||
ExcludeTeam bool
|
||||
Type model.SidebarCategoryType
|
||||
}
|
||||
|
||||
type ThreadMembershipImportData struct {
|
||||
// LastViewed is the timestamp to set the LastViewed field to.
|
||||
LastViewed int64
|
||||
|
||||
@@ -63,12 +63,7 @@ func testCreateInitialSidebarCategories(t *testing.T, rctx request.CTX, ss store
|
||||
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
assert.NoError(t, nErr)
|
||||
require.Len(t, res.Categories, 3)
|
||||
assert.Equal(t, model.SidebarCategoryFavorites, res.Categories[0].Type)
|
||||
@@ -86,15 +81,11 @@ func testCreateInitialSidebarCategories(t *testing.T, rctx request.CTX, ss store
|
||||
|
||||
team := setupTeam(t, rctx, ss, userID, userID2)
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(rctx, userID2, opts)
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(rctx, userID2, team.Id)
|
||||
assert.NoError(t, nErr)
|
||||
assert.Len(t, res.Categories, 3)
|
||||
assert.Equal(t, model.SidebarCategoryFavorites, res.Categories[0].Type)
|
||||
@@ -112,19 +103,11 @@ func testCreateInitialSidebarCategories(t *testing.T, rctx request.CTX, ss store
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
team2 := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
opts = &store.SidebarCategorySearchOpts{
|
||||
TeamID: team2.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(rctx, userID, team2.Id)
|
||||
assert.NoError(t, nErr)
|
||||
assert.Len(t, res.Categories, 3)
|
||||
assert.Equal(t, model.SidebarCategoryFavorites, res.Categories[0].Type)
|
||||
@@ -141,11 +124,7 @@ func testCreateInitialSidebarCategories(t *testing.T, rctx request.CTX, ss store
|
||||
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -154,7 +133,7 @@ func testCreateInitialSidebarCategories(t *testing.T, rctx request.CTX, ss store
|
||||
require.Equal(t, res, initialCategories)
|
||||
|
||||
// Calling CreateInitialSidebarCategories a second time shouldn't create any new categories
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
assert.NoError(t, nErr)
|
||||
assert.NotEmpty(t, res)
|
||||
|
||||
@@ -176,11 +155,7 @@ func testCreateInitialSidebarCategories(t *testing.T, rctx request.CTX, ss store
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
_, _ = ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
_, _ = ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -234,11 +209,8 @@ func testCreateInitialSidebarCategories(t *testing.T, rctx request.CTX, ss store
|
||||
require.NoError(t, nErr)
|
||||
|
||||
// Create the categories
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
categories, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
// Create the categories
|
||||
categories, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
assert.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
@@ -303,11 +275,8 @@ func testCreateInitialSidebarCategories(t *testing.T, rctx request.CTX, ss store
|
||||
require.NoError(t, nErr)
|
||||
|
||||
// Create the categories
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
categories, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
// Create the categories
|
||||
categories, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
assert.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
@@ -371,11 +340,8 @@ func testCreateInitialSidebarCategories(t *testing.T, rctx request.CTX, ss store
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create the categories
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
categories, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
// Create the categories
|
||||
categories, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
assert.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
@@ -420,11 +386,8 @@ func testCreateInitialSidebarCategories(t *testing.T, rctx request.CTX, ss store
|
||||
require.NoError(t, nErr)
|
||||
|
||||
// Create the categories
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
categories, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
// Create the categories
|
||||
categories, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
assert.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
@@ -461,11 +424,7 @@ func testCreateSidebarCategory(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -491,11 +450,7 @@ func testCreateSidebarCategory(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -532,11 +487,7 @@ func testCreateSidebarCategory(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
userID := model.NewId()
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -574,11 +525,7 @@ func testCreateSidebarCategory(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
userID := model.NewId()
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -639,11 +586,7 @@ func testCreateSidebarCategory(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
// Create the category
|
||||
@@ -676,11 +619,7 @@ func testGetSidebarCategory(t *testing.T, rctx request.CTX, ss store.Store, s Sq
|
||||
channelID2 := model.NewId()
|
||||
channelID3 := model.NewId()
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -710,11 +649,8 @@ func testGetSidebarCategory(t *testing.T, rctx request.CTX, ss store.Store, s Sq
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
// Create the initial categories and find the channels category
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
// Create the initial categories and find the channels category
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -778,11 +714,8 @@ func testGetSidebarCategory(t *testing.T, rctx request.CTX, ss store.Store, s Sq
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
// Create the initial categories and find the channels category
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
// Create the initial categories and find the channels category
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -820,12 +753,8 @@ func testGetSidebarCategory(t *testing.T, rctx request.CTX, ss store.Store, s Sq
|
||||
userID := model.NewId()
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
// Create the initial categories and find the channels category
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -888,11 +817,8 @@ func testGetSidebarCategory(t *testing.T, rctx request.CTX, ss store.Store, s Sq
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
// Create the initial categories and find the DMs category
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
// Create the initial categories and find the DMs category
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -933,11 +859,8 @@ func testGetSidebarCategory(t *testing.T, rctx request.CTX, ss store.Store, s Sq
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
// Create the initial categories and find the DMs category
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
// Create the initial categories and find the DMs category
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -975,11 +898,8 @@ func testGetSidebarCategory(t *testing.T, rctx request.CTX, ss store.Store, s Sq
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
// Create the initial categories and find the DMs category
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
// Create the initial categories and find the DMs category
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -1009,11 +929,7 @@ func testGetSidebarCategory(t *testing.T, rctx request.CTX, ss store.Store, s Sq
|
||||
|
||||
// Create another team and assign the DM to a custom category on that team
|
||||
otherTeam := setupTeam(t, rctx, ss, userID)
|
||||
opts = &store.SidebarCategorySearchOpts{
|
||||
TeamID: otherTeam.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(rctx, userID, otherTeam.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -1040,11 +956,7 @@ func testGetSidebarCategories(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
userID := model.NewId()
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -1074,66 +986,6 @@ func testGetSidebarCategories(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
assert.Equal(t, gotCategory.Channels, res.Categories[1].Channels)
|
||||
assert.Equal(t, channelIds, res.Categories[1].Channels)
|
||||
})
|
||||
t.Run("should not return categories for teams deleted, or no longer a member", func(t *testing.T) {
|
||||
userID := model.NewId()
|
||||
|
||||
teamMember1 := setupTeam(t, rctx, ss, userID)
|
||||
teamMember2 := setupTeam(t, rctx, ss, userID)
|
||||
teamDeleted := setupTeam(t, rctx, ss, userID)
|
||||
teamDeleted.DeleteAt = model.GetMillis()
|
||||
ss.Team().Update(teamDeleted)
|
||||
teamNotMember := setupTeam(t, rctx, ss)
|
||||
teamDeletedMember := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
members, err := ss.Team().GetMembersByIds(teamDeletedMember.Id, []string{userID}, nil)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, members)
|
||||
member := members[0]
|
||||
member.DeleteAt = model.GetMillis()
|
||||
ss.Team().UpdateMember(rctx, member)
|
||||
|
||||
teamIds := []string{
|
||||
teamMember1.Id,
|
||||
teamMember2.Id,
|
||||
teamDeleted.Id,
|
||||
teamNotMember.Id,
|
||||
teamDeletedMember.Id,
|
||||
}
|
||||
|
||||
for _, id := range teamIds {
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, &store.SidebarCategorySearchOpts{TeamID: id})
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
}
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamMember1.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
|
||||
// Team member and not exclude
|
||||
res, err := ss.Channel().GetSidebarCategories(userID, opts)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 3, len(res.Categories))
|
||||
|
||||
// No team member and not exclude
|
||||
opts.TeamID = teamDeleted.Id
|
||||
res, err = ss.Channel().GetSidebarCategories(userID, opts)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 0, len(res.Categories))
|
||||
|
||||
// No team member and exclude
|
||||
opts.ExcludeTeam = true
|
||||
res, err = ss.Channel().GetSidebarCategories(userID, opts)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 6, len(res.Categories))
|
||||
|
||||
// Team member and exclude
|
||||
opts.TeamID = teamMember1.Id
|
||||
res, err = ss.Channel().GetSidebarCategories(userID, opts)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 3, len(res.Categories))
|
||||
})
|
||||
}
|
||||
|
||||
func testUpdateSidebarCategories(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
@@ -1142,11 +994,8 @@ func testUpdateSidebarCategories(t *testing.T, rctx request.CTX, ss store.Store)
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
// Create the initial categories
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, err := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
// Create the initial categories
|
||||
res, err := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -1180,11 +1029,8 @@ func testUpdateSidebarCategories(t *testing.T, rctx request.CTX, ss store.Store)
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
// Create the initial categories
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, err := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
// Create the initial categories
|
||||
res, err := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -1211,11 +1057,7 @@ func testUpdateSidebarCategories(t *testing.T, rctx request.CTX, ss store.Store)
|
||||
userID := model.NewId()
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -1282,11 +1124,8 @@ func testUpdateSidebarCategories(t *testing.T, rctx request.CTX, ss store.Store)
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
// Create the initial categories and find the favorites category
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
// Create the initial categories and find the favorites category
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -1347,11 +1186,8 @@ func testUpdateSidebarCategories(t *testing.T, rctx request.CTX, ss store.Store)
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
// Create the initial categories and find the favorites category
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
// Create the initial categories and find the favorites category
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -1418,11 +1254,8 @@ func testUpdateSidebarCategories(t *testing.T, rctx request.CTX, ss store.Store)
|
||||
team2 := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
// Create the initial categories and find the favorites categories in each team
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
// Create the initial categories and find the favorites categories in each team
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -1432,11 +1265,7 @@ func testUpdateSidebarCategories(t *testing.T, rctx request.CTX, ss store.Store)
|
||||
favoritesCategory := categories.Categories[0]
|
||||
require.Equal(t, model.SidebarCategoryFavorites, favoritesCategory.Type)
|
||||
|
||||
opts = &store.SidebarCategorySearchOpts{
|
||||
TeamID: team2.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(rctx, userID, team2.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -1527,11 +1356,8 @@ func testUpdateSidebarCategories(t *testing.T, rctx request.CTX, ss store.Store)
|
||||
team := setupTeam(t, rctx, ss, userID, userID2)
|
||||
|
||||
// Create the initial categories and find the favorites category
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
// Create the initial categories and find the favorites category
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -1544,7 +1370,7 @@ func testUpdateSidebarCategories(t *testing.T, rctx request.CTX, ss store.Store)
|
||||
require.Equal(t, model.SidebarCategoryChannels, channelsCategory.Type)
|
||||
|
||||
// Create the other users' categories
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(rctx, userID2, opts)
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(rctx, userID2, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -1701,11 +1527,7 @@ func testUpdateSidebarCategories(t *testing.T, rctx request.CTX, ss store.Store)
|
||||
)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -1760,11 +1582,7 @@ func testUpdateSidebarCategories(t *testing.T, rctx request.CTX, ss store.Store)
|
||||
)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -1852,11 +1670,8 @@ func testUpdateSidebarCategories(t *testing.T, rctx request.CTX, ss store.Store)
|
||||
require.NoError(t, err)
|
||||
|
||||
// And then create the initial categories so that it includes the channel
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
// And then create the initial categories so that it includes the channel
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -1920,11 +1735,8 @@ func testUpdateSidebarCategories(t *testing.T, rctx request.CTX, ss store.Store)
|
||||
require.NoError(t, err)
|
||||
|
||||
// And then create the initial categories so that Channels includes the channel
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
// And then create the initial categories so that Channels includes the channel
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -1982,11 +1794,7 @@ func setupInitialSidebarCategories(t *testing.T, rctx request.CTX, ss store.Stor
|
||||
userID := model.NewId()
|
||||
team := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -2109,11 +1917,7 @@ func testClearSidebarOnTeamLeave(t *testing.T, rctx request.CTX, ss store.Store,
|
||||
// Create a second team and set up the sidebar categories for it
|
||||
team2 := setupTeam(t, rctx, ss, userID)
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team2.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, err := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, err := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team2.Id)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -2300,11 +2104,7 @@ func testUpdateSidebarChannelsByPreferences(t *testing.T, rctx request.CTX, ss s
|
||||
userID := model.NewId()
|
||||
teamID := model.NewId()
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamID,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, teamID)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -2329,11 +2129,7 @@ func testUpdateSidebarChannelsByPreferences(t *testing.T, rctx request.CTX, ss s
|
||||
userID := model.NewId()
|
||||
teamID := model.NewId()
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamID,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, teamID)
|
||||
assert.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -2371,11 +2167,8 @@ func testSidebarCategoryDeadlock(t *testing.T, rctx request.CTX, ss store.Store)
|
||||
require.NoError(t, err)
|
||||
|
||||
// And then create the initial categories so that it includes the channel
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, err := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
// And then create the initial categories so that it includes the channel
|
||||
res, err := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -2482,11 +2275,8 @@ func doTestSidebarCategoryConcurrentAccess(t *testing.T, rctx request.CTX, ss st
|
||||
}
|
||||
|
||||
// Create the initial categories
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, opts)
|
||||
// Create the initial categories
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(rctx, userID, team.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
|
||||
@@ -342,9 +342,9 @@ func (_m *ChannelStore) CreateDirectChannel(ctx request.CTX, userID *model.User,
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// CreateInitialSidebarCategories provides a mock function with given fields: c, userID, opts
|
||||
func (_m *ChannelStore) CreateInitialSidebarCategories(c request.CTX, userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
|
||||
ret := _m.Called(c, userID, opts)
|
||||
// CreateInitialSidebarCategories provides a mock function with given fields: c, userID, teamID
|
||||
func (_m *ChannelStore) CreateInitialSidebarCategories(c request.CTX, userID string, teamID string) (*model.OrderedSidebarCategories, error) {
|
||||
ret := _m.Called(c, userID, teamID)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for CreateInitialSidebarCategories")
|
||||
@@ -352,19 +352,19 @@ func (_m *ChannelStore) CreateInitialSidebarCategories(c request.CTX, userID str
|
||||
|
||||
var r0 *model.OrderedSidebarCategories
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, string, *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error)); ok {
|
||||
return rf(c, userID, opts)
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, string, string) (*model.OrderedSidebarCategories, error)); ok {
|
||||
return rf(c, userID, teamID)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, string, *store.SidebarCategorySearchOpts) *model.OrderedSidebarCategories); ok {
|
||||
r0 = rf(c, userID, opts)
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, string, string) *model.OrderedSidebarCategories); ok {
|
||||
r0 = rf(c, userID, teamID)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.OrderedSidebarCategories)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(request.CTX, string, *store.SidebarCategorySearchOpts) error); ok {
|
||||
r1 = rf(c, userID, opts)
|
||||
if rf, ok := ret.Get(1).(func(request.CTX, string, string) error); ok {
|
||||
r1 = rf(c, userID, teamID)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -1968,9 +1968,9 @@ func (_m *ChannelStore) GetPublicChannelsForTeam(teamID string, offset int, limi
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetSidebarCategories provides a mock function with given fields: userID, opts
|
||||
func (_m *ChannelStore) GetSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
|
||||
ret := _m.Called(userID, opts)
|
||||
// GetSidebarCategories provides a mock function with given fields: userID, teamID
|
||||
func (_m *ChannelStore) GetSidebarCategories(userID string, teamID string) (*model.OrderedSidebarCategories, error) {
|
||||
ret := _m.Called(userID, teamID)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for GetSidebarCategories")
|
||||
@@ -1978,19 +1978,19 @@ func (_m *ChannelStore) GetSidebarCategories(userID string, opts *store.SidebarC
|
||||
|
||||
var r0 *model.OrderedSidebarCategories
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(string, *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error)); ok {
|
||||
return rf(userID, opts)
|
||||
if rf, ok := ret.Get(0).(func(string, string) (*model.OrderedSidebarCategories, error)); ok {
|
||||
return rf(userID, teamID)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(string, *store.SidebarCategorySearchOpts) *model.OrderedSidebarCategories); ok {
|
||||
r0 = rf(userID, opts)
|
||||
if rf, ok := ret.Get(0).(func(string, string) *model.OrderedSidebarCategories); ok {
|
||||
r0 = rf(userID, teamID)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.OrderedSidebarCategories)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(string, *store.SidebarCategorySearchOpts) error); ok {
|
||||
r1 = rf(userID, opts)
|
||||
if rf, ok := ret.Get(1).(func(string, string) error); ok {
|
||||
r1 = rf(userID, teamID)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
@@ -1041,10 +1041,10 @@ func (s *TimerLayerChannelStore) CreateDirectChannel(ctx request.CTX, userID *mo
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) CreateInitialSidebarCategories(c request.CTX, userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
|
||||
func (s *TimerLayerChannelStore) CreateInitialSidebarCategories(c request.CTX, userID string, teamID string) (*model.OrderedSidebarCategories, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.ChannelStore.CreateInitialSidebarCategories(c, userID, opts)
|
||||
result, err := s.ChannelStore.CreateInitialSidebarCategories(c, userID, teamID)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
@@ -1937,10 +1937,10 @@ func (s *TimerLayerChannelStore) GetPublicChannelsForTeam(teamID string, offset
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) GetSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
|
||||
func (s *TimerLayerChannelStore) GetSidebarCategories(userID string, teamID string) (*model.OrderedSidebarCategories, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.ChannelStore.GetSidebarCategories(userID, opts)
|
||||
result, err := s.ChannelStore.GetSidebarCategories(userID, teamID)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user