[MM-18946] [MM-26721] [MM-6842] Cross team search+private channel autocomplete (#18468)
* Show private channels in autocomplete This is supported in all Engines: MySQL, Postgres, Bleve, Elasticsearch. https://mattermost.atlassian.net/browse/MM-18496 ```release-note Private channels will now appear in channel autocomplete. If you are using Bleve or ElasticSearch, you will have to reindex the channels again to populate them with the new attributes. ``` A large chunk of this work has been based on the earlier effort at https://github.com/mattermost/mattermost-server/pull/17804. Full credit goes to https://github.com/arvinDarmawan. * Add comment ```release-note NONE ``` * Adding more tests ```release-note NONE ``` * fix more tests ```release-note NONE ``` * tmp ```release-note NONE ``` * more fixes ```release-note NONE ``` * add tests ```release-note NONE ``` * Add review comments from previous PR ```release-note NONE ``` * Add API to return all channels from all team ```release-note NONE ``` * Added support for bleve and ES ```release-note NONE ``` * Streaming response for GetAllChannels ```release-note NONE ``` * Fix tests ```release-note NONE ``` * Trigger CI ```release-note NONE ``` * fix tests ```release-note NONE ``` * Addressing review comments ```release-note NONE ``` * Fix lint ```release-note NONE ``` * Removing flaky test ```release-note NONE ``` * Address comments ```release-note NONE ``` * Trigger CI ```release-note NONE ``` * Added /users/<userid>/channel_members endpoint ```release-note NONE ``` * Minor edit ```release-note NONE ``` * Improve embedding ```release-note NONE ``` * Fix lint error ```release-note NONE ``` Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
971af6935c
Коммит
e24f22745e
@@ -1034,6 +1034,58 @@ func TestGetChannelsForTeamForUser(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetChannelsForUser(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
client := th.Client
|
||||
|
||||
// Adding another team with more channels (public and private)
|
||||
myTeam := th.CreateTeam()
|
||||
ch1 := th.CreateChannelWithClientAndTeam(client, model.ChannelTypeOpen, myTeam.Id)
|
||||
ch2 := th.CreateChannelWithClientAndTeam(client, model.ChannelTypePrivate, myTeam.Id)
|
||||
th.LinkUserToTeam(th.BasicUser, myTeam)
|
||||
th.App.AddUserToChannel(th.BasicUser, ch1, false)
|
||||
th.App.AddUserToChannel(th.BasicUser, ch2, false)
|
||||
|
||||
channels, _, err := client.GetChannelsForUserWithLastDeleteAt(th.BasicUser.Id, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
numPrivate := 0
|
||||
numPublic := 0
|
||||
numOffTopic := 0
|
||||
numTownSquare := 0
|
||||
for _, ch := range channels {
|
||||
if ch.Type == model.ChannelTypeOpen {
|
||||
numPublic++
|
||||
} else if ch.Type == model.ChannelTypePrivate {
|
||||
numPrivate++
|
||||
}
|
||||
|
||||
if ch.DisplayName == "Off-Topic" {
|
||||
numOffTopic++
|
||||
} else if ch.DisplayName == "Town Square" {
|
||||
numTownSquare++
|
||||
}
|
||||
}
|
||||
|
||||
assert.Len(t, channels, 9)
|
||||
assert.Equal(t, 2, numPrivate)
|
||||
assert.Equal(t, 7, numPublic)
|
||||
assert.Equal(t, 2, numOffTopic)
|
||||
assert.Equal(t, 2, numTownSquare)
|
||||
|
||||
// Creating some more channels to be exactly 100 to test page size boundaries.
|
||||
for i := 0; i < 91; i++ {
|
||||
ch1 = th.CreateChannelWithClientAndTeam(client, model.ChannelTypeOpen, myTeam.Id)
|
||||
th.App.AddUserToChannel(th.BasicUser, ch1, false)
|
||||
}
|
||||
|
||||
channels, _, err = client.GetChannelsForUserWithLastDeleteAt(th.BasicUser.Id, 0)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, channels, 100)
|
||||
}
|
||||
|
||||
func TestGetAllChannels(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
@@ -1383,6 +1435,16 @@ func TestSearchAllChannels(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
team := th.CreateTeam()
|
||||
privateChannel2, _, err := th.SystemAdminClient.CreateChannel(&model.Channel{
|
||||
DisplayName: "dn_private2",
|
||||
Name: "private2",
|
||||
Type: model.ChannelTypePrivate,
|
||||
TeamId: team.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
th.LinkUserToTeam(th.SystemAdminUser, team)
|
||||
th.LinkUserToTeam(th.SystemAdminUser, th.BasicTeam)
|
||||
|
||||
groupConstrainedChannel, _, err := th.SystemAdminClient.CreateChannel(&model.Channel{
|
||||
DisplayName: "SearchAllChannels-groupConstrained-1",
|
||||
Name: "groupconstrained1",
|
||||
@@ -1450,7 +1512,7 @@ func TestSearchAllChannels(t *testing.T) {
|
||||
{
|
||||
"Search with private channel filter",
|
||||
&model.ChannelSearch{Private: true},
|
||||
[]string{th.BasicPrivateChannel.Id, th.BasicPrivateChannel2.Id, privateChannel.Id, groupConstrainedChannel.Id},
|
||||
[]string{th.BasicPrivateChannel.Id, privateChannel2.Id, th.BasicPrivateChannel2.Id, privateChannel.Id, groupConstrainedChannel.Id},
|
||||
},
|
||||
{
|
||||
"Search with public channel filter",
|
||||
@@ -1517,6 +1579,14 @@ func TestSearchAllChannels(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
userChannels, _, err := th.SystemAdminClient.SearchAllChannelsForUser("private")
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, userChannels, 2)
|
||||
|
||||
userChannels, _, err = th.SystemAdminClient.SearchAllChannelsForUser("FOOBARDISPLAYNAME")
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, userChannels, 1)
|
||||
|
||||
// Searching with no terms returns all default channels
|
||||
allChannels, _, err := th.SystemAdminClient.SearchAllChannels(&model.ChannelSearch{Term: ""})
|
||||
require.NoError(t, err)
|
||||
@@ -3238,7 +3308,7 @@ func TestAutocompleteChannels(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
// A private channel to make sure private channels are not used
|
||||
// A private channel to make sure private channels are used.
|
||||
ptown, _, _ := th.Client.CreateChannel(&model.Channel{
|
||||
DisplayName: "Town",
|
||||
Name: "town",
|
||||
@@ -3267,8 +3337,8 @@ func TestAutocompleteChannels(t *testing.T) {
|
||||
"Basic town-square",
|
||||
th.BasicTeam.Id,
|
||||
"town",
|
||||
[]string{"town-square"},
|
||||
[]string{"off-topic", "town", "tower"},
|
||||
[]string{"town-square", "town"},
|
||||
[]string{"off-topic", "tower"},
|
||||
},
|
||||
{
|
||||
"Basic off-topic",
|
||||
@@ -3281,8 +3351,8 @@ func TestAutocompleteChannels(t *testing.T) {
|
||||
"Basic town square and off topic",
|
||||
th.BasicTeam.Id,
|
||||
"tow",
|
||||
[]string{"town-square", "tower"},
|
||||
[]string{"off-topic", "town"},
|
||||
[]string{"town-square", "tower", "town"},
|
||||
[]string{"off-topic"},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user