ChannelStore migration Part 3 (#15504)
* Migration finished * Change error var name * Fix imports * Fix tests * Merge with master * Doing some suggestions * More suggestions * Fix i18n Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
5353bceaea
Коммит
bb4df5a68e
@@ -1783,7 +1783,12 @@ func (a *App) GetChannelMembersTimezones(channelId string) ([]string, *model.App
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMembersByIds(channelId string, userIds []string) (*model.ChannelMembers, *model.AppError) {
|
||||
return a.Srv().Store.Channel().GetMembersByIds(channelId, userIds)
|
||||
members, err := a.Srv().Store.Channel().GetMembersByIds(channelId, userIds)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetChannelMembersByIds", "app.channel.get_members_by_ids.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return members, nil
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError) {
|
||||
@@ -1850,7 +1855,13 @@ func (a *App) GetChannelCounts(teamId string, userId string) (*model.ChannelCoun
|
||||
func (a *App) GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError) {
|
||||
channelUnread, err := a.Srv().Store.Channel().GetChannelUnread(channelId, userId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("GetChannelUnread", "app.channel.get_unread.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, model.NewAppError("GetChannelUnread", "app.channel.get_unread.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
if channelUnread.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_MARK_UNREAD_MENTION {
|
||||
@@ -2329,7 +2340,12 @@ func (a *App) AutocompleteChannels(teamId string, term string) (*model.ChannelLi
|
||||
includeDeleted := *a.Config().TeamSettings.ExperimentalViewArchivedChannels
|
||||
term = strings.TrimSpace(term)
|
||||
|
||||
return a.Srv().Store.Channel().AutocompleteInTeam(teamId, term, includeDeleted)
|
||||
channelList, err := a.Srv().Store.Channel().AutocompleteInTeam(teamId, term, includeDeleted)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("AutocompleteChannels", "app.channel.search.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return channelList, nil
|
||||
}
|
||||
|
||||
func (a *App) AutocompleteChannelsForSearch(teamId string, userId string, term string) (*model.ChannelList, *model.AppError) {
|
||||
@@ -2337,7 +2353,12 @@ func (a *App) AutocompleteChannelsForSearch(teamId string, userId string, term s
|
||||
|
||||
term = strings.TrimSpace(term)
|
||||
|
||||
return a.Srv().Store.Channel().AutocompleteInTeamForSearch(teamId, userId, term, includeDeleted)
|
||||
channelList, err := a.Srv().Store.Channel().AutocompleteInTeamForSearch(teamId, userId, term, includeDeleted)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("AutocompleteChannelsForSearch", "app.channel.search.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return channelList, nil
|
||||
}
|
||||
|
||||
// SearchAllChannels returns a list of channels, the total count of the results of the search (if the paginate search option is true), and an error.
|
||||
@@ -2361,7 +2382,12 @@ func (a *App) SearchAllChannels(term string, opts model.ChannelSearchOpts) (*mod
|
||||
|
||||
term = strings.TrimSpace(term)
|
||||
|
||||
return a.Srv().Store.Channel().SearchAllChannels(term, storeOpts)
|
||||
channelList, totalCount, err := a.Srv().Store.Channel().SearchAllChannels(term, storeOpts)
|
||||
if err != nil {
|
||||
return nil, 0, model.NewAppError("SearchAllChannels", "app.channel.search.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return channelList, totalCount, nil
|
||||
}
|
||||
|
||||
func (a *App) SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError) {
|
||||
@@ -2369,13 +2395,23 @@ func (a *App) SearchChannels(teamId string, term string) (*model.ChannelList, *m
|
||||
|
||||
term = strings.TrimSpace(term)
|
||||
|
||||
return a.Srv().Store.Channel().SearchInTeam(teamId, term, includeDeleted)
|
||||
channelList, err := a.Srv().Store.Channel().SearchInTeam(teamId, term, includeDeleted)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SearchChannels", "app.channel.search.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return channelList, nil
|
||||
}
|
||||
|
||||
func (a *App) SearchArchivedChannels(teamId string, term string, userId string) (*model.ChannelList, *model.AppError) {
|
||||
term = strings.TrimSpace(term)
|
||||
|
||||
return a.Srv().Store.Channel().SearchArchivedInTeam(teamId, term, userId)
|
||||
channelList, err := a.Srv().Store.Channel().SearchArchivedInTeam(teamId, term, userId)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SearchArchivedChannels", "app.channel.search.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return channelList, nil
|
||||
}
|
||||
|
||||
func (a *App) SearchChannelsForUser(userId, teamId, term string) (*model.ChannelList, *model.AppError) {
|
||||
@@ -2383,7 +2419,12 @@ func (a *App) SearchChannelsForUser(userId, teamId, term string) (*model.Channel
|
||||
|
||||
term = strings.TrimSpace(term)
|
||||
|
||||
return a.Srv().Store.Channel().SearchForUserInTeam(userId, teamId, term, includeDeleted)
|
||||
channelList, err := a.Srv().Store.Channel().SearchForUserInTeam(userId, teamId, term, includeDeleted)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SearchChannelsForUser", "app.channel.search.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return channelList, nil
|
||||
}
|
||||
|
||||
func (a *App) SearchGroupChannels(userId, term string) (*model.ChannelList, *model.AppError) {
|
||||
@@ -2393,14 +2434,19 @@ func (a *App) SearchGroupChannels(userId, term string) (*model.ChannelList, *mod
|
||||
|
||||
channelList, err := a.Srv().Store.Channel().SearchGroupChannels(userId, term)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, model.NewAppError("SearchGroupChannels", "app.channel.search_group_channels.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return channelList, nil
|
||||
}
|
||||
|
||||
func (a *App) SearchChannelsUserNotIn(teamId string, userId string, term string) (*model.ChannelList, *model.AppError) {
|
||||
term = strings.TrimSpace(term)
|
||||
return a.Srv().Store.Channel().SearchMore(userId, teamId, term)
|
||||
channelList, err := a.Srv().Store.Channel().SearchMore(userId, teamId, term)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SearchChannelsUserNotIn", "app.channel.search.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return channelList, nil
|
||||
}
|
||||
|
||||
func (a *App) MarkChannelsAsViewed(channelIds []string, userId string, currentSessionId string) (map[string]int64, *model.AppError) {
|
||||
@@ -2523,7 +2569,12 @@ func (a *App) PermanentDeleteChannel(channel *model.Channel) *model.AppError {
|
||||
}
|
||||
|
||||
func (a *App) RemoveAllDeactivatedMembersFromChannel(channel *model.Channel) *model.AppError {
|
||||
return a.Srv().Store.Channel().RemoveAllDeactivatedMembers(channel.Id)
|
||||
err := a.Srv().Store.Channel().RemoveAllDeactivatedMembers(channel.Id)
|
||||
if err != nil {
|
||||
return model.NewAppError("RemoveAllDeactivatedMembersFromChannel", "app.channel.remove_all_deactivated_members.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MoveChannel method is prone to data races if someone joins to channel during the move process. However this
|
||||
|
||||
@@ -4,9 +4,12 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
)
|
||||
@@ -26,20 +29,30 @@ func (a *App) GetSidebarCategories(userId, teamId string) (*model.OrderedSidebar
|
||||
|
||||
if err == nil && len(categories.Categories) == 0 {
|
||||
// A user must always have categories, so migration must not have happened yet, and we should run it ourselves
|
||||
nErr := a.createInitialSidebarCategories(userId, teamId)
|
||||
if nErr != nil {
|
||||
return nil, nErr
|
||||
appErr := a.createInitialSidebarCategories(userId, teamId)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
categories, err = a.waitForSidebarCategories(userId, teamId)
|
||||
}
|
||||
|
||||
return categories, err
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("GetSidebarCategories", "app.channel.sidebar_categories.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, model.NewAppError("GetSidebarCategories", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
return categories, nil
|
||||
}
|
||||
|
||||
// waitForSidebarCategories is used to get a user's sidebar categories after they've been created since there may be
|
||||
// replication lag if any database replicas exist. It will wait until results are available to return them.
|
||||
func (a *App) waitForSidebarCategories(userId, teamId string) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
func (a *App) waitForSidebarCategories(userId, teamId string) (*model.OrderedSidebarCategories, error) {
|
||||
if len(a.Config().SqlSettings.DataSourceReplicas) == 0 {
|
||||
// The categories should be available immediately on a single database
|
||||
return a.Srv().Store.Channel().GetSidebarCategories(userId, teamId)
|
||||
@@ -64,17 +77,45 @@ func (a *App) waitForSidebarCategories(userId, teamId string) (*model.OrderedSid
|
||||
}
|
||||
|
||||
func (a *App) GetSidebarCategoryOrder(userId, teamId string) ([]string, *model.AppError) {
|
||||
return a.Srv().Store.Channel().GetSidebarCategoryOrder(userId, teamId)
|
||||
categories, err := a.Srv().Store.Channel().GetSidebarCategoryOrder(userId, teamId)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("GetSidebarCategoryOrder", "app.channel.sidebar_categories.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, model.NewAppError("GetSidebarCategoryOrder", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
return categories, nil
|
||||
}
|
||||
|
||||
func (a *App) GetSidebarCategory(categoryId string) (*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
return a.Srv().Store.Channel().GetSidebarCategory(categoryId)
|
||||
category, err := a.Srv().Store.Channel().GetSidebarCategory(categoryId)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("GetSidebarCategory", "app.channel.sidebar_categories.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, model.NewAppError("GetSidebarCategory", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
return category, nil
|
||||
}
|
||||
|
||||
func (a *App) CreateSidebarCategory(userId, teamId string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
category, err := a.Srv().Store.Channel().CreateSidebarCategory(userId, teamId, newCategory)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("CreateSidebarCategory", "app.channel.sidebar_categories.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, model.NewAppError("CreateSidebarCategory", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_SIDEBAR_CATEGORY_CREATED, teamId, "", userId, nil)
|
||||
message.Add("category_id", category.Id)
|
||||
@@ -85,7 +126,16 @@ func (a *App) CreateSidebarCategory(userId, teamId string, newCategory *model.Si
|
||||
func (a *App) UpdateSidebarCategoryOrder(userId, teamId string, categoryOrder []string) *model.AppError {
|
||||
err := a.Srv().Store.Channel().UpdateSidebarCategoryOrder(userId, teamId, categoryOrder)
|
||||
if err != nil {
|
||||
return err
|
||||
var nfErr *store.ErrNotFound
|
||||
var invErr *store.ErrInvalidInput
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return model.NewAppError("UpdateSidebarCategoryOrder", "app.channel.sidebar_categories.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
case errors.As(err, &invErr):
|
||||
return model.NewAppError("UpdateSidebarCategoryOrder", "app.channel.sidebar_categories.app_error", nil, invErr.Error(), http.StatusBadRequest)
|
||||
default:
|
||||
return model.NewAppError("UpdateSidebarCategoryOrder", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_SIDEBAR_CATEGORY_ORDER_UPDATED, teamId, "", userId, nil)
|
||||
message.Add("order", categoryOrder)
|
||||
@@ -96,8 +146,9 @@ func (a *App) UpdateSidebarCategoryOrder(userId, teamId string, categoryOrder []
|
||||
func (a *App) UpdateSidebarCategories(userId, teamId string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
result, err := a.Srv().Store.Channel().UpdateSidebarCategories(userId, teamId, categories)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, model.NewAppError("UpdateSidebarCategories", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_SIDEBAR_CATEGORY_UPDATED, teamId, "", userId, nil)
|
||||
a.Publish(message)
|
||||
return result, nil
|
||||
@@ -106,7 +157,13 @@ func (a *App) UpdateSidebarCategories(userId, teamId string, categories []*model
|
||||
func (a *App) DeleteSidebarCategory(userId, teamId, categoryId string) *model.AppError {
|
||||
err := a.Srv().Store.Channel().DeleteSidebarCategory(categoryId)
|
||||
if err != nil {
|
||||
return err
|
||||
var invErr *store.ErrInvalidInput
|
||||
switch {
|
||||
case errors.As(err, &invErr):
|
||||
return model.NewAppError("DeleteSidebarCategory", "app.channel.sidebar_categories.app_error", nil, invErr.Error(), http.StatusBadRequest)
|
||||
default:
|
||||
return model.NewAppError("DeleteSidebarCategory", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_SIDEBAR_CATEGORY_DELETED, teamId, "", userId, nil)
|
||||
|
||||
@@ -129,6 +129,6 @@ func TestGetSidebarCategories(t *testing.T) {
|
||||
categories, appErr := th.App.GetSidebarCategories(th.BasicUser.Id, th.BasicTeam.Id)
|
||||
assert.Nil(t, categories)
|
||||
assert.NotNil(t, appErr)
|
||||
assert.Equal(t, "store.sql_channel.sidebar_categories.app_error", appErr.Id)
|
||||
assert.Equal(t, "app.channel.sidebar_categories.app_error", appErr.Id)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ func (a *App) exportAllChannels(writer io.Writer) *model.AppError {
|
||||
channels, err := a.Srv().Store.Channel().GetAllChannelsForExportAfter(1000, afterId)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
return model.NewAppError("exportAllChannels", "app.channel.get_all.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if len(channels) == 0 {
|
||||
@@ -296,9 +296,9 @@ func (a *App) buildUserTeamAndChannelMemberships(userId string) (*[]UserTeamImpo
|
||||
func (a *App) buildUserChannelMemberships(userId string, teamId string) (*[]UserChannelImportData, *model.AppError) {
|
||||
var memberships []UserChannelImportData
|
||||
|
||||
members, err := a.Srv().Store.Channel().GetChannelMembersForExport(userId, teamId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
members, nErr := a.Srv().Store.Channel().GetChannelMembersForExport(userId, teamId)
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("buildUserChannelMemberships", "app.channel.get_members.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
category := model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL
|
||||
@@ -517,7 +517,7 @@ func (a *App) exportAllDirectChannels(writer io.Writer) *model.AppError {
|
||||
for {
|
||||
channels, err := a.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, afterId)
|
||||
if err != nil {
|
||||
return err
|
||||
return model.NewAppError("exportAllDirectChannels", "app.channel.get_all_direct.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if len(channels) == 0 {
|
||||
|
||||
@@ -231,8 +231,8 @@ func TestExportDMChannel(t *testing.T) {
|
||||
err := th1.App.BulkExport(&b, "somefile", "somePath", "someDir")
|
||||
require.Nil(t, err)
|
||||
|
||||
channels, err := th1.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
channels, nErr := th1.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, nErr)
|
||||
assert.Equal(t, 1, len(channels))
|
||||
|
||||
th1.TearDown()
|
||||
@@ -240,8 +240,8 @@ func TestExportDMChannel(t *testing.T) {
|
||||
th2 := Setup(t)
|
||||
defer th2.TearDown()
|
||||
|
||||
channels, err = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
channels, nErr = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, nErr)
|
||||
assert.Equal(t, 0, len(channels))
|
||||
|
||||
// import the exported channel
|
||||
@@ -250,8 +250,8 @@ func TestExportDMChannel(t *testing.T) {
|
||||
assert.Equal(t, 0, i)
|
||||
|
||||
// Ensure the Members of the imported DM channel is the same was from the exported
|
||||
channels, err = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
channels, nErr = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, nErr)
|
||||
assert.Equal(t, 1, len(channels))
|
||||
assert.ElementsMatch(t, []string{th1.BasicUser.Username, th1.BasicUser2.Username}, *channels[0].Members)
|
||||
}
|
||||
@@ -267,15 +267,15 @@ func TestExportDMChannelToSelf(t *testing.T) {
|
||||
err := th1.App.BulkExport(&b, "somefile", "somePath", "someDir")
|
||||
require.Nil(t, err)
|
||||
|
||||
channels, err := th1.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
channels, nErr := th1.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, nErr)
|
||||
assert.Equal(t, 1, len(channels))
|
||||
|
||||
th2 := Setup(t)
|
||||
defer th2.TearDown()
|
||||
|
||||
channels, err = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
channels, nErr = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, nErr)
|
||||
assert.Equal(t, 0, len(channels))
|
||||
|
||||
// import the exported channel
|
||||
@@ -283,8 +283,8 @@ func TestExportDMChannelToSelf(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 0, i)
|
||||
|
||||
channels, err = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
channels, nErr = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, nErr)
|
||||
assert.Equal(t, 1, len(channels))
|
||||
assert.Equal(t, 1, len((*channels[0].Members)))
|
||||
assert.Equal(t, th1.BasicUser.Username, (*channels[0].Members)[0])
|
||||
@@ -305,8 +305,8 @@ func TestExportGMChannel(t *testing.T) {
|
||||
err := th1.App.BulkExport(&b, "somefile", "somePath", "someDir")
|
||||
require.Nil(t, err)
|
||||
|
||||
channels, err := th1.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
channels, nErr := th1.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, nErr)
|
||||
assert.Equal(t, 1, len(channels))
|
||||
|
||||
th1.TearDown()
|
||||
@@ -314,8 +314,8 @@ func TestExportGMChannel(t *testing.T) {
|
||||
th2 := Setup(t)
|
||||
defer th2.TearDown()
|
||||
|
||||
channels, err = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
channels, nErr = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, nErr)
|
||||
assert.Equal(t, 0, len(channels))
|
||||
}
|
||||
|
||||
@@ -337,8 +337,8 @@ func TestExportGMandDMChannels(t *testing.T) {
|
||||
err := th1.App.BulkExport(&b, "somefile", "somePath", "someDir")
|
||||
require.Nil(t, err)
|
||||
|
||||
channels, err := th1.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
channels, nErr := th1.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, nErr)
|
||||
assert.Equal(t, 2, len(channels))
|
||||
|
||||
th1.TearDown()
|
||||
@@ -346,8 +346,8 @@ func TestExportGMandDMChannels(t *testing.T) {
|
||||
th2 := Setup(t)
|
||||
defer th2.TearDown()
|
||||
|
||||
channels, err = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
channels, nErr = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, nErr)
|
||||
assert.Equal(t, 0, len(channels))
|
||||
|
||||
// import the exported channel
|
||||
@@ -356,8 +356,8 @@ func TestExportGMandDMChannels(t *testing.T) {
|
||||
assert.Equal(t, 0, i)
|
||||
|
||||
// Ensure the Members of the imported GM channel is the same was from the exported
|
||||
channels, err = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
channels, nErr = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, nErr)
|
||||
|
||||
// Adding some deteminism so its possible to assert on slice index
|
||||
sort.Slice(channels, func(i, j int) bool { return channels[i].Type > channels[j].Type })
|
||||
|
||||
@@ -25,7 +25,7 @@ func (a *App) ResetPermissionsSystem() *model.AppError {
|
||||
|
||||
// Reset all Channels to not have a scheme.
|
||||
if err := a.Srv().Store.Channel().ResetAllChannelSchemes(); err != nil {
|
||||
return err
|
||||
return model.NewAppError("ResetPermissionsSystem", "app.channel.reset_all_channel_schemes.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
// Reset all Custom Role assignments to Users.
|
||||
@@ -40,7 +40,7 @@ func (a *App) ResetPermissionsSystem() *model.AppError {
|
||||
|
||||
// Reset all Custom Role assignments to ChannelMembers.
|
||||
if err := a.Srv().Store.Channel().ClearAllCustomRoleAssignments(); err != nil {
|
||||
return err
|
||||
return model.NewAppError("ResetPermissionsSystem", "app.channel.clear_all_custom_role_assignments.select.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
// Purge all schemes from the database.
|
||||
|
||||
@@ -188,7 +188,13 @@ func (a *App) GetChannelsForScheme(scheme *model.Scheme, offset int, limit int)
|
||||
if err := a.IsPhase2MigrationCompleted(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return a.Srv().Store.Channel().GetChannelsByScheme(scheme.Id, offset, limit)
|
||||
|
||||
channelList, nErr := a.Srv().Store.Channel().GetChannelsByScheme(scheme.Id, offset, limit)
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("GetChannelsForScheme", "app.channel.get_by_scheme.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return channelList, nil
|
||||
}
|
||||
|
||||
func (s *Server) IsPhase2MigrationCompleted() *model.AppError {
|
||||
|
||||
@@ -209,12 +209,15 @@ func (a *App) SyncSyncableRoles(syncableID string, syncableType model.GroupSynca
|
||||
nErr := a.Srv().Store.Team().UpdateMembersRole(syncableID, permittedAdmins)
|
||||
if nErr != nil {
|
||||
// TODO: Should we change the key "store.update_error" to "app.update_error"? It is very general and changing it now will modify lots of files
|
||||
return model.NewAppError("SyncSyncableRoles", "store.update_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
return model.NewAppError("App.SyncSyncableRoles", "store.update_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return nil
|
||||
case model.GroupSyncableTypeChannel:
|
||||
return a.Srv().Store.Channel().UpdateMembersRole(syncableID, permittedAdmins)
|
||||
nErr := a.Srv().Store.Channel().UpdateMembersRole(syncableID, permittedAdmins)
|
||||
if nErr != nil {
|
||||
return model.NewAppError("App.SyncSyncableRoles", "store.update_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return model.NewAppError("App.SyncSyncableRoles", "groups.unsupported_syncable_type", map[string]interface{}{"Value": syncableType}, "", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -2006,7 +2006,12 @@ func (a *App) UserCanSeeOtherUser(userId string, otherUserId string) (bool, *mod
|
||||
}
|
||||
|
||||
func (a *App) userBelongsToChannels(userId string, channelIds []string) (bool, *model.AppError) {
|
||||
return a.Srv().Store.Channel().UserBelongsToChannels(userId, channelIds)
|
||||
belongs, err := a.Srv().Store.Channel().UserBelongsToChannels(userId, channelIds)
|
||||
if err != nil {
|
||||
return false, model.NewAppError("userBelongsToChannels", "app.channel.user_belongs_to_channels.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return belongs, nil
|
||||
}
|
||||
|
||||
func (a *App) GetViewUsersRestrictions(userId string) (*model.ViewUsersRestrictions, *model.AppError) {
|
||||
|
||||
Ссылка в новой задаче
Block a user