MM-23596: Ability to list private channels for team (#14925)
Summary: store, app, api and go driver support for listing private channels Ticket Link: https://mattermost.atlassian.net/browse/MM-23596
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
a4fc0fcfb7
Коммит
af8b914c6c
@@ -1273,6 +1273,24 @@ func (s *OpenTracingLayerChannelStore) GetPinnedPosts(channelId string) (*model.
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetPrivateChannelsForTeam")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := s.ChannelStore.GetPrivateChannelsForTeam(teamId, offset, limit)
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetPublicChannelsByIdsForTeam")
|
||||
|
||||
@@ -1046,6 +1046,29 @@ func (s SqlChannelStore) GetMoreChannels(teamId string, userId string, offset in
|
||||
return channels, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
|
||||
channels := &model.ChannelList{}
|
||||
|
||||
query := s.getQueryBuilder().
|
||||
Select("*").
|
||||
From("Channels").
|
||||
Where(sq.Eq{"Type": model.CHANNEL_PRIVATE, "TeamId": teamId, "DeleteAt": 0}).
|
||||
OrderBy("DisplayName").
|
||||
Limit(uint64(limit)).
|
||||
Offset(uint64(offset))
|
||||
|
||||
sql, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlChannelStore.GetPrivateChannelsForTeam", "store.sql_channel.get_private_channels.get.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
_, err = s.GetReplica().Select(channels, sql, args...)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlChannelStore.GetPrivateChannelsForTeam", "store.sql_channel.get_private_channels.get.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return channels, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
|
||||
channels := &model.ChannelList{}
|
||||
_, err := s.GetReplica().Select(channels, `
|
||||
|
||||
@@ -156,6 +156,7 @@ type ChannelStore interface {
|
||||
GetAllChannels(page, perPage int, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, error)
|
||||
GetAllChannelsCount(opts ChannelSearchOpts) (int64, error)
|
||||
GetMoreChannels(teamId string, userId string, offset int, limit int) (*model.ChannelList, error)
|
||||
GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError)
|
||||
GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError)
|
||||
GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError)
|
||||
GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError)
|
||||
|
||||
@@ -61,6 +61,7 @@ func TestChannelStore(t *testing.T, ss store.Store, s SqlSupplier) {
|
||||
t.Run("GetChannels", func(t *testing.T) { testChannelStoreGetChannels(t, ss) })
|
||||
t.Run("GetAllChannels", func(t *testing.T) { testChannelStoreGetAllChannels(t, ss, s) })
|
||||
t.Run("GetMoreChannels", func(t *testing.T) { testChannelStoreGetMoreChannels(t, ss) })
|
||||
t.Run("GetPrivateChannelsForTeam", func(t *testing.T) { testChannelStoreGetPrivateChannelsForTeam(t, ss) })
|
||||
t.Run("GetPublicChannelsForTeam", func(t *testing.T) { testChannelStoreGetPublicChannelsForTeam(t, ss) })
|
||||
t.Run("GetPublicChannelsByIdsForTeam", func(t *testing.T) { testChannelStoreGetPublicChannelsByIdsForTeam(t, ss) })
|
||||
t.Run("GetChannelCounts", func(t *testing.T) { testChannelStoreGetChannelCounts(t, ss) })
|
||||
@@ -3444,6 +3445,98 @@ func testChannelStoreGetMoreChannels(t *testing.T, ss store.Store) {
|
||||
})
|
||||
}
|
||||
|
||||
func testChannelStoreGetPrivateChannelsForTeam(t *testing.T, ss store.Store) {
|
||||
teamId := model.NewId()
|
||||
|
||||
// p1 is a private channel on the team
|
||||
p1 := model.Channel{
|
||||
TeamId: teamId,
|
||||
DisplayName: "PrivateChannel1Team1",
|
||||
Name: "zz" + model.NewId() + "b",
|
||||
Type: model.CHANNEL_PRIVATE,
|
||||
}
|
||||
_, nErr := ss.Channel().Save(&p1, -1)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
// p2 is a private channel on another team
|
||||
p2 := model.Channel{
|
||||
TeamId: model.NewId(),
|
||||
DisplayName: "PrivateChannel1Team2",
|
||||
Name: "zz" + model.NewId() + "b",
|
||||
Type: model.CHANNEL_PRIVATE,
|
||||
}
|
||||
_, nErr = ss.Channel().Save(&p2, -1)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
// o1 is a public channel on the team
|
||||
o1 := model.Channel{
|
||||
TeamId: teamId,
|
||||
DisplayName: "OpenChannel1Team1",
|
||||
Name: "zz" + model.NewId() + "b",
|
||||
Type: model.CHANNEL_OPEN,
|
||||
}
|
||||
_, nErr = ss.Channel().Save(&o1, -1)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
t.Run("only p1 initially listed in private channels", func(t *testing.T) {
|
||||
list, channelErr := ss.Channel().GetPrivateChannelsForTeam(teamId, 0, 100)
|
||||
require.Nil(t, channelErr)
|
||||
require.Equal(t, &model.ChannelList{&p1}, list)
|
||||
})
|
||||
|
||||
// p3 is another private channel on the team
|
||||
p3 := model.Channel{
|
||||
TeamId: teamId,
|
||||
DisplayName: "PrivateChannel2Team1",
|
||||
Name: "zz" + model.NewId() + "b",
|
||||
Type: model.CHANNEL_PRIVATE,
|
||||
}
|
||||
_, nErr = ss.Channel().Save(&p3, -1)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
// p4 is another private, but deleted channel on the team
|
||||
p4 := model.Channel{
|
||||
TeamId: teamId,
|
||||
DisplayName: "PrivateChannel3Team1",
|
||||
Name: "zz" + model.NewId() + "b",
|
||||
Type: model.CHANNEL_PRIVATE,
|
||||
}
|
||||
_, nErr = ss.Channel().Save(&p4, -1)
|
||||
require.Nil(t, nErr)
|
||||
err := ss.Channel().Delete(p4.Id, model.GetMillis())
|
||||
require.Nil(t, err, "channel should have been deleted")
|
||||
|
||||
t.Run("both p1 and p3 listed in private channels", func(t *testing.T) {
|
||||
list, err := ss.Channel().GetPrivateChannelsForTeam(teamId, 0, 100)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, &model.ChannelList{&p1, &p3}, list)
|
||||
})
|
||||
|
||||
t.Run("only p1 listed in private channels with offset 0, limit 1", func(t *testing.T) {
|
||||
list, err := ss.Channel().GetPrivateChannelsForTeam(teamId, 0, 1)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, &model.ChannelList{&p1}, list)
|
||||
})
|
||||
|
||||
t.Run("only p3 listed in private channels with offset 1, limit 1", func(t *testing.T) {
|
||||
list, err := ss.Channel().GetPrivateChannelsForTeam(teamId, 1, 1)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, &model.ChannelList{&p3}, list)
|
||||
})
|
||||
|
||||
t.Run("verify analytics for private channels", func(t *testing.T) {
|
||||
count, err := ss.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
|
||||
require.Nil(t, err)
|
||||
require.EqualValues(t, 3, count)
|
||||
})
|
||||
|
||||
t.Run("verify analytics for open open channels", func(t *testing.T) {
|
||||
count, err := ss.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
|
||||
require.Nil(t, err)
|
||||
require.EqualValues(t, 1, count)
|
||||
})
|
||||
}
|
||||
|
||||
func testChannelStoreGetPublicChannelsForTeam(t *testing.T, ss store.Store) {
|
||||
teamId := model.NewId()
|
||||
|
||||
|
||||
@@ -1051,6 +1051,31 @@ func (_m *ChannelStore) GetPinnedPosts(channelId string) (*model.PostList, *mode
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetPrivateChannelsForTeam provides a mock function with given fields: teamId, offset, limit
|
||||
func (_m *ChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
|
||||
ret := _m.Called(teamId, offset, limit)
|
||||
|
||||
var r0 *model.ChannelList
|
||||
if rf, ok := ret.Get(0).(func(string, int, int) *model.ChannelList); ok {
|
||||
r0 = rf(teamId, offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.ChannelList)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, int, int) *model.AppError); ok {
|
||||
r1 = rf(teamId, offset, limit)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetPublicChannelsByIdsForTeam provides a mock function with given fields: teamId, channelIds
|
||||
func (_m *ChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) {
|
||||
ret := _m.Called(teamId, channelIds)
|
||||
|
||||
@@ -1176,6 +1176,22 @@ func (s *TimerLayerChannelStore) GetPinnedPosts(channelId string) (*model.PostLi
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0, resultVar1 := s.ChannelStore.GetPrivateChannelsForTeam(teamId, offset, limit)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if resultVar1 == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("ChannelStore.GetPrivateChannelsForTeam", success, elapsed)
|
||||
}
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) {
|
||||
start := timemodule.Now()
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user