MM-51482_Create Apps Category and link to bots DM (#22918)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
13f1d0fdc5
Коммит
1051925eec
@@ -25,13 +25,17 @@ func (a *App) createInitialSidebarCategories(userID string, opts *store.SidebarC
|
||||
|
||||
func (a *App) GetSidebarCategoriesForTeamForUser(c request.CTX, userID, teamID string) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
var appErr *model.AppError
|
||||
categories, err := a.Srv().Store().Channel().GetSidebarCategoriesForTeamForUser(userID, teamID)
|
||||
if err == nil && len(categories.Categories) == 0 {
|
||||
// A user must always have categories, so migration must not have happened yet, and we should run it ourselves
|
||||
categories, appErr = a.createInitialSidebarCategories(userID, &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamID,
|
||||
ExcludeTeam: false,
|
||||
})
|
||||
appsCategoryEnabled := a.Config().FeatureFlags.AppsSidebarCategory
|
||||
options := &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamID,
|
||||
ExcludeTeam: false,
|
||||
AppsCategoryEnabled: appsCategoryEnabled,
|
||||
}
|
||||
categories, err := a.Srv().Store().Channel().GetSidebarCategoriesForTeamForUser(userID, teamID, options)
|
||||
if err == nil && (len(categories.Categories) == 0 || (appsCategoryEnabled && checkMissingSystemSidebarCategories(categories))) {
|
||||
// A user must always have system categories, so migration must not have happened yet, and we should run it ourselves
|
||||
categories, appErr = a.createInitialSidebarCategories(userID, options)
|
||||
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
@@ -52,10 +56,17 @@ func (a *App) GetSidebarCategoriesForTeamForUser(c request.CTX, userID, teamID s
|
||||
|
||||
func (a *App) GetSidebarCategories(c request.CTX, userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
var appErr *model.AppError
|
||||
categories, err := a.Srv().Store().Channel().GetSidebarCategories(userID, opts)
|
||||
if err == nil && len(categories.Categories) == 0 {
|
||||
// A user must always have categories, so migration must not have happened yet, and we should run it ourselves
|
||||
categories, appErr = a.createInitialSidebarCategories(userID, opts)
|
||||
appsCategoryEnabled := a.Config().FeatureFlags.AppsSidebarCategory
|
||||
options := &store.SidebarCategorySearchOpts{
|
||||
TeamID: opts.TeamID,
|
||||
ExcludeTeam: opts.ExcludeTeam,
|
||||
AppsCategoryEnabled: appsCategoryEnabled,
|
||||
}
|
||||
categories, err := a.Srv().Store().Channel().GetSidebarCategories(userID, options)
|
||||
if err == nil && (len(categories.Categories) == 0 || (appsCategoryEnabled && checkMissingSystemSidebarCategories(categories))) {
|
||||
// A user must always have system categories, so migration must not have happened yet, and we should run it ourselves
|
||||
categories, appErr = a.createInitialSidebarCategories(userID, options)
|
||||
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
@@ -90,7 +101,8 @@ func (a *App) GetSidebarCategoryOrder(c request.CTX, userID, teamID string) ([]s
|
||||
}
|
||||
|
||||
func (a *App) GetSidebarCategory(c request.CTX, categoryId string) (*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
category, err := a.Srv().Store().Channel().GetSidebarCategory(categoryId)
|
||||
appsCategoryEnabled := a.Config().FeatureFlags.AppsSidebarCategory
|
||||
category, err := a.Srv().Store().Channel().GetSidebarCategory(categoryId, &store.SidebarCategorySearchOpts{AppsCategoryEnabled: appsCategoryEnabled})
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
@@ -105,7 +117,8 @@ func (a *App) GetSidebarCategory(c request.CTX, categoryId string) (*model.Sideb
|
||||
}
|
||||
|
||||
func (a *App) CreateSidebarCategory(c request.CTX, userID, teamID string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
category, err := a.Srv().Store().Channel().CreateSidebarCategory(userID, teamID, newCategory)
|
||||
appsCategoryEnabled := a.Config().FeatureFlags.AppsSidebarCategory
|
||||
category, err := a.Srv().Store().Channel().CreateSidebarCategory(userID, teamID, newCategory, &store.SidebarCategorySearchOpts{AppsCategoryEnabled: appsCategoryEnabled})
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
@@ -142,7 +155,13 @@ func (a *App) UpdateSidebarCategoryOrder(c request.CTX, userID, teamID string, c
|
||||
}
|
||||
|
||||
func (a *App) UpdateSidebarCategories(c request.CTX, userID, teamID string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
updatedCategories, originalCategories, err := a.Srv().Store().Channel().UpdateSidebarCategories(userID, teamID, categories)
|
||||
appsCategoryEnabled := a.Config().FeatureFlags.AppsSidebarCategory
|
||||
updatedCategories, originalCategories, err := a.Srv().Store().Channel().UpdateSidebarCategories(
|
||||
userID,
|
||||
teamID,
|
||||
categories,
|
||||
&store.SidebarCategorySearchOpts{AppsCategoryEnabled: appsCategoryEnabled},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("UpdateSidebarCategories", "app.channel.sidebar_categories.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
@@ -286,3 +305,17 @@ func (a *App) DeleteSidebarCategory(c request.CTX, userID, teamID, categoryId st
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkMissingSystemSidebarCategories(categories *model.OrderedSidebarCategories) bool {
|
||||
missingSystemCategories := make(map[model.SidebarCategoryType]struct{})
|
||||
|
||||
for _, systemSidebarCategory := range model.SystemSidebarCategories {
|
||||
missingSystemCategories[systemSidebarCategory] = struct{}{}
|
||||
}
|
||||
|
||||
for _, category := range categories.Categories {
|
||||
delete(missingSystemCategories, category.Type)
|
||||
}
|
||||
|
||||
return len(missingSystemCategories) != 0
|
||||
}
|
||||
|
||||
481
server/channels/app/channel_category_with_apps_category_test.go
Обычный файл
481
server/channels/app/channel_category_with_apps_category_test.go
Обычный файл
@@ -0,0 +1,481 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/v8/model"
|
||||
)
|
||||
|
||||
func TestSidebarCategoryWithAppsCategory(t *testing.T) {
|
||||
th := Setup(t).InitBasicWithAppsSidebarEnabled()
|
||||
defer th.TearDown()
|
||||
|
||||
basicChannel2 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
defer th.App.PermanentDeleteChannel(th.Context, basicChannel2)
|
||||
user := th.CreateUser()
|
||||
defer th.App.Srv().Store().User().PermanentDelete(user.Id)
|
||||
th.LinkUserToTeam(user, th.BasicTeam)
|
||||
th.AddUserToChannel(user, basicChannel2)
|
||||
|
||||
var createdCategory *model.SidebarCategoryWithChannels
|
||||
t.Run("CreateSidebarCategory", func(t *testing.T) {
|
||||
catData := model.SidebarCategoryWithChannels{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
DisplayName: "TEST",
|
||||
},
|
||||
Channels: []string{th.BasicChannel.Id, basicChannel2.Id, basicChannel2.Id},
|
||||
}
|
||||
_, err := th.App.CreateSidebarCategory(th.Context, user.Id, th.BasicTeam.Id, &catData)
|
||||
require.NotNil(t, err, "Should return error due to duplicate IDs")
|
||||
catData.Channels = []string{th.BasicChannel.Id, basicChannel2.Id}
|
||||
cat, err := th.App.CreateSidebarCategory(th.Context, user.Id, th.BasicTeam.Id, &catData)
|
||||
require.Nil(t, err, "Expected no error")
|
||||
require.NotNil(t, cat, "Expected category object, got nil")
|
||||
createdCategory = cat
|
||||
})
|
||||
|
||||
t.Run("UpdateSidebarCategories", func(t *testing.T) {
|
||||
require.NotNil(t, createdCategory)
|
||||
createdCategory.Channels = []string{th.BasicChannel.Id}
|
||||
updatedCat, err := th.App.UpdateSidebarCategories(th.Context, user.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{createdCategory})
|
||||
require.Nil(t, err, "Expected no error")
|
||||
require.NotNil(t, updatedCat, "Expected category object, got nil")
|
||||
require.Len(t, updatedCat, 1)
|
||||
require.Len(t, updatedCat[0].Channels, 1)
|
||||
require.Equal(t, updatedCat[0].Channels[0], th.BasicChannel.Id)
|
||||
})
|
||||
|
||||
t.Run("UpdateSidebarCategoryOrder", func(t *testing.T) {
|
||||
err := th.App.UpdateSidebarCategoryOrder(th.Context, user.Id, th.BasicTeam.Id, []string{th.BasicChannel.Id, basicChannel2.Id})
|
||||
require.NotNil(t, err, "Should return error due to invalid order")
|
||||
|
||||
actualOrder, err := th.App.GetSidebarCategoryOrder(th.Context, user.Id, th.BasicTeam.Id)
|
||||
require.Nil(t, err, "Should fetch order successfully")
|
||||
|
||||
actualOrder[2], actualOrder[3] = actualOrder[3], actualOrder[2]
|
||||
err = th.App.UpdateSidebarCategoryOrder(th.Context, user.Id, th.BasicTeam.Id, actualOrder)
|
||||
require.Nil(t, err, "Should update order successfully")
|
||||
|
||||
// We create a copy of actualOrder to prevent racy read
|
||||
// of the slice when the broadcast message is sent from webhub.
|
||||
newOrder := make([]string, len(actualOrder))
|
||||
copy(newOrder, actualOrder)
|
||||
newOrder[2] = "asd"
|
||||
err = th.App.UpdateSidebarCategoryOrder(th.Context, user.Id, th.BasicTeam.Id, newOrder)
|
||||
require.NotNil(t, err, "Should return error due to invalid id")
|
||||
})
|
||||
|
||||
t.Run("GetSidebarCategoryOrder", func(t *testing.T) {
|
||||
catOrder, err := th.App.GetSidebarCategoryOrder(th.Context, user.Id, th.BasicTeam.Id)
|
||||
require.Nil(t, err, "Expected no error")
|
||||
require.Len(t, catOrder, 5)
|
||||
require.Equal(t, catOrder[1], createdCategory.Id, "the newly created category should be after favorites")
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetSidebarCategoriesWithAppsCategory(t *testing.T) {
|
||||
t.Run("should return the sidebar categories for the given user/team", func(t *testing.T) {
|
||||
th := Setup(t).InitBasicWithAppsSidebarEnabled()
|
||||
defer th.TearDown()
|
||||
|
||||
_, err := th.App.CreateSidebarCategory(th.Context, th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
UserId: th.BasicUser.Id,
|
||||
TeamId: th.BasicTeam.Id,
|
||||
DisplayName: "new category",
|
||||
},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
categories, err := th.App.GetSidebarCategoriesForTeamForUser(th.Context, th.BasicUser.Id, th.BasicTeam.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.Len(t, categories.Categories, 5)
|
||||
})
|
||||
|
||||
t.Run("should create the initial categories even if migration hasn't ran yet", func(t *testing.T) {
|
||||
th := Setup(t).InitBasicWithAppsSidebarEnabled()
|
||||
defer th.TearDown()
|
||||
|
||||
// Manually add the user to the team without going through the app layer to simulate a pre-existing user/team
|
||||
// relationship that hasn't been migrated yet
|
||||
team := th.CreateTeam()
|
||||
_, err := th.App.Srv().Store().Team().SaveMember(&model.TeamMember{
|
||||
TeamId: team.Id,
|
||||
UserId: th.BasicUser.Id,
|
||||
SchemeUser: true,
|
||||
}, 100)
|
||||
require.NoError(t, err)
|
||||
|
||||
categories, appErr := th.App.GetSidebarCategoriesForTeamForUser(th.Context, th.BasicUser.Id, team.Id)
|
||||
assert.Nil(t, appErr)
|
||||
assert.Len(t, categories.Categories, 4)
|
||||
})
|
||||
|
||||
t.Run("should return a store error if a db table is missing", func(t *testing.T) {
|
||||
th := Setup(t).InitBasicWithAppsSidebarEnabled()
|
||||
defer th.TearDown()
|
||||
|
||||
// Temporarily renaming a table to force a DB error.
|
||||
sqlStore := mainHelper.GetSQLStore()
|
||||
_, err := sqlStore.GetMasterX().Exec("ALTER TABLE SidebarCategories RENAME TO SidebarCategoriesTest")
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
_, err := sqlStore.GetMasterX().Exec("ALTER TABLE SidebarCategoriesTest RENAME TO SidebarCategories")
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
|
||||
categories, appErr := th.App.GetSidebarCategoriesForTeamForUser(th.Context, th.BasicUser.Id, th.BasicTeam.Id)
|
||||
assert.Nil(t, categories)
|
||||
assert.NotNil(t, appErr)
|
||||
assert.Equal(t, "app.channel.sidebar_categories.app_error", appErr.Id)
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpdateSidebarCategoriesWithAppsCategory(t *testing.T) {
|
||||
t.Run("should mute and unmute all channels in a category when it is muted or unmuted", func(t *testing.T) {
|
||||
th := Setup(t).InitBasicWithAppsSidebarEnabled()
|
||||
defer th.TearDown()
|
||||
|
||||
categories, err := th.App.GetSidebarCategoriesForTeamForUser(th.Context, th.BasicUser.Id, th.BasicTeam.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
channelsCategory := categories.Categories[1]
|
||||
|
||||
// Create some channels to be part of the channels category
|
||||
channel1 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(th.BasicUser, channel1)
|
||||
|
||||
channel2 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(th.BasicUser, channel2)
|
||||
|
||||
// Mute the category
|
||||
updated, err := th.App.UpdateSidebarCategories(th.Context, th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: channelsCategory.Id,
|
||||
Muted: true,
|
||||
},
|
||||
Channels: []string{channel1.Id, channel2.Id},
|
||||
},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
assert.True(t, updated[0].Muted)
|
||||
|
||||
// Confirm that the channels are now muted
|
||||
member1, err := th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member1.IsChannelMuted())
|
||||
member2, err := th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member2.IsChannelMuted())
|
||||
|
||||
// Unmute the category
|
||||
updated, err = th.App.UpdateSidebarCategories(th.Context, th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: channelsCategory.Id,
|
||||
Muted: false,
|
||||
},
|
||||
Channels: []string{channel1.Id, channel2.Id},
|
||||
},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
assert.False(t, updated[0].Muted)
|
||||
|
||||
// Confirm that the channels are now unmuted
|
||||
member1, err = th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member1.IsChannelMuted())
|
||||
member2, err = th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member2.IsChannelMuted())
|
||||
})
|
||||
|
||||
t.Run("should mute and unmute channels moved from an unmuted category to a muted one and back", func(t *testing.T) {
|
||||
th := Setup(t).InitBasicWithAppsSidebarEnabled()
|
||||
defer th.TearDown()
|
||||
|
||||
// Create some channels
|
||||
channel1 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(th.BasicUser, channel1)
|
||||
|
||||
channel2 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(th.BasicUser, channel2)
|
||||
|
||||
// And some categories
|
||||
mutedCategory, err := th.App.CreateSidebarCategory(th.Context, th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
DisplayName: "muted",
|
||||
Muted: true,
|
||||
},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
require.True(t, mutedCategory.Muted)
|
||||
|
||||
unmutedCategory, err := th.App.CreateSidebarCategory(th.Context, th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
DisplayName: "unmuted",
|
||||
Muted: false,
|
||||
},
|
||||
Channels: []string{channel1.Id, channel2.Id},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
require.False(t, unmutedCategory.Muted)
|
||||
|
||||
// Move the channels
|
||||
_, err = th.App.UpdateSidebarCategories(th.Context, th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: mutedCategory.Id,
|
||||
DisplayName: mutedCategory.DisplayName,
|
||||
Muted: mutedCategory.Muted,
|
||||
},
|
||||
Channels: []string{channel1.Id, channel2.Id},
|
||||
},
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: unmutedCategory.Id,
|
||||
DisplayName: unmutedCategory.DisplayName,
|
||||
Muted: unmutedCategory.Muted,
|
||||
},
|
||||
Channels: []string{},
|
||||
},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
// Confirm that the channels are now muted
|
||||
member1, err := th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member1.IsChannelMuted())
|
||||
member2, err := th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member2.IsChannelMuted())
|
||||
|
||||
// Move the channels back
|
||||
_, err = th.App.UpdateSidebarCategories(th.Context, th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: mutedCategory.Id,
|
||||
DisplayName: mutedCategory.DisplayName,
|
||||
Muted: mutedCategory.Muted,
|
||||
},
|
||||
Channels: []string{},
|
||||
},
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: unmutedCategory.Id,
|
||||
DisplayName: unmutedCategory.DisplayName,
|
||||
Muted: unmutedCategory.Muted,
|
||||
},
|
||||
Channels: []string{channel1.Id, channel2.Id},
|
||||
},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
// Confirm that the channels are now unmuted
|
||||
member1, err = th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member1.IsChannelMuted())
|
||||
member2, err = th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member2.IsChannelMuted())
|
||||
})
|
||||
|
||||
t.Run("should not mute or unmute channels moved between muted categories", func(t *testing.T) {
|
||||
th := Setup(t).InitBasicWithAppsSidebarEnabled()
|
||||
defer th.TearDown()
|
||||
|
||||
// Create some channels
|
||||
channel1 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(th.BasicUser, channel1)
|
||||
|
||||
channel2 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(th.BasicUser, channel2)
|
||||
|
||||
// And some categories
|
||||
category1, err := th.App.CreateSidebarCategory(th.Context, th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
DisplayName: "category1",
|
||||
Muted: true,
|
||||
},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
require.True(t, category1.Muted)
|
||||
|
||||
category2, err := th.App.CreateSidebarCategory(th.Context, th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
DisplayName: "category2",
|
||||
Muted: true,
|
||||
},
|
||||
Channels: []string{channel1.Id, channel2.Id},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
require.True(t, category2.Muted)
|
||||
|
||||
// Move the unmuted channels
|
||||
_, err = th.App.UpdateSidebarCategories(th.Context, th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: category1.Id,
|
||||
DisplayName: category1.DisplayName,
|
||||
Muted: category1.Muted,
|
||||
},
|
||||
Channels: []string{channel1.Id, channel2.Id},
|
||||
},
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: category2.Id,
|
||||
DisplayName: category2.DisplayName,
|
||||
Muted: category2.Muted,
|
||||
},
|
||||
Channels: []string{},
|
||||
},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
// Confirm that the channels are still unmuted
|
||||
member1, err := th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member1.IsChannelMuted())
|
||||
member2, err := th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member2.IsChannelMuted())
|
||||
|
||||
// Mute the channels manually
|
||||
_, err = th.App.ToggleMuteChannel(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.ToggleMuteChannel(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
// Move the muted channels back
|
||||
_, err = th.App.UpdateSidebarCategories(th.Context, th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: category1.Id,
|
||||
DisplayName: category1.DisplayName,
|
||||
Muted: category1.Muted,
|
||||
},
|
||||
Channels: []string{},
|
||||
},
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: category2.Id,
|
||||
DisplayName: category2.DisplayName,
|
||||
Muted: category2.Muted,
|
||||
},
|
||||
Channels: []string{channel1.Id, channel2.Id},
|
||||
},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
// Confirm that the channels are still muted
|
||||
member1, err = th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member1.IsChannelMuted())
|
||||
member2, err = th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member2.IsChannelMuted())
|
||||
})
|
||||
|
||||
t.Run("should not mute or unmute channels moved between unmuted categories", func(t *testing.T) {
|
||||
th := Setup(t).InitBasicWithAppsSidebarEnabled()
|
||||
defer th.TearDown()
|
||||
|
||||
// Create some channels
|
||||
channel1 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(th.BasicUser, channel1)
|
||||
|
||||
channel2 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(th.BasicUser, channel2)
|
||||
|
||||
// And some categories
|
||||
category1, err := th.App.CreateSidebarCategory(th.Context, th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
DisplayName: "category1",
|
||||
Muted: false,
|
||||
},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
require.False(t, category1.Muted)
|
||||
|
||||
category2, err := th.App.CreateSidebarCategory(th.Context, th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
DisplayName: "category2",
|
||||
Muted: false,
|
||||
},
|
||||
Channels: []string{channel1.Id, channel2.Id},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
require.False(t, category2.Muted)
|
||||
|
||||
// Move the unmuted channels
|
||||
_, err = th.App.UpdateSidebarCategories(th.Context, th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: category1.Id,
|
||||
DisplayName: category1.DisplayName,
|
||||
Muted: category1.Muted,
|
||||
},
|
||||
Channels: []string{channel1.Id, channel2.Id},
|
||||
},
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: category2.Id,
|
||||
DisplayName: category2.DisplayName,
|
||||
Muted: category2.Muted,
|
||||
},
|
||||
Channels: []string{},
|
||||
},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
// Confirm that the channels are still unmuted
|
||||
member1, err := th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member1.IsChannelMuted())
|
||||
member2, err := th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.False(t, member2.IsChannelMuted())
|
||||
|
||||
// Mute the channels manually
|
||||
_, err = th.App.ToggleMuteChannel(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.ToggleMuteChannel(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
// Move the muted channels back
|
||||
_, err = th.App.UpdateSidebarCategories(th.Context, th.BasicUser.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: category1.Id,
|
||||
DisplayName: category1.DisplayName,
|
||||
Muted: category1.Muted,
|
||||
},
|
||||
Channels: []string{},
|
||||
},
|
||||
{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
Id: category2.Id,
|
||||
DisplayName: category2.DisplayName,
|
||||
Muted: category2.Muted,
|
||||
},
|
||||
Channels: []string{channel1.Id, channel2.Id},
|
||||
},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
// Confirm that the channels are still muted
|
||||
member1, err = th.App.GetChannelMember(th.Context, channel1.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member1.IsChannelMuted())
|
||||
member2, err = th.App.GetChannelMember(th.Context, channel2.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.True(t, member2.IsChannelMuted())
|
||||
})
|
||||
}
|
||||
@@ -253,6 +253,12 @@ func (th *TestHelper) InitBasic() *TestHelper {
|
||||
return th
|
||||
}
|
||||
|
||||
func (th *TestHelper) InitBasicWithAppsSidebarEnabled() *TestHelper {
|
||||
th.App.Config().FeatureFlags.AppsSidebarCategory = true
|
||||
|
||||
return th.InitBasic()
|
||||
}
|
||||
|
||||
func (th *TestHelper) DeleteBots() *TestHelper {
|
||||
preexistingBots, _ := th.App.GetBots(&model.BotGetOptions{Page: 0, PerPage: 100})
|
||||
for _, bot := range preexistingBots {
|
||||
|
||||
@@ -956,9 +956,11 @@ func (a *App) JoinUserToTeam(c request.CTX, team *model.Team, user *model.User,
|
||||
return nil, model.NewAppError("JoinUserToTeam", "app.user.update_update.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
appsCategoryEnabled := a.Config().FeatureFlags.AppsSidebarCategory
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
AppsCategoryEnabled: appsCategoryEnabled,
|
||||
}
|
||||
if _, err := a.createInitialSidebarCategories(user.Id, opts); err != nil {
|
||||
mlog.Warn(
|
||||
|
||||
@@ -1025,6 +1025,119 @@ func TestJoinUserToTeam(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestJoinUserToTeamWithAppsCategoryEnabled(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.FeatureFlags.AppsSidebarCategory = true })
|
||||
|
||||
id := model.NewId()
|
||||
team := &model.Team{
|
||||
DisplayName: "dn_" + id,
|
||||
Name: "name" + id,
|
||||
Email: "success+" + id + "@simulator.amazonses.com",
|
||||
Type: model.TeamOpen,
|
||||
}
|
||||
|
||||
_, err := th.App.CreateTeam(th.Context, team)
|
||||
require.Nil(t, err, "Should create a new team")
|
||||
|
||||
maxUsersPerTeam := th.App.Config().TeamSettings.MaxUsersPerTeam
|
||||
defer func() {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.MaxUsersPerTeam = maxUsersPerTeam })
|
||||
th.App.PermanentDeleteTeam(th.Context, team)
|
||||
}()
|
||||
one := 1
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.MaxUsersPerTeam = &one })
|
||||
|
||||
t.Run("new join", func(t *testing.T) {
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
|
||||
ruser, _ := th.App.CreateUser(th.Context, &user)
|
||||
defer th.App.PermanentDeleteUser(th.Context, &user)
|
||||
|
||||
_, appErr := th.App.JoinUserToTeam(th.Context, team, ruser, "")
|
||||
require.Nil(t, appErr, "Should return no error")
|
||||
})
|
||||
|
||||
t.Run("new join with limit problem", func(t *testing.T) {
|
||||
user1 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
|
||||
ruser1, _ := th.App.CreateUser(th.Context, &user1)
|
||||
user2 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
|
||||
ruser2, _ := th.App.CreateUser(th.Context, &user2)
|
||||
|
||||
defer th.App.PermanentDeleteUser(th.Context, &user1)
|
||||
defer th.App.PermanentDeleteUser(th.Context, &user2)
|
||||
|
||||
_, appErr := th.App.JoinUserToTeam(th.Context, team, ruser1, ruser2.Id)
|
||||
require.Nil(t, appErr, "Should return no error")
|
||||
|
||||
_, appErr = th.App.JoinUserToTeam(th.Context, team, ruser2, ruser1.Id)
|
||||
require.NotNil(t, appErr, "Should fail")
|
||||
})
|
||||
|
||||
t.Run("re-join after leaving with limit problem", func(t *testing.T) {
|
||||
user1 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
|
||||
ruser1, _ := th.App.CreateUser(th.Context, &user1)
|
||||
|
||||
user2 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
|
||||
ruser2, _ := th.App.CreateUser(th.Context, &user2)
|
||||
|
||||
defer th.App.PermanentDeleteUser(th.Context, &user1)
|
||||
defer th.App.PermanentDeleteUser(th.Context, &user2)
|
||||
|
||||
_, appErr := th.App.JoinUserToTeam(th.Context, team, ruser1, ruser2.Id)
|
||||
require.Nil(t, appErr, "Should return no error")
|
||||
appErr = th.App.LeaveTeam(th.Context, team, ruser1, ruser1.Id)
|
||||
require.Nil(t, appErr, "Should return no error")
|
||||
_, appErr = th.App.JoinUserToTeam(th.Context, team, ruser2, ruser2.Id)
|
||||
require.Nil(t, appErr, "Should return no error")
|
||||
|
||||
_, appErr = th.App.JoinUserToTeam(th.Context, team, ruser1, ruser2.Id)
|
||||
require.NotNil(t, appErr, "Should fail")
|
||||
})
|
||||
|
||||
t.Run("new join with correct scheme_admin value from group syncable", func(t *testing.T) {
|
||||
user1 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
|
||||
ruser1, _ := th.App.CreateUser(th.Context, &user1)
|
||||
defer th.App.PermanentDeleteUser(th.Context, &user1)
|
||||
|
||||
group := th.CreateGroup()
|
||||
|
||||
_, err = th.App.UpsertGroupMember(group.Id, user1.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
gs, err := th.App.UpsertGroupSyncable(&model.GroupSyncable{
|
||||
AutoAdd: true,
|
||||
SyncableId: team.Id,
|
||||
Type: model.GroupSyncableTypeTeam,
|
||||
GroupId: group.Id,
|
||||
SchemeAdmin: false,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.MaxUsersPerTeam = model.NewInt(999) })
|
||||
|
||||
tm1, appErr := th.App.JoinUserToTeam(th.Context, team, ruser1, "")
|
||||
require.Nil(t, appErr)
|
||||
require.False(t, tm1.SchemeAdmin)
|
||||
|
||||
user2 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
|
||||
ruser2, _ := th.App.CreateUser(th.Context, &user2)
|
||||
defer th.App.PermanentDeleteUser(th.Context, &user2)
|
||||
|
||||
_, err = th.App.UpsertGroupMember(group.Id, user2.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
gs.SchemeAdmin = true
|
||||
_, err = th.App.UpdateGroupSyncable(gs)
|
||||
require.Nil(t, err)
|
||||
|
||||
tm2, appErr := th.App.JoinUserToTeam(th.Context, team, ruser2, "")
|
||||
require.Nil(t, appErr)
|
||||
require.True(t, tm2.SchemeAdmin)
|
||||
})
|
||||
}
|
||||
|
||||
func TestLeaveTeamPanic(t *testing.T) {
|
||||
th := SetupWithStoreMock(t)
|
||||
defer th.TearDown()
|
||||
|
||||
Ссылка в новой задаче
Block a user