store: guests will only receive results of which channels they are in (#20295)
* store: guests will only receive results of which channels they are in * api4/channel_test: add test case for guest accounts channel autocomplete * apply to searchengine and also for AutocompleteInTeam Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
cffe921e62
Коммит
fe3816cc20
@@ -5899,7 +5899,7 @@ func testChannelStoreSearchInTeam(t *testing.T, ss store.Store) {
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run("AutoCompleteInTeam/"+testCase.Description, func(t *testing.T) {
|
||||
channels, err := ss.Channel().AutocompleteInTeam(testCase.TeamID, testCase.UserID, testCase.Term, testCase.IncludeDeleted)
|
||||
channels, err := ss.Channel().AutocompleteInTeam(testCase.TeamID, testCase.UserID, testCase.Term, testCase.IncludeDeleted, false)
|
||||
require.NoError(t, err)
|
||||
sort.Sort(ByChannelDisplayName(channels))
|
||||
require.Equal(t, testCase.ExpectedResults, channels)
|
||||
@@ -5946,6 +5946,15 @@ func testAutocomplete(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Channel().Save(&o2, -1)
|
||||
require.NoError(t, err)
|
||||
|
||||
o6 := model.Channel{
|
||||
TeamId: teamID,
|
||||
DisplayName: "ChannelA3",
|
||||
Name: NewTestId(),
|
||||
Type: model.ChannelTypeOpen,
|
||||
}
|
||||
_, err = ss.Channel().Save(&o6, -1)
|
||||
require.NoError(t, err)
|
||||
|
||||
m1 := model.ChannelMember{
|
||||
ChannelId: o1.Id,
|
||||
UserId: model.NewId(),
|
||||
@@ -6063,20 +6072,22 @@ func testAutocomplete(t *testing.T, ss store.Store) {
|
||||
UserID string
|
||||
Term string
|
||||
IncludeDeleted bool
|
||||
IsGuest bool
|
||||
ExpectedChannelIds []string
|
||||
ExpectedTeamNames []string
|
||||
}{
|
||||
{"user 1, Channel A", m1.UserId, "ChannelA", false, []string{o1.Id, o2.Id}, []string{t1.Name, t2.Name}},
|
||||
{"user 1, Channel B", m1.UserId, "ChannelB", false, []string{o4.Id}, []string{t2.Name}},
|
||||
{"user 2, Channel A", m3.UserId, "ChannelA", false, []string{o3.Id, o1.Id, o2.Id}, []string{t2.Name, t1.Name, t1.Name}},
|
||||
{"user 2, Channel B", m3.UserId, "ChannelB", false, nil, nil},
|
||||
{"user 1, empty string", m1.UserId, "", false, []string{o1.Id, o2.Id, o4.Id}, []string{t1.Name, t2.Name, t2.Name}},
|
||||
{"user 2, empty string", m3.UserId, "", false, []string{o1.Id, o2.Id, o3.Id}, []string{t1.Name, t2.Name, t1.Name}},
|
||||
{"user 1, Channel A", m1.UserId, "ChannelA", false, false, []string{o1.Id, o2.Id, o6.Id}, []string{t1.Name, t2.Name, t1.Name}},
|
||||
{"user 1, Channel B", m1.UserId, "ChannelB", false, false, []string{o4.Id}, []string{t2.Name}},
|
||||
{"user 2, Channel A", m3.UserId, "ChannelA", false, false, []string{o3.Id, o1.Id, o2.Id, o6.Id}, []string{t2.Name, t1.Name, t1.Name, t1.Name}},
|
||||
{"user 2 guest, Channel A", m3.UserId, "ChannelA", false, true, []string{o2.Id, o3.Id}, []string{t2.Name, t1.Name}},
|
||||
{"user 2, Channel B", m3.UserId, "ChannelB", false, false, nil, nil},
|
||||
{"user 1, empty string", m1.UserId, "", false, false, []string{o1.Id, o2.Id, o4.Id, o6.Id}, []string{t1.Name, t2.Name, t2.Name, t1.Name}},
|
||||
{"user 2, empty string", m3.UserId, "", false, false, []string{o1.Id, o2.Id, o3.Id, o6.Id}, []string{t1.Name, t2.Name, t1.Name, t1.Name}},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run("Autocomplete/"+testCase.Description, func(t *testing.T) {
|
||||
channels, err := ss.Channel().Autocomplete(testCase.UserID, testCase.Term, testCase.IncludeDeleted)
|
||||
channels, err := ss.Channel().Autocomplete(testCase.UserID, testCase.Term, testCase.IncludeDeleted, testCase.IsGuest)
|
||||
require.NoError(t, err)
|
||||
var gotChannelIds []string
|
||||
var gotTeamNames []string
|
||||
@@ -6084,8 +6095,8 @@ func testAutocomplete(t *testing.T, ss store.Store) {
|
||||
gotChannelIds = append(gotChannelIds, ch.Id)
|
||||
gotTeamNames = append(gotTeamNames, ch.TeamName)
|
||||
}
|
||||
require.ElementsMatch(t, testCase.ExpectedChannelIds, gotChannelIds)
|
||||
require.ElementsMatch(t, testCase.ExpectedTeamNames, gotTeamNames)
|
||||
require.ElementsMatch(t, testCase.ExpectedChannelIds, gotChannelIds, "channels IDs are not as expected")
|
||||
require.ElementsMatch(t, testCase.ExpectedTeamNames, gotTeamNames, "team names are not as expected")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,13 +60,13 @@ func (_m *ChannelStore) AnalyticsTypeCount(teamID string, channelType model.Chan
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Autocomplete provides a mock function with given fields: userID, term, includeDeleted
|
||||
func (_m *ChannelStore) Autocomplete(userID string, term string, includeDeleted bool) (model.ChannelListWithTeamData, error) {
|
||||
ret := _m.Called(userID, term, includeDeleted)
|
||||
// Autocomplete provides a mock function with given fields: userID, term, includeDeleted, isGuest
|
||||
func (_m *ChannelStore) Autocomplete(userID string, term string, includeDeleted bool, isGuest bool) (model.ChannelListWithTeamData, error) {
|
||||
ret := _m.Called(userID, term, includeDeleted, isGuest)
|
||||
|
||||
var r0 model.ChannelListWithTeamData
|
||||
if rf, ok := ret.Get(0).(func(string, string, bool) model.ChannelListWithTeamData); ok {
|
||||
r0 = rf(userID, term, includeDeleted)
|
||||
if rf, ok := ret.Get(0).(func(string, string, bool, bool) model.ChannelListWithTeamData); ok {
|
||||
r0 = rf(userID, term, includeDeleted, isGuest)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(model.ChannelListWithTeamData)
|
||||
@@ -74,8 +74,8 @@ func (_m *ChannelStore) Autocomplete(userID string, term string, includeDeleted
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, string, bool) error); ok {
|
||||
r1 = rf(userID, term, includeDeleted)
|
||||
if rf, ok := ret.Get(1).(func(string, string, bool, bool) error); ok {
|
||||
r1 = rf(userID, term, includeDeleted, isGuest)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -83,13 +83,13 @@ func (_m *ChannelStore) Autocomplete(userID string, term string, includeDeleted
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// AutocompleteInTeam provides a mock function with given fields: teamID, userID, term, includeDeleted
|
||||
func (_m *ChannelStore) AutocompleteInTeam(teamID string, userID string, term string, includeDeleted bool) (model.ChannelList, error) {
|
||||
ret := _m.Called(teamID, userID, term, includeDeleted)
|
||||
// AutocompleteInTeam provides a mock function with given fields: teamID, userID, term, includeDeleted, isGuest
|
||||
func (_m *ChannelStore) AutocompleteInTeam(teamID string, userID string, term string, includeDeleted bool, isGuest bool) (model.ChannelList, error) {
|
||||
ret := _m.Called(teamID, userID, term, includeDeleted, isGuest)
|
||||
|
||||
var r0 model.ChannelList
|
||||
if rf, ok := ret.Get(0).(func(string, string, string, bool) model.ChannelList); ok {
|
||||
r0 = rf(teamID, userID, term, includeDeleted)
|
||||
if rf, ok := ret.Get(0).(func(string, string, string, bool, bool) model.ChannelList); ok {
|
||||
r0 = rf(teamID, userID, term, includeDeleted, isGuest)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(model.ChannelList)
|
||||
@@ -97,8 +97,8 @@ func (_m *ChannelStore) AutocompleteInTeam(teamID string, userID string, term st
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, string, string, bool) error); ok {
|
||||
r1 = rf(teamID, userID, term, includeDeleted)
|
||||
if rf, ok := ret.Get(1).(func(string, string, string, bool, bool) error); ok {
|
||||
r1 = rf(teamID, userID, term, includeDeleted, isGuest)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user