MM-15422: Adds new parameters for retrieving pages of channels. (#10903)
* MM-15422: Adds new parameters for retrieving pages of channels and searching channels. * MM-15422: Appends excluded channel names with defaults. Adds separate struct for data-tier option parameter.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
124b371312
Коммит
e8af4872c6
@@ -16,23 +16,52 @@ import (
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
|
||||
func (a *App) CreateDefaultChannels(teamId string) ([]*model.Channel, *model.AppError) {
|
||||
townSquare := &model.Channel{DisplayName: utils.T("api.channel.create_default_channels.town_square"), Name: "town-square", Type: model.CHANNEL_OPEN, TeamId: teamId}
|
||||
|
||||
if _, err := a.CreateChannel(townSquare, false); err != nil {
|
||||
return nil, err
|
||||
// CreateDefaultChannels creates channels in the given team for each channel returned by (*App).DefaultChannelNames.
|
||||
//
|
||||
func (a *App) CreateDefaultChannels(teamID string) ([]*model.Channel, *model.AppError) {
|
||||
displayNames := map[string]string{
|
||||
"town-square": utils.T("api.channel.create_default_channels.town_square"),
|
||||
"off-topic": utils.T("api.channel.create_default_channels.off_topic"),
|
||||
}
|
||||
|
||||
offTopic := &model.Channel{DisplayName: utils.T("api.channel.create_default_channels.off_topic"), Name: "off-topic", Type: model.CHANNEL_OPEN, TeamId: teamId}
|
||||
|
||||
if _, err := a.CreateChannel(offTopic, false); err != nil {
|
||||
return nil, err
|
||||
channels := []*model.Channel{}
|
||||
defaultChannelNames := a.DefaultChannelNames()
|
||||
for _, name := range defaultChannelNames {
|
||||
displayName := utils.TDefault(displayNames[name], name)
|
||||
channel := &model.Channel{DisplayName: displayName, Name: name, Type: model.CHANNEL_OPEN, TeamId: teamID}
|
||||
if _, err := a.CreateChannel(channel, false); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
channels = append(channels, channel)
|
||||
}
|
||||
|
||||
channels := []*model.Channel{townSquare, offTopic}
|
||||
return channels, nil
|
||||
}
|
||||
|
||||
// DefaultChannelNames returns the list of system-wide default channel names.
|
||||
//
|
||||
// By default the list will be (not necessarily in this order):
|
||||
// ['town-square', 'off-topic']
|
||||
// However, if TeamSettings.ExperimentalDefaultChannels contains a list of channels then that list will replace
|
||||
// 'off-topic' and be included in the return results in addition to 'town-square'. For example:
|
||||
// ['town-square', 'game-of-thrones', 'wow']
|
||||
//
|
||||
func (a *App) DefaultChannelNames() []string {
|
||||
names := []string{"town-square"}
|
||||
|
||||
if len(a.Config().TeamSettings.ExperimentalDefaultChannels) == 0 {
|
||||
names = append(names, "off-topic")
|
||||
} else {
|
||||
seenChannels := map[string]bool{}
|
||||
for _, channelName := range a.Config().TeamSettings.ExperimentalDefaultChannels {
|
||||
if !seenChannels[channelName] {
|
||||
names = append(names, channelName)
|
||||
seenChannels[channelName] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return names
|
||||
}
|
||||
|
||||
func (a *App) JoinDefaultChannels(teamId string, user *model.User, shouldBeAdmin bool, userRequestorId string) *model.AppError {
|
||||
var requestor *model.User
|
||||
if userRequestorId != "" {
|
||||
@@ -43,22 +72,8 @@ func (a *App) JoinDefaultChannels(teamId string, user *model.User, shouldBeAdmin
|
||||
}
|
||||
}
|
||||
|
||||
defaultChannelList := []string{"town-square"}
|
||||
|
||||
if len(a.Config().TeamSettings.ExperimentalDefaultChannels) == 0 {
|
||||
defaultChannelList = append(defaultChannelList, "off-topic")
|
||||
} else {
|
||||
seenChannels := map[string]bool{}
|
||||
for _, channelName := range a.Config().TeamSettings.ExperimentalDefaultChannels {
|
||||
if !seenChannels[channelName] {
|
||||
defaultChannelList = append(defaultChannelList, channelName)
|
||||
seenChannels[channelName] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var err *model.AppError
|
||||
for _, channelName := range defaultChannelList {
|
||||
for _, channelName := range a.DefaultChannelNames() {
|
||||
if result := <-a.Srv.Store.Channel().GetByName(teamId, channelName, true); result.Err != nil {
|
||||
err = result.Err
|
||||
} else {
|
||||
@@ -1230,8 +1245,16 @@ func (a *App) GetChannelsForUser(teamId string, userId string, includeDeleted bo
|
||||
return result.Data.(*model.ChannelList), nil
|
||||
}
|
||||
|
||||
func (a *App) GetAllChannels(page, perPage int, includeDeleted bool) (*model.ChannelListWithTeamData, *model.AppError) {
|
||||
result := <-a.Srv.Store.Channel().GetAllChannels(page*perPage, perPage, includeDeleted)
|
||||
func (a *App) GetAllChannels(page, perPage int, opts model.ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError) {
|
||||
if opts.ExcludeDefaultChannels {
|
||||
opts.ExcludeChannelNames = a.DefaultChannelNames()
|
||||
}
|
||||
storeOpts := store.ChannelSearchOpts{
|
||||
ExcludeChannelNames: opts.ExcludeChannelNames,
|
||||
NotAssociatedToGroup: opts.NotAssociatedToGroup,
|
||||
IncludeDeleted: opts.IncludeDeleted,
|
||||
}
|
||||
result := <-a.Srv.Store.Channel().GetAllChannels(page*perPage, perPage, storeOpts)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
@@ -1784,8 +1807,17 @@ func (a *App) AutocompleteChannelsForSearch(teamId string, userId string, term s
|
||||
return result.Data.(*model.ChannelList), nil
|
||||
}
|
||||
|
||||
func (a *App) SearchAllChannels(term string, includeDeleted bool) (*model.ChannelListWithTeamData, *model.AppError) {
|
||||
result := <-a.Srv.Store.Channel().SearchAllChannels(term, *a.Config().TeamSettings.ExperimentalViewArchivedChannels && includeDeleted)
|
||||
func (a *App) SearchAllChannels(term string, opts model.ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError) {
|
||||
opts.IncludeDeleted = *a.Config().TeamSettings.ExperimentalViewArchivedChannels && opts.IncludeDeleted
|
||||
if opts.ExcludeDefaultChannels {
|
||||
opts.ExcludeChannelNames = a.DefaultChannelNames()
|
||||
}
|
||||
storeOpts := store.ChannelSearchOpts{
|
||||
ExcludeChannelNames: opts.ExcludeChannelNames,
|
||||
NotAssociatedToGroup: opts.NotAssociatedToGroup,
|
||||
IncludeDeleted: opts.IncludeDeleted,
|
||||
}
|
||||
result := <-a.Srv.Store.Channel().SearchAllChannels(term, storeOpts)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
|
||||
@@ -895,3 +895,20 @@ func TestUpdateChannelMemberRolesChangingGuest(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestDefaultChannelNames(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
actual := th.App.DefaultChannelNames()
|
||||
expect := []string{"town-square", "off-topic"}
|
||||
require.ElementsMatch(t, expect, actual)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.TeamSettings.ExperimentalDefaultChannels = []string{"foo", "bar"}
|
||||
})
|
||||
|
||||
actual = th.App.DefaultChannelNames()
|
||||
expect = []string{"town-square", "foo", "bar"}
|
||||
require.ElementsMatch(t, expect, actual)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user