GraphQL: Create dedicated top-level filter for sidebar categories (#20353)
We add the excludeTeam switch to allow user to get all sidebar categories from other teams excluding a given team. ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ade2271442
Коммит
bd6acf04a9
@@ -284,7 +284,7 @@ func generateLayer(name, templateFile string) ([]byte, error) {
|
||||
switch param.Type {
|
||||
case "ChannelSearchOpts", "UserGetByIdsOpts", "ThreadMembershipOpts":
|
||||
paramsWithType = append(paramsWithType, fmt.Sprintf("%s store.%s", param.Name, param.Type))
|
||||
case "*UserGetByIdsOpts", "*ChannelMemberGraphQLSearchOpts":
|
||||
case "*UserGetByIdsOpts", "*ChannelMemberGraphQLSearchOpts", "*SidebarCategorySearchOpts":
|
||||
paramsWithType = append(paramsWithType, fmt.Sprintf("%s *store.%s", param.Name, strings.TrimPrefix(param.Type, "*")))
|
||||
default:
|
||||
paramsWithType = append(paramsWithType, fmt.Sprintf("%s %s", param.Name, param.Type))
|
||||
@@ -298,7 +298,7 @@ func generateLayer(name, templateFile string) ([]byte, error) {
|
||||
switch param.Type {
|
||||
case "ChannelSearchOpts", "UserGetByIdsOpts", "ThreadMembershipOpts":
|
||||
paramsWithType = append(paramsWithType, fmt.Sprintf("%s store.%s", param.Name, param.Type))
|
||||
case "*UserGetByIdsOpts", "*ChannelMemberGraphQLSearchOpts":
|
||||
case "*UserGetByIdsOpts", "*ChannelMemberGraphQLSearchOpts", "*SidebarCategorySearchOpts":
|
||||
paramsWithType = append(paramsWithType, fmt.Sprintf("%s *store.%s", param.Name, strings.TrimPrefix(param.Type, "*")))
|
||||
default:
|
||||
paramsWithType = append(paramsWithType, fmt.Sprintf("%s %s", param.Name, param.Type))
|
||||
|
||||
@@ -710,7 +710,7 @@ func (s *OpenTracingLayerChannelStore) CreateDirectChannel(userID *model.User, o
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) CreateInitialSidebarCategories(userID string, teamID string) (*model.OrderedSidebarCategories, error) {
|
||||
func (s *OpenTracingLayerChannelStore) CreateInitialSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.CreateInitialSidebarCategories")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -719,7 +719,7 @@ func (s *OpenTracingLayerChannelStore) CreateInitialSidebarCategories(userID str
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.ChannelStore.CreateInitialSidebarCategories(userID, teamID)
|
||||
result, err := s.ChannelStore.CreateInitialSidebarCategories(userID, opts)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
@@ -1641,7 +1641,7 @@ func (s *OpenTracingLayerChannelStore) GetPublicChannelsForTeam(teamID string, o
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) GetSidebarCategories(userID string, teamID string) (*model.OrderedSidebarCategories, error) {
|
||||
func (s *OpenTracingLayerChannelStore) GetSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetSidebarCategories")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -1650,7 +1650,25 @@ func (s *OpenTracingLayerChannelStore) GetSidebarCategories(userID string, teamI
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.ChannelStore.GetSidebarCategories(userID, teamID)
|
||||
result, err := s.ChannelStore.GetSidebarCategories(userID, opts)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) GetSidebarCategoriesForTeamForUser(userID string, teamID string) (*model.OrderedSidebarCategories, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetSidebarCategoriesForTeamForUser")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.ChannelStore.GetSidebarCategoriesForTeamForUser(userID, teamID)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
|
||||
@@ -773,11 +773,11 @@ func (s *RetryLayerChannelStore) CreateDirectChannel(userID *model.User, otherUs
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerChannelStore) CreateInitialSidebarCategories(userID string, teamID string) (*model.OrderedSidebarCategories, error) {
|
||||
func (s *RetryLayerChannelStore) CreateInitialSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.ChannelStore.CreateInitialSidebarCategories(userID, teamID)
|
||||
result, err := s.ChannelStore.CreateInitialSidebarCategories(userID, opts)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
@@ -1850,11 +1850,32 @@ func (s *RetryLayerChannelStore) GetPublicChannelsForTeam(teamID string, offset
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerChannelStore) GetSidebarCategories(userID string, teamID string) (*model.OrderedSidebarCategories, error) {
|
||||
func (s *RetryLayerChannelStore) GetSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.ChannelStore.GetSidebarCategories(userID, teamID)
|
||||
result, err := s.ChannelStore.GetSidebarCategories(userID, opts)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
timepkg.Sleep(100 * timepkg.Millisecond)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerChannelStore) GetSidebarCategoriesForTeamForUser(userID string, teamID string) (*model.OrderedSidebarCategories, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.ChannelStore.GetSidebarCategoriesForTeamForUser(userID, teamID)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package sqlstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
sq "github.com/mattermost/squirrel"
|
||||
@@ -19,18 +20,27 @@ type dbSelecter interface {
|
||||
Select(i interface{}, query string, args ...interface{}) error
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) CreateInitialSidebarCategories(userId, teamId string) (*model.OrderedSidebarCategories, error) {
|
||||
func (s SqlChannelStore) CreateInitialSidebarCategories(userId string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "CreateInitialSidebarCategories: begin_transaction")
|
||||
}
|
||||
defer finalizeTransactionX(transaction)
|
||||
|
||||
if err = s.createInitialSidebarCategoriesT(transaction, userId, teamId); err != nil {
|
||||
teamsWithExclude, err := s.SqlStore.stores.team.GetTeamsForUser(context.Background(), 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 {
|
||||
return nil, errors.Wrap(err, "CreateInitialSidebarCategories: createInitialSidebarCategoriesT")
|
||||
}
|
||||
|
||||
oc, err := s.getSidebarCategoriesT(transaction, userId, teamId)
|
||||
oc, err := s.getSidebarCategoriesT(transaction, userId, opts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "CreateInitialSidebarCategories: getSidebarCategoriesT")
|
||||
}
|
||||
@@ -42,82 +52,119 @@ func (s SqlChannelStore) CreateInitialSidebarCategories(userId, teamId string) (
|
||||
return oc, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) createInitialSidebarCategoriesT(transaction *sqlxTxWrapper, userId, teamId string) error {
|
||||
selectQuery, selectParams, _ := s.getQueryBuilder().
|
||||
Select("Type").
|
||||
func (s SqlChannelStore) createInitialSidebarCategoriesT(transaction *sqlxTxWrapper, userId string, excludedTeamIDs []string, opts *store.SidebarCategorySearchOpts) error {
|
||||
query := s.getQueryBuilder().
|
||||
Select("Type, TeamId").
|
||||
From("SidebarCategories").
|
||||
Where(sq.Eq{
|
||||
"UserId": userId,
|
||||
"TeamId": teamId,
|
||||
"Type": []model.SidebarCategoryType{model.SidebarCategoryFavorites, model.SidebarCategoryChannels, model.SidebarCategoryDirectMessages},
|
||||
}).ToSql()
|
||||
"Type": []model.SidebarCategoryType{
|
||||
model.SidebarCategoryFavorites,
|
||||
model.SidebarCategoryChannels,
|
||||
model.SidebarCategoryDirectMessages,
|
||||
},
|
||||
})
|
||||
|
||||
existingTypes := []model.SidebarCategoryType{}
|
||||
err := transaction.Select(&existingTypes, selectQuery, selectParams...)
|
||||
if !opts.ExcludeTeam {
|
||||
query = query.Where(sq.Eq{"TeamId": opts.TeamID})
|
||||
} else {
|
||||
query = query.Where(sq.NotEq{"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...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "createInitialSidebarCategoriesT: failed to select existing categories")
|
||||
}
|
||||
|
||||
hasCategoryOfType := make(map[model.SidebarCategoryType]bool, len(existingTypes))
|
||||
hasCategoryOfType := make(map[model.SidebarCategoryType]map[string]bool, len(existingTypes))
|
||||
for _, existingType := range existingTypes {
|
||||
hasCategoryOfType[existingType] = true
|
||||
if hasCategoryOfType[existingType.Type] == nil {
|
||||
hasCategoryOfType[existingType.Type] = make(map[string]bool)
|
||||
hasCategoryOfType[existingType.Type][existingType.TeamId] = true
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
channelsCategoryId := fmt.Sprintf("%s_%s_%s", model.SidebarCategoryChannels, userId, teamId)
|
||||
directMessagesCategoryId := fmt.Sprintf("%s_%s_%s", model.SidebarCategoryDirectMessages, userId, teamId)
|
||||
insertBuilder := s.getQueryBuilder().Insert("SidebarCategories").
|
||||
Columns("Id, UserId, TeamId, SortOrder, Sorting, Type, DisplayName, Muted, Collapsed")
|
||||
|
||||
if !hasCategoryOfType[model.SidebarCategoryFavorites] {
|
||||
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 {
|
||||
// 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)
|
||||
// Create the SidebarChannels first since there's more opportunity for something to fail here
|
||||
if err := s.migrateFavoritesToSidebarT(transaction, userId, teamId, favoritesCategoryId); err != nil {
|
||||
if err := s.migrateFavoritesToSidebarT(transaction, userId, teamID, favoritesCategoryId); err != nil {
|
||||
return errors.Wrap(err, "createInitialSidebarCategoriesT: failed to migrate favorites to sidebar")
|
||||
}
|
||||
|
||||
if _, err := transaction.NamedExec(`INSERT INTO
|
||||
SidebarCategories(Id, UserId, TeamId, SortOrder, Sorting, Type, DisplayName, Muted, Collapsed)
|
||||
VALUES(:Id, :UserId, :TeamId, :SortOrder, :Sorting, :Type, :DisplayName, :Muted, :Collapsed)`, &model.SidebarCategory{
|
||||
DisplayName: "Favorites", // This will be retranslated by the client into the user's locale
|
||||
Id: favoritesCategoryId,
|
||||
UserId: userId,
|
||||
TeamId: teamId,
|
||||
Sorting: model.SidebarCategorySortDefault,
|
||||
SortOrder: model.DefaultSidebarSortOrderFavorites,
|
||||
Type: model.SidebarCategoryFavorites,
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "createInitialSidebarCategoriesT: failed to insert favorites category")
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
if !hasCategoryOfType[model.SidebarCategoryChannels] {
|
||||
if _, err := transaction.NamedExec(`INSERT INTO
|
||||
SidebarCategories(Id, UserId, TeamId, SortOrder, Sorting, Type, DisplayName, Muted, Collapsed)
|
||||
VALUES(:Id, :UserId, :TeamId, :SortOrder, :Sorting, :Type, :DisplayName, :Muted, :Collapsed)`, &model.SidebarCategory{
|
||||
DisplayName: "Channels", // This will be retranslated by the client into the user's locale
|
||||
Id: channelsCategoryId,
|
||||
UserId: userId,
|
||||
TeamId: teamId,
|
||||
Sorting: model.SidebarCategorySortDefault,
|
||||
SortOrder: model.DefaultSidebarSortOrderChannels,
|
||||
Type: model.SidebarCategoryChannels,
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "createInitialSidebarCategoriesT: failed to insert channels category")
|
||||
}
|
||||
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)
|
||||
hasInsert = true
|
||||
}
|
||||
|
||||
if !hasCategoryOfType[model.SidebarCategoryDirectMessages] {
|
||||
if _, err := transaction.NamedExec(`INSERT INTO
|
||||
SidebarCategories(Id, UserId, TeamId, SortOrder, Sorting, Type, DisplayName, Muted, Collapsed)
|
||||
VALUES(:Id, :UserId, :TeamId, :SortOrder, :Sorting, :Type, :DisplayName, :Muted, :Collapsed)`, &model.SidebarCategory{
|
||||
DisplayName: "Direct Messages", // This will be retranslated by the client into the user's locale
|
||||
Id: directMessagesCategoryId,
|
||||
UserId: userId,
|
||||
TeamId: teamId,
|
||||
Sorting: model.SidebarCategorySortRecent,
|
||||
SortOrder: model.DefaultSidebarSortOrderDMs,
|
||||
Type: model.SidebarCategoryDirectMessages,
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "createInitialSidebarCategoriesT: failed to insert direct messages category")
|
||||
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)
|
||||
hasInsert = true
|
||||
}
|
||||
|
||||
if hasInsert {
|
||||
sql, args, err := insertBuilder.ToSql()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "insertSidebarCategories_Tosql")
|
||||
}
|
||||
_, err = transaction.Exec(sql, args...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "createInitialSidebarCategoriesT: failed to insert categories")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +299,11 @@ func (s SqlChannelStore) CreateSidebarCategory(userId, teamId string, newCategor
|
||||
|
||||
defer finalizeTransactionX(transaction)
|
||||
|
||||
categoriesWithOrder, err := s.getSidebarCategoriesT(transaction, userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
categoriesWithOrder, err := s.getSidebarCategoriesT(transaction, userId, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if len(categoriesWithOrder.Categories) == 0 {
|
||||
@@ -468,28 +519,35 @@ func (s SqlChannelStore) GetSidebarCategory(categoryId string) (*model.SidebarCa
|
||||
return s.completePopulatingCategoryChannels(result)
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) getSidebarCategoriesT(db dbSelecter, userId, teamId string) (*model.OrderedSidebarCategories, error) {
|
||||
func (s SqlChannelStore) getSidebarCategoriesT(db dbSelecter, userId string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
|
||||
oc := model.OrderedSidebarCategories{
|
||||
Categories: make(model.SidebarCategoriesWithChannels, 0),
|
||||
Order: make([]string, 0),
|
||||
}
|
||||
|
||||
categories := []*sidebarCategoryForJoin{}
|
||||
query, args, err := s.getQueryBuilder().
|
||||
query := s.getQueryBuilder().
|
||||
Select("SidebarCategories.*", "SidebarChannels.ChannelId").
|
||||
From("SidebarCategories").
|
||||
LeftJoin("SidebarChannels ON SidebarChannels.CategoryId=Id").
|
||||
Where(sq.And{
|
||||
sq.Eq{"SidebarCategories.UserId": userId},
|
||||
sq.Eq{"SidebarCategories.TeamId": teamId},
|
||||
}).
|
||||
OrderBy("SidebarCategories.SortOrder ASC, SidebarChannels.SortOrder ASC").ToSql()
|
||||
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})
|
||||
}
|
||||
|
||||
sql, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "sidebar_categories_tosql")
|
||||
}
|
||||
|
||||
if err := db.Select(&categories, query, args...); err != nil {
|
||||
return nil, store.NewErrNotFound("SidebarCategories", fmt.Sprintf("userId=%s,teamId=%s", userId, teamId))
|
||||
if err := db.Select(&categories, sql, args...); err != nil {
|
||||
return nil, store.NewErrNotFound("SidebarCategories", fmt.Sprintf("userId=%s,teamId=%s", userId, opts.TeamID))
|
||||
}
|
||||
|
||||
for _, category := range categories {
|
||||
@@ -521,8 +579,16 @@ func (s SqlChannelStore) getSidebarCategoriesT(db dbSelecter, userId, teamId str
|
||||
return &oc, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetSidebarCategories(userId, teamId string) (*model.OrderedSidebarCategories, error) {
|
||||
return s.getSidebarCategoriesT(s.GetReplicaX(), userId, teamId)
|
||||
func (s SqlChannelStore) GetSidebarCategoriesForTeamForUser(userId, teamId string) (*model.OrderedSidebarCategories, error) {
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
return s.getSidebarCategoriesT(s.GetReplicaX(), userId, opts)
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
|
||||
return s.getSidebarCategoriesT(s.GetReplicaX(), userID, opts)
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetSidebarCategoryOrder(userId, teamId string) ([]string, error) {
|
||||
|
||||
@@ -262,8 +262,9 @@ type ChannelStore interface {
|
||||
MigrateChannelMembers(fromChannelID string, fromUserID string) (map[string]string, error)
|
||||
ResetAllChannelSchemes() error
|
||||
ClearAllCustomRoleAssignments() error
|
||||
CreateInitialSidebarCategories(userID, teamID string) (*model.OrderedSidebarCategories, error)
|
||||
GetSidebarCategories(userID, teamID string) (*model.OrderedSidebarCategories, error)
|
||||
CreateInitialSidebarCategories(userID string, opts *SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error)
|
||||
GetSidebarCategoriesForTeamForUser(userID, teamID string) (*model.OrderedSidebarCategories, error)
|
||||
GetSidebarCategories(userID string, opts *SidebarCategorySearchOpts) (*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)
|
||||
@@ -1013,3 +1014,10 @@ type ChannelMemberGraphQLSearchOpts struct {
|
||||
LastUpdateAt int
|
||||
ExcludeTeam bool
|
||||
}
|
||||
|
||||
// SidebarCategorySearchOpts contains the options for a graphQL query
|
||||
// to get the sidebar categories.
|
||||
type SidebarCategorySearchOpts struct {
|
||||
TeamID string
|
||||
ExcludeTeam bool
|
||||
}
|
||||
|
||||
@@ -33,14 +33,19 @@ func testCreateInitialSidebarCategories(t *testing.T, ss store.Store) {
|
||||
userId := model.NewId()
|
||||
teamId := model.NewId()
|
||||
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
assert.NoError(t, nErr)
|
||||
assert.Len(t, res.Categories, 3)
|
||||
require.Len(t, res.Categories, 3)
|
||||
assert.Equal(t, model.SidebarCategoryFavorites, res.Categories[0].Type)
|
||||
assert.Equal(t, model.SidebarCategoryChannels, res.Categories[1].Type)
|
||||
assert.Equal(t, model.SidebarCategoryDirectMessages, res.Categories[2].Type)
|
||||
|
||||
res2, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
res2, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, res, res2)
|
||||
})
|
||||
@@ -49,20 +54,24 @@ func testCreateInitialSidebarCategories(t *testing.T, ss store.Store) {
|
||||
userId := model.NewId()
|
||||
teamId := model.NewId()
|
||||
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
userId2 := model.NewId()
|
||||
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(userId2, teamId)
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(userId2, opts)
|
||||
assert.NoError(t, nErr)
|
||||
assert.Len(t, res.Categories, 3)
|
||||
assert.Equal(t, model.SidebarCategoryFavorites, res.Categories[0].Type)
|
||||
assert.Equal(t, model.SidebarCategoryChannels, res.Categories[1].Type)
|
||||
assert.Equal(t, model.SidebarCategoryDirectMessages, res.Categories[2].Type)
|
||||
|
||||
res2, err := ss.Channel().GetSidebarCategories(userId2, teamId)
|
||||
res2, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId2, teamId)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, res, res2)
|
||||
})
|
||||
@@ -71,20 +80,27 @@ func testCreateInitialSidebarCategories(t *testing.T, ss store.Store) {
|
||||
userId := model.NewId()
|
||||
teamId := model.NewId()
|
||||
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
teamId2 := model.NewId()
|
||||
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(userId, teamId2)
|
||||
opts = &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId2,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
assert.NoError(t, nErr)
|
||||
assert.Len(t, res.Categories, 3)
|
||||
assert.Equal(t, model.SidebarCategoryFavorites, res.Categories[0].Type)
|
||||
assert.Equal(t, model.SidebarCategoryChannels, res.Categories[1].Type)
|
||||
assert.Equal(t, model.SidebarCategoryDirectMessages, res.Categories[2].Type)
|
||||
|
||||
res2, err := ss.Channel().GetSidebarCategories(userId, teamId2)
|
||||
res2, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId2)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, res, res2)
|
||||
})
|
||||
@@ -93,20 +109,24 @@ func testCreateInitialSidebarCategories(t *testing.T, ss store.Store) {
|
||||
userId := model.NewId()
|
||||
teamId := model.NewId()
|
||||
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
initialCategories, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
initialCategories, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, res, initialCategories)
|
||||
|
||||
// Calling CreateInitialSidebarCategories a second time shouldn't create any new categories
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
assert.NoError(t, nErr)
|
||||
assert.NotEmpty(t, res)
|
||||
|
||||
res, err = ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
res, err = ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, initialCategories.Categories, res.Categories)
|
||||
})
|
||||
@@ -123,13 +143,17 @@ func testCreateInitialSidebarCategories(t *testing.T, ss store.Store) {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
_, _ = ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
_, _ = ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
res, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
res, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, res.Categories, 3)
|
||||
})
|
||||
@@ -176,7 +200,11 @@ func testCreateInitialSidebarCategories(t *testing.T, ss store.Store) {
|
||||
require.NoError(t, nErr)
|
||||
|
||||
// Create the categories
|
||||
categories, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
categories, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
assert.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
@@ -185,7 +213,7 @@ func testCreateInitialSidebarCategories(t *testing.T, ss store.Store) {
|
||||
assert.Equal(t, []string{channel2.Id}, categories.Categories[1].Channels)
|
||||
|
||||
// Get and check the categories for channels
|
||||
categories2, nErr := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
categories2, nErr := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, nErr)
|
||||
require.Equal(t, categories, categories2)
|
||||
})
|
||||
@@ -240,14 +268,18 @@ func testCreateInitialSidebarCategories(t *testing.T, ss store.Store) {
|
||||
require.NoError(t, nErr)
|
||||
|
||||
// Create the categories
|
||||
categories, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
categories, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
assert.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
assert.Equal(t, []string{channel2.Id, channel1.Id}, categories.Categories[0].Channels)
|
||||
|
||||
// Get and check the categories for channels
|
||||
categories2, nErr := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
categories2, nErr := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, nErr)
|
||||
require.Equal(t, categories, categories2)
|
||||
})
|
||||
@@ -303,7 +335,11 @@ func testCreateInitialSidebarCategories(t *testing.T, ss store.Store) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create the categories
|
||||
categories, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
categories, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
assert.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
@@ -312,7 +348,7 @@ func testCreateInitialSidebarCategories(t *testing.T, ss store.Store) {
|
||||
assert.Equal(t, []string{dmChannel2.Id}, categories.Categories[2].Channels)
|
||||
|
||||
// Get and check the categories for channels
|
||||
categories2, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
categories2, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, categories, categories2)
|
||||
})
|
||||
@@ -347,7 +383,11 @@ func testCreateInitialSidebarCategories(t *testing.T, ss store.Store) {
|
||||
require.NoError(t, nErr)
|
||||
|
||||
// Create the categories
|
||||
categories, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
categories, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
assert.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
@@ -356,10 +396,54 @@ func testCreateInitialSidebarCategories(t *testing.T, ss store.Store) {
|
||||
assert.Equal(t, []string{}, categories.Categories[1].Channels)
|
||||
|
||||
// Get and check the categories for channels
|
||||
categories2, nErr := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
categories2, nErr := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, nErr)
|
||||
require.Equal(t, categories, categories2)
|
||||
})
|
||||
|
||||
t.Run("graphQL path to create initial favorites/channels/DMs categories on different teams", func(t *testing.T) {
|
||||
userId := model.NewId()
|
||||
|
||||
t1 := &model.Team{
|
||||
DisplayName: "DisplayName",
|
||||
Name: NewTestId(),
|
||||
Email: MakeEmail(),
|
||||
Type: model.TeamOpen,
|
||||
InviteId: model.NewId(),
|
||||
}
|
||||
t1, err := ss.Team().Save(t1)
|
||||
require.NoError(t, err)
|
||||
|
||||
m1 := &model.TeamMember{TeamId: t1.Id, UserId: userId}
|
||||
_, nErr := ss.Team().SaveMember(m1, -1)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
t2 := &model.Team{
|
||||
DisplayName: "DisplayName2",
|
||||
Name: NewTestId(),
|
||||
Email: MakeEmail(),
|
||||
Type: model.TeamOpen,
|
||||
InviteId: model.NewId(),
|
||||
}
|
||||
t2, err = ss.Team().Save(t2)
|
||||
require.NoError(t, err)
|
||||
|
||||
m2 := &model.TeamMember{TeamId: t2.Id, UserId: userId}
|
||||
_, nErr = ss.Team().SaveMember(m2, -1)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: t1.Id,
|
||||
ExcludeTeam: true,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
for _, cat := range res.Categories {
|
||||
assert.Equal(t, t2.Id, cat.TeamId)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func testCreateSidebarCategory(t *testing.T, ss store.Store) {
|
||||
@@ -383,7 +467,11 @@ func testCreateSidebarCategory(t *testing.T, ss store.Store) {
|
||||
userId := model.NewId()
|
||||
teamId := model.NewId()
|
||||
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -396,7 +484,7 @@ func testCreateSidebarCategory(t *testing.T, ss store.Store) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Confirm that it comes second
|
||||
res, err = ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
res, err = ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res.Categories, 4)
|
||||
assert.Equal(t, model.SidebarCategoryFavorites, res.Categories[0].Type)
|
||||
@@ -408,12 +496,16 @@ func testCreateSidebarCategory(t *testing.T, ss store.Store) {
|
||||
userId := model.NewId()
|
||||
teamId := model.NewId()
|
||||
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
// Re-arrange the categories so that Favorites comes last
|
||||
categories, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
categories, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
@@ -434,7 +526,7 @@ func testCreateSidebarCategory(t *testing.T, ss store.Store) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Confirm that it comes first
|
||||
res, err = ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
res, err = ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res.Categories, 4)
|
||||
assert.Equal(t, model.SidebarCategoryCustom, res.Categories[0].Type)
|
||||
@@ -445,7 +537,11 @@ func testCreateSidebarCategory(t *testing.T, ss store.Store) {
|
||||
userId := model.NewId()
|
||||
teamId := model.NewId()
|
||||
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -483,11 +579,15 @@ func testCreateSidebarCategory(t *testing.T, ss store.Store) {
|
||||
userId := model.NewId()
|
||||
teamId := model.NewId()
|
||||
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
categories, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
categories, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
|
||||
@@ -549,7 +649,11 @@ func testGetSidebarCategory(t *testing.T, ss store.Store, s SqlStore) {
|
||||
channelId2 := model.NewId()
|
||||
channelId3 := model.NewId()
|
||||
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -579,11 +683,15 @@ func testGetSidebarCategory(t *testing.T, ss store.Store, s SqlStore) {
|
||||
teamId := model.NewId()
|
||||
|
||||
// Create the initial categories and find the channels category
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
categories, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
categories, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
|
||||
channelsCategory := categories.Categories[1]
|
||||
@@ -643,11 +751,15 @@ func testGetSidebarCategory(t *testing.T, ss store.Store, s SqlStore) {
|
||||
teamId := model.NewId()
|
||||
|
||||
// Create the initial categories and find the channels category
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
categories, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
categories, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryChannels, categories.Categories[1].Type)
|
||||
|
||||
@@ -681,12 +793,16 @@ func testGetSidebarCategory(t *testing.T, ss store.Store, s SqlStore) {
|
||||
userId := model.NewId()
|
||||
teamId := model.NewId()
|
||||
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
// Create the initial categories and find the channels category
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
categories, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
categories, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
|
||||
favoritesCategory := categories.Categories[0]
|
||||
@@ -745,11 +861,15 @@ func testGetSidebarCategory(t *testing.T, ss store.Store, s SqlStore) {
|
||||
teamId := model.NewId()
|
||||
|
||||
// Create the initial categories and find the DMs category
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
categories, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
categories, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryDirectMessages, categories.Categories[2].Type)
|
||||
|
||||
@@ -786,11 +906,15 @@ func testGetSidebarCategory(t *testing.T, ss store.Store, s SqlStore) {
|
||||
teamId := model.NewId()
|
||||
|
||||
// Create the initial categories and find the DMs category
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
categories, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
categories, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryDirectMessages, categories.Categories[2].Type)
|
||||
|
||||
@@ -824,11 +948,15 @@ func testGetSidebarCategory(t *testing.T, ss store.Store, s SqlStore) {
|
||||
teamId := model.NewId()
|
||||
|
||||
// Create the initial categories and find the DMs category
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
categories, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
categories, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryDirectMessages, categories.Categories[2].Type)
|
||||
|
||||
@@ -854,8 +982,11 @@ func testGetSidebarCategory(t *testing.T, ss store.Store, s SqlStore) {
|
||||
|
||||
// Create another team and assign the DM to a custom category on that team
|
||||
otherTeamId := model.NewId()
|
||||
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(userId, otherTeamId)
|
||||
opts = &store.SidebarCategorySearchOpts{
|
||||
TeamID: otherTeamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -882,7 +1013,11 @@ func testGetSidebarCategories(t *testing.T, ss store.Store) {
|
||||
userId := model.NewId()
|
||||
teamId := model.NewId()
|
||||
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -901,7 +1036,7 @@ func testGetSidebarCategories(t *testing.T, ss store.Store) {
|
||||
gotCategory, err := ss.Channel().GetSidebarCategory(newCategory.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
res, err = ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
res, err = ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res.Categories, 4)
|
||||
|
||||
@@ -920,11 +1055,15 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store) {
|
||||
teamId := model.NewId()
|
||||
|
||||
// Create the initial categories
|
||||
res, err := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, err := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
initialCategories, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
initialCategories, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
|
||||
favoritesCategory := initialCategories.Categories[0]
|
||||
@@ -954,11 +1093,15 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store) {
|
||||
teamId := model.NewId()
|
||||
|
||||
// Create the initial categories
|
||||
res, err := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, err := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
initialCategories, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
initialCategories, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
|
||||
favoritesCategory := initialCategories.Categories[0]
|
||||
@@ -981,11 +1124,15 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store) {
|
||||
userId := model.NewId()
|
||||
teamId := model.NewId()
|
||||
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
initialCategories, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
initialCategories, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
|
||||
favoritesCategory := initialCategories.Categories[0]
|
||||
@@ -1048,11 +1195,15 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store) {
|
||||
teamId := model.NewId()
|
||||
|
||||
// Create the initial categories and find the favorites category
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
categories, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
categories, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
|
||||
favoritesCategory := categories.Categories[0]
|
||||
@@ -1109,11 +1260,15 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store) {
|
||||
teamId := model.NewId()
|
||||
|
||||
// Create the initial categories and find the favorites category
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
categories, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
categories, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
|
||||
favoritesCategory := categories.Categories[0]
|
||||
@@ -1176,21 +1331,29 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store) {
|
||||
teamId2 := model.NewId()
|
||||
|
||||
// Create the initial categories and find the favorites categories in each team
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
categories, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
categories, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
|
||||
favoritesCategory := categories.Categories[0]
|
||||
require.Equal(t, model.SidebarCategoryFavorites, favoritesCategory.Type)
|
||||
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(userId, teamId2)
|
||||
opts = &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId2,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
categories2, err := ss.Channel().GetSidebarCategories(userId, teamId2)
|
||||
categories2, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId2)
|
||||
require.NoError(t, err)
|
||||
|
||||
favoritesCategory2 := categories2.Categories[0]
|
||||
@@ -1276,11 +1439,15 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store) {
|
||||
teamId := model.NewId()
|
||||
|
||||
// Create the initial categories and find the favorites category
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
categories, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
categories, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
|
||||
favoritesCategory := categories.Categories[0]
|
||||
@@ -1291,11 +1458,11 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store) {
|
||||
// Create the other users' categories
|
||||
userId2 := model.NewId()
|
||||
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(userId2, teamId)
|
||||
res, nErr = ss.Channel().CreateInitialSidebarCategories(userId2, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
categories2, err := ss.Channel().GetSidebarCategories(userId2, teamId)
|
||||
categories2, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId2, teamId)
|
||||
require.NoError(t, err)
|
||||
|
||||
favoritesCategory2 := categories2.Categories[0]
|
||||
@@ -1447,12 +1614,16 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store) {
|
||||
)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
// And some categories
|
||||
initialCategories, nErr := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
initialCategories, nErr := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
channelsCategory := initialCategories.Categories[1]
|
||||
@@ -1502,12 +1673,16 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store) {
|
||||
)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
// The DM should start in the DMs category
|
||||
initialCategories, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
initialCategories, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
|
||||
dmsCategory := initialCategories.Categories[2]
|
||||
@@ -1590,11 +1765,15 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// And then create the initial categories so that it includes the channel
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
initialCategories, nErr := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
initialCategories, nErr := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
channelsCategory := initialCategories.Categories[1]
|
||||
@@ -1654,11 +1833,15 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// And then create the initial categories so that Channels includes the channel
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
initialCategories, nErr := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
initialCategories, nErr := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
channelsCategory := initialCategories.Categories[1]
|
||||
@@ -1712,11 +1895,15 @@ func setupInitialSidebarCategories(t *testing.T, ss store.Store) (string, string
|
||||
userId := model.NewId()
|
||||
teamId := model.NewId()
|
||||
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
res, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
res, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res.Categories, 3)
|
||||
|
||||
@@ -1835,11 +2022,15 @@ func testClearSidebarOnTeamLeave(t *testing.T, ss store.Store, s SqlStore) {
|
||||
// Create a second team and set up the sidebar categories for it
|
||||
teamId2 := model.NewId()
|
||||
|
||||
res, err := ss.Channel().CreateInitialSidebarCategories(userId, teamId2)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId2,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, err := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
res, err = ss.Channel().GetSidebarCategories(userId, teamId2)
|
||||
res, err = ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId2)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res.Categories, 3)
|
||||
|
||||
@@ -1896,7 +2087,7 @@ func testClearSidebarOnTeamLeave(t *testing.T, ss store.Store, s SqlStore) {
|
||||
assert.Equal(t, int64(2), count)
|
||||
|
||||
// Confirm that the categories on the second team are unchanged
|
||||
res, err = ss.Channel().GetSidebarCategories(userId, teamId2)
|
||||
res, err = ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId2)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, res.Categories, 4)
|
||||
|
||||
@@ -1915,7 +2106,7 @@ func testDeleteSidebarCategory(t *testing.T, ss store.Store, s SqlStore) {
|
||||
require.NotNil(t, newCategory)
|
||||
|
||||
// Ensure that the category was created properly
|
||||
res, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
res, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res.Categories, 4)
|
||||
|
||||
@@ -1923,7 +2114,7 @@ func testDeleteSidebarCategory(t *testing.T, ss store.Store, s SqlStore) {
|
||||
err = ss.Channel().DeleteSidebarCategory(newCategory.Id)
|
||||
assert.NoError(t, err)
|
||||
|
||||
res, err = ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
res, err = ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res.Categories, 3)
|
||||
})
|
||||
@@ -1967,7 +2158,7 @@ func testDeleteSidebarCategory(t *testing.T, ss store.Store, s SqlStore) {
|
||||
require.NotNil(t, newCategory)
|
||||
|
||||
// Ensure that the categories are set up correctly
|
||||
res, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
res, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res.Categories, 4)
|
||||
|
||||
@@ -1979,7 +2170,7 @@ func testDeleteSidebarCategory(t *testing.T, ss store.Store, s SqlStore) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Confirm that the category was deleted...
|
||||
res, err = ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
res, err = ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, res.Categories, 3)
|
||||
|
||||
@@ -1999,7 +2190,7 @@ func testDeleteSidebarCategory(t *testing.T, ss store.Store, s SqlStore) {
|
||||
t.Run("should not allow you to remove non-custom categories", func(t *testing.T) {
|
||||
userId, teamId := setupInitialSidebarCategories(t, ss)
|
||||
defer ss.User().PermanentDelete(userId)
|
||||
res, err := ss.Channel().GetSidebarCategories(userId, teamId)
|
||||
res, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userId, teamId)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res.Categories, 3)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, res.Categories[0].Type)
|
||||
@@ -2022,7 +2213,11 @@ func testUpdateSidebarChannelsByPreferences(t *testing.T, ss store.Store) {
|
||||
userId := model.NewId()
|
||||
teamId := model.NewId()
|
||||
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
require.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -2047,7 +2242,11 @@ func testUpdateSidebarChannelsByPreferences(t *testing.T, ss store.Store) {
|
||||
userId := model.NewId()
|
||||
teamId := model.NewId()
|
||||
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
|
||||
assert.NoError(t, nErr)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
@@ -2085,11 +2284,15 @@ func testSidebarCategoryDeadlock(t *testing.T, ss store.Store) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// And then create the initial categories so that it includes the channel
|
||||
res, err := ss.Channel().CreateInitialSidebarCategories(userID, teamID)
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamID,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
res, err := ss.Channel().CreateInitialSidebarCategories(userID, opts)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, res)
|
||||
|
||||
initialCategories, err := ss.Channel().GetSidebarCategories(userID, teamID)
|
||||
initialCategories, err := ss.Channel().GetSidebarCategoriesForTeamForUser(userID, teamID)
|
||||
require.NoError(t, err)
|
||||
|
||||
channelsCategory := initialCategories.Categories[1]
|
||||
|
||||
@@ -222,13 +222,13 @@ func (_m *ChannelStore) CreateDirectChannel(userID *model.User, otherUserID *mod
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// CreateInitialSidebarCategories provides a mock function with given fields: userID, teamID
|
||||
func (_m *ChannelStore) CreateInitialSidebarCategories(userID string, teamID string) (*model.OrderedSidebarCategories, error) {
|
||||
ret := _m.Called(userID, teamID)
|
||||
// CreateInitialSidebarCategories provides a mock function with given fields: userID, opts
|
||||
func (_m *ChannelStore) CreateInitialSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
|
||||
ret := _m.Called(userID, opts)
|
||||
|
||||
var r0 *model.OrderedSidebarCategories
|
||||
if rf, ok := ret.Get(0).(func(string, string) *model.OrderedSidebarCategories); ok {
|
||||
r0 = rf(userID, teamID)
|
||||
if rf, ok := ret.Get(0).(func(string, *store.SidebarCategorySearchOpts) *model.OrderedSidebarCategories); ok {
|
||||
r0 = rf(userID, opts)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.OrderedSidebarCategories)
|
||||
@@ -236,8 +236,8 @@ func (_m *ChannelStore) CreateInitialSidebarCategories(userID string, teamID str
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, string) error); ok {
|
||||
r1 = rf(userID, teamID)
|
||||
if rf, ok := ret.Get(1).(func(string, *store.SidebarCategorySearchOpts) error); ok {
|
||||
r1 = rf(userID, opts)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -1372,8 +1372,31 @@ func (_m *ChannelStore) GetPublicChannelsForTeam(teamID string, offset int, limi
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetSidebarCategories provides a mock function with given fields: userID, teamID
|
||||
func (_m *ChannelStore) GetSidebarCategories(userID string, teamID string) (*model.OrderedSidebarCategories, error) {
|
||||
// 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)
|
||||
|
||||
var r0 *model.OrderedSidebarCategories
|
||||
if rf, ok := ret.Get(0).(func(string, *store.SidebarCategorySearchOpts) *model.OrderedSidebarCategories); ok {
|
||||
r0 = rf(userID, opts)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.OrderedSidebarCategories)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, *store.SidebarCategorySearchOpts) error); ok {
|
||||
r1 = rf(userID, opts)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetSidebarCategoriesForTeamForUser provides a mock function with given fields: userID, teamID
|
||||
func (_m *ChannelStore) GetSidebarCategoriesForTeamForUser(userID string, teamID string) (*model.OrderedSidebarCategories, error) {
|
||||
ret := _m.Called(userID, teamID)
|
||||
|
||||
var r0 *model.OrderedSidebarCategories
|
||||
|
||||
@@ -677,10 +677,10 @@ func (s *TimerLayerChannelStore) CreateDirectChannel(userID *model.User, otherUs
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) CreateInitialSidebarCategories(userID string, teamID string) (*model.OrderedSidebarCategories, error) {
|
||||
func (s *TimerLayerChannelStore) CreateInitialSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.ChannelStore.CreateInitialSidebarCategories(userID, teamID)
|
||||
result, err := s.ChannelStore.CreateInitialSidebarCategories(userID, opts)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
@@ -1509,10 +1509,10 @@ func (s *TimerLayerChannelStore) GetPublicChannelsForTeam(teamID string, offset
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) GetSidebarCategories(userID string, teamID string) (*model.OrderedSidebarCategories, error) {
|
||||
func (s *TimerLayerChannelStore) GetSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.ChannelStore.GetSidebarCategories(userID, teamID)
|
||||
result, err := s.ChannelStore.GetSidebarCategories(userID, opts)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
@@ -1525,6 +1525,22 @@ func (s *TimerLayerChannelStore) GetSidebarCategories(userID string, teamID stri
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) GetSidebarCategoriesForTeamForUser(userID string, teamID string) (*model.OrderedSidebarCategories, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.ChannelStore.GetSidebarCategoriesForTeamForUser(userID, teamID)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("ChannelStore.GetSidebarCategoriesForTeamForUser", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) GetSidebarCategory(categoryID string) (*model.SidebarCategoryWithChannels, error) {
|
||||
start := time.Now()
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user