Excludes remote channels from channel search (#28708)

* Excludes remote channels from channel search

This is done through a new body parameter in the SearchAllChannels
endpoint that allows to search for local only channels, which are
either channels that are shared but marked as homed locally, or
channels that are not shared at all.

* fix lint

* Fix tests

---------

Co-authored-by: Caleb Roseland <caleb@calebroseland.com>
Этот коммит содержится в:
Miguel de la Cruz
2024-10-18 15:41:24 +02:00
коммит произвёл GitHub
родитель f06742c7e2
Коммит b4d8b6239c
13 изменённых файлов: 82 добавлений и 8 удалений

Просмотреть файл

@@ -3411,6 +3411,16 @@ func (s SqlChannelStore) channelSearchQuery(opts *store.ChannelSearchOpts) sq.Se
})
}
if opts.ExcludeRemote {
// local channels either have a SharedChannels record with
// home set to true, or don't have a SharedChannels record at all
query = query.LeftJoin("SharedChannels ON c.Id = SharedChannels.ChannelId").
Where(sq.Or{
sq.Eq{"SharedChannels.Home": true},
sq.Eq{"SharedChannels.ChannelId": nil},
})
}
return query
}

Просмотреть файл

@@ -1074,6 +1074,7 @@ type ChannelSearchOpts struct {
IncludePolicyID bool
IncludeTeamInfo bool
IncludeSearchById bool
ExcludeRemote bool
CountOnly bool
Public bool
Private bool

Просмотреть файл

@@ -6506,6 +6506,29 @@ func testChannelStoreSearchAllChannels(t *testing.T, rctx request.CTX, ss store.
})
require.NoError(t, nErr)
// Mark o12 and o14 as shared, o13 will be homed locally and o14
// will be homed remotely
sc12 := &model.SharedChannel{
ChannelId: o12.Id,
TeamId: o12.TeamId,
CreatorId: model.NewId(),
ShareName: "testsharelocal",
Home: true,
}
_, scErr := ss.SharedChannel().Save(sc12)
require.NoError(t, scErr)
sc14 := &model.SharedChannel{
ChannelId: o14.Id,
TeamId: o14.TeamId,
CreatorId: model.NewId(),
ShareName: "testshareremote",
Home: false,
RemoteId: model.NewId(),
}
_, sc2Err := ss.SharedChannel().Save(sc14)
require.NoError(t, sc2Err)
testCases := []struct {
Description string
Term string
@@ -6550,6 +6573,7 @@ func testChannelStoreSearchAllChannels(t *testing.T, rctx request.CTX, ss store.
{"Filter team 1 and team 2, public and private and exclude group constrained", "", store.ChannelSearchOpts{IncludeDeleted: false, TeamIds: []string{t1.Id, t2.Id}, Public: true, Private: true, ExcludeGroupConstrained: true, Page: model.NewPointer(0), PerPage: model.NewPointer(5)}, model.ChannelList{&o1, &o2, &o3, &o4, &o6}, 12},
{"Filter deleted returns only deleted channels", "", store.ChannelSearchOpts{Deleted: true, Page: model.NewPointer(0), PerPage: model.NewPointer(5)}, model.ChannelList{&o13}, 1},
{"Search ChannelA by id", o1.Id, store.ChannelSearchOpts{IncludeDeleted: false, Page: model.NewPointer(0), PerPage: model.NewPointer(5), IncludeSearchById: true}, model.ChannelList{&o1}, 1},
{"Filter excluding remote channels", "", store.ChannelSearchOpts{IncludeDeleted: false, ExcludeRemote: true}, model.ChannelList{&o1, &o2, &o3, &o4, &o5, &o6, &o7, &o8, &o9, &o10, &o11, &o12}, 0},
}
for _, testCase := range testCases {