mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[MM-25314] Migrate AppError from channel_member_history_store.go (#14693)
* Migrate AppError from channel_member_history_store * Migrate AppError from channel_member_history_store * Migrate AppError from channel_member_history_store * Migrate AppError from channel_member_history_store * Migrating error keys * Review fixes. * Regenerating i18n * Add some i18n strings Co-authored-by: Dante Pippi <6619666+dantepippi@users.noreply.github.com> Co-authored-by: Jesús Espino <jespinog@gmail.com> Co-authored-by: mattermod <mattermod@users.noreply.github.com>
This commit is contained in:
@@ -97,7 +97,7 @@ func (a *App) JoinDefaultChannels(teamId string, user *model.User, shouldBeAdmin
|
||||
_, err = a.Srv().Store.Channel().SaveMember(cm)
|
||||
if histErr := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); histErr != nil {
|
||||
mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(histErr))
|
||||
return histErr
|
||||
return model.NewAppError("JoinDefaultChannels", "app.channel_member_history.log_join_event.internal_error", nil, histErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if *a.Config().ServiceSettings.ExperimentalEnableDefaultChannelLeaveJoinMessages {
|
||||
@@ -253,7 +253,7 @@ func (a *App) CreateChannel(channel *model.Channel, addMember bool) (*model.Chan
|
||||
}
|
||||
if err := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(channel.CreatorId, sc.Id, model.GetMillis()); err != nil {
|
||||
mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(err))
|
||||
return nil, err
|
||||
return nil, model.NewAppError("CreateChannel", "app.channel_member_history.log_join_event.internal_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
a.InvalidateCacheForUser(channel.CreatorId)
|
||||
@@ -370,12 +370,12 @@ func (a *App) createDirectChannel(userId string, otherUserId string) (*model.Cha
|
||||
|
||||
if err := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(userId, channel.Id, model.GetMillis()); err != nil {
|
||||
mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(err))
|
||||
return nil, err
|
||||
return nil, model.NewAppError("CreateDirectChannel", "app.channel_member_history.log_join_event.internal_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
if userId != otherUserId {
|
||||
if err := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(otherUserId, channel.Id, model.GetMillis()); err != nil {
|
||||
mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(err))
|
||||
return nil, err
|
||||
return nil, model.NewAppError("CreateDirectChannel", "app.channel_member_history.log_join_event.internal_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -494,7 +494,7 @@ func (a *App) createGroupChannel(userIds []string, creatorId string) (*model.Cha
|
||||
}
|
||||
if err := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); err != nil {
|
||||
mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(err))
|
||||
return nil, err
|
||||
return nil, model.NewAppError("createGroupChannel", "app.channel_member_history.log_join_event.internal_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1257,9 +1257,9 @@ func (a *App) addUserToChannel(user *model.User, channel *model.Channel, teamMem
|
||||
}
|
||||
a.WaitForChannelMembership(channel.Id, user.Id)
|
||||
|
||||
if err = a.Srv().Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); err != nil {
|
||||
mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(err))
|
||||
return nil, err
|
||||
if nErr := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); nErr != nil {
|
||||
mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(nErr))
|
||||
return nil, model.NewAppError("AddUserToChannel", "app.channel_member_history.log_join_event.internal_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
a.InvalidateCacheForUser(user.Id)
|
||||
@@ -1966,7 +1966,7 @@ func (a *App) removeUserFromChannel(userIdToRemove string, removerUserId string,
|
||||
return err
|
||||
}
|
||||
if err := a.Srv().Store.ChannelMemberHistory().LogLeaveEvent(userIdToRemove, channel.Id, model.GetMillis()); err != nil {
|
||||
return err
|
||||
return model.NewAppError("removeUserFromChannel", "app.channel_member_history.log_leave_event.internal_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if isGuest {
|
||||
|
||||
@@ -154,8 +154,8 @@ func TestJoinDefaultChannelsCreatesChannelMemberHistoryRecordTownSquare(t *testi
|
||||
channel, err := th.App.Srv().Store.Channel().GetByName(th.BasicTeam.Id, "town-square", true)
|
||||
require.Nil(t, err)
|
||||
townSquareChannelId := channel.Id
|
||||
users, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, townSquareChannelId)
|
||||
require.Nil(t, err)
|
||||
users, nErr := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, townSquareChannelId)
|
||||
require.Nil(t, nErr)
|
||||
initialNumTownSquareUsers := len(users)
|
||||
|
||||
// create a new user that joins the default channels
|
||||
@@ -163,8 +163,8 @@ func TestJoinDefaultChannelsCreatesChannelMemberHistoryRecordTownSquare(t *testi
|
||||
th.App.JoinDefaultChannels(th.BasicTeam.Id, user, false, "")
|
||||
|
||||
// there should be a ChannelMemberHistory record for the user
|
||||
histories, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, townSquareChannelId)
|
||||
require.Nil(t, err)
|
||||
histories, nErr := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, townSquareChannelId)
|
||||
require.Nil(t, nErr)
|
||||
assert.Len(t, histories, initialNumTownSquareUsers+1)
|
||||
|
||||
found := false
|
||||
@@ -185,8 +185,8 @@ func TestJoinDefaultChannelsCreatesChannelMemberHistoryRecordOffTopic(t *testing
|
||||
channel, err := th.App.Srv().Store.Channel().GetByName(th.BasicTeam.Id, "off-topic", true)
|
||||
require.Nil(t, err)
|
||||
offTopicChannelId := channel.Id
|
||||
users, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, offTopicChannelId)
|
||||
require.Nil(t, err)
|
||||
users, nErr := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, offTopicChannelId)
|
||||
require.Nil(t, nErr)
|
||||
initialNumTownSquareUsers := len(users)
|
||||
|
||||
// create a new user that joins the default channels
|
||||
@@ -194,8 +194,8 @@ func TestJoinDefaultChannelsCreatesChannelMemberHistoryRecordOffTopic(t *testing
|
||||
th.App.JoinDefaultChannels(th.BasicTeam.Id, user, false, "")
|
||||
|
||||
// there should be a ChannelMemberHistory record for the user
|
||||
histories, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, offTopicChannelId)
|
||||
require.Nil(t, err)
|
||||
histories, nErr := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, offTopicChannelId)
|
||||
require.Nil(t, nErr)
|
||||
assert.Len(t, histories, initialNumTownSquareUsers+1)
|
||||
|
||||
found := false
|
||||
@@ -298,8 +298,8 @@ func TestCreateGroupChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
|
||||
channel, err := th.App.CreateGroupChannel(groupUserIds, th.BasicUser.Id)
|
||||
|
||||
require.Nil(t, err, "Failed to create group channel.")
|
||||
histories, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
require.Nil(t, err)
|
||||
histories, nErr := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
require.Nil(t, nErr)
|
||||
assert.Len(t, histories, 3)
|
||||
|
||||
channelMemberHistoryUserIds := make([]string, 0)
|
||||
@@ -323,8 +323,8 @@ func TestCreateDirectChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
|
||||
channel, err := th.App.GetOrCreateDirectChannel(user1.Id, user2.Id)
|
||||
require.Nil(t, err, "Failed to create direct channel.")
|
||||
|
||||
histories, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
require.Nil(t, err)
|
||||
histories, nErr := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
require.Nil(t, nErr)
|
||||
assert.Len(t, histories, 2)
|
||||
|
||||
historyId0 := histories[0].UserId
|
||||
@@ -351,8 +351,8 @@ func TestGetDirectChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
|
||||
require.Nil(t, err, "Failed to create direct channel.")
|
||||
|
||||
// there should be a ChannelMemberHistory record for both users
|
||||
histories, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
require.Nil(t, err)
|
||||
histories, nErr := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
require.Nil(t, nErr)
|
||||
assert.Len(t, histories, 2)
|
||||
|
||||
historyId0 := histories[0].UserId
|
||||
@@ -386,8 +386,8 @@ func TestAddUserToChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
|
||||
require.Nil(t, err, "Failed to add user to channel.")
|
||||
|
||||
// there should be a ChannelMemberHistory record for the user
|
||||
histories, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
require.Nil(t, err)
|
||||
histories, nErr := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
require.Nil(t, nErr)
|
||||
assert.Len(t, histories, 2)
|
||||
channelMemberHistoryUserIds := make([]string, 0)
|
||||
for _, history := range histories {
|
||||
@@ -474,8 +474,8 @@ func TestAddChannelMemberNoUserRequestor(t *testing.T) {
|
||||
require.Nil(t, err, "Failed to add user to channel.")
|
||||
|
||||
// there should be a ChannelMemberHistory record for the user
|
||||
histories, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
require.Nil(t, err)
|
||||
histories, nErr := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
require.Nil(t, nErr)
|
||||
assert.Len(t, histories, 2)
|
||||
channelMemberHistoryUserIds := make([]string, 0)
|
||||
for _, history := range histories {
|
||||
|
||||
@@ -297,9 +297,9 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
timeAfterLeaving := model.GetMillis()
|
||||
|
||||
// Purging channelmemberhistory doesn't re-add user to channel
|
||||
_, err = th.App.Srv().Store.ChannelMemberHistory().PermanentDeleteBatch(timeBeforeLeaving, 1000)
|
||||
if err != nil {
|
||||
t.Errorf("error permanently deleting channelmemberhistory: %s", err.Error())
|
||||
_, nErr := th.App.Srv().Store.ChannelMemberHistory().PermanentDeleteBatch(timeBeforeLeaving, 1000)
|
||||
if nErr != nil {
|
||||
t.Errorf("error permanently deleting channelmemberhistory: %s", nErr.Error())
|
||||
}
|
||||
|
||||
pErr = th.App.CreateDefaultMemberships(scienceChannelGroupSyncable.UpdateAt)
|
||||
@@ -313,9 +313,9 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
}
|
||||
|
||||
// Purging channelmemberhistory doesn't re-add user to channel
|
||||
_, err = th.App.Srv().Jobs.Store.ChannelMemberHistory().PermanentDeleteBatch(timeAfterLeaving, 1000)
|
||||
if err != nil {
|
||||
t.Errorf("error permanently deleting channelmemberhistory: %s", err.Error())
|
||||
_, nErr = th.App.Srv().Jobs.Store.ChannelMemberHistory().PermanentDeleteBatch(timeAfterLeaving, 1000)
|
||||
if nErr != nil {
|
||||
t.Errorf("error permanently deleting channelmemberhistory: %s", nErr.Error())
|
||||
}
|
||||
|
||||
pErr = th.App.CreateDefaultMemberships(scienceChannelGroupSyncable.UpdateAt)
|
||||
|
||||
32
i18n/en.json
32
i18n/en.json
@@ -3026,6 +3026,14 @@
|
||||
"id": "app.channel.update_channel.internal_error",
|
||||
"translation": "Unable to update channel."
|
||||
},
|
||||
{
|
||||
"id": "app.channel_member_history.log_join_event.internal_error",
|
||||
"translation": "Failed to record channel member history."
|
||||
},
|
||||
{
|
||||
"id": "app.channel_member_history.log_leave_event.internal_error",
|
||||
"translation": "Failed to record channel member history. Failed to update existing join record"
|
||||
},
|
||||
{
|
||||
"id": "app.cluster.404.app_error",
|
||||
"translation": "Cluster API endpoint not found."
|
||||
@@ -4158,6 +4166,10 @@
|
||||
"id": "ent.compliance.run_failed.error",
|
||||
"translation": "Compliance export failed for job '{{.JobName}}' at '{{.FilePath}}'"
|
||||
},
|
||||
{
|
||||
"id": "ent.data_retention.channel_member_history_batch.internal_error",
|
||||
"translation": "Failed to purge records."
|
||||
},
|
||||
{
|
||||
"id": "ent.data_retention.generic.license.error",
|
||||
"translation": "Your license does not support Data Retention."
|
||||
@@ -4334,6 +4346,10 @@
|
||||
"id": "ent.elasticsearch.test_config.reenter_password",
|
||||
"translation": "The Elasticsearch Server URL or Username has changed. Please re-enter the Elasticsearch password to test connection."
|
||||
},
|
||||
{
|
||||
"id": "ent.get_users_in_channel_during",
|
||||
"translation": "Failed to get users in channel during specified time period."
|
||||
},
|
||||
{
|
||||
"id": "ent.id_loaded.license_disable.app_error",
|
||||
"translation": "Your license does not support ID Loaded Push Notifications."
|
||||
@@ -6358,22 +6374,6 @@
|
||||
"id": "store.sql_channel.user_belongs_to_channels.app_error",
|
||||
"translation": "Unable to determine if the user belongs to a list of channels."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_channel_member_history.get_users_in_channel_during.app_error",
|
||||
"translation": "Failed to get users in channel during specified time period."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_channel_member_history.log_join_event.app_error",
|
||||
"translation": "Failed to record channel member history."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_channel_member_history.log_leave_event.update_error",
|
||||
"translation": "Failed to record channel member history. Failed to update existing join record"
|
||||
},
|
||||
{
|
||||
"id": "store.sql_channel_member_history.permanent_delete_batch.app_error",
|
||||
"translation": "Failed to purge records."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_cluster_discovery.cleanup.app_error",
|
||||
"translation": "Failed to save ClusterDiscovery row."
|
||||
|
||||
@@ -1989,7 +1989,7 @@ func (s *OpenTracingLayerChannelStore) UserBelongsToChannels(userId string, chan
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelMemberHistoryStore) GetUsersInChannelDuring(startTime int64, endTime int64, channelId string) ([]*model.ChannelMemberHistoryResult, *model.AppError) {
|
||||
func (s *OpenTracingLayerChannelMemberHistoryStore) GetUsersInChannelDuring(startTime int64, endTime int64, channelId string) ([]*model.ChannelMemberHistoryResult, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelMemberHistoryStore.GetUsersInChannelDuring")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -2007,7 +2007,7 @@ func (s *OpenTracingLayerChannelMemberHistoryStore) GetUsersInChannelDuring(star
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelMemberHistoryStore) LogJoinEvent(userId string, channelId string, joinTime int64) *model.AppError {
|
||||
func (s *OpenTracingLayerChannelMemberHistoryStore) LogJoinEvent(userId string, channelId string, joinTime int64) error {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelMemberHistoryStore.LogJoinEvent")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -2025,7 +2025,7 @@ func (s *OpenTracingLayerChannelMemberHistoryStore) LogJoinEvent(userId string,
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelMemberHistoryStore) LogLeaveEvent(userId string, channelId string, leaveTime int64) *model.AppError {
|
||||
func (s *OpenTracingLayerChannelMemberHistoryStore) LogLeaveEvent(userId string, channelId string, leaveTime int64) error {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelMemberHistoryStore.LogLeaveEvent")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -2043,7 +2043,7 @@ func (s *OpenTracingLayerChannelMemberHistoryStore) LogLeaveEvent(userId string,
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelMemberHistoryStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError) {
|
||||
func (s *OpenTracingLayerChannelMemberHistoryStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelMemberHistoryStore.PermanentDeleteBatch")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
|
||||
@@ -5,11 +5,12 @@ package sqlstore
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type SqlChannelMemberHistoryStore struct {
|
||||
@@ -31,7 +32,7 @@ func newSqlChannelMemberHistoryStore(sqlStore SqlStore) store.ChannelMemberHisto
|
||||
return s
|
||||
}
|
||||
|
||||
func (s SqlChannelMemberHistoryStore) LogJoinEvent(userId string, channelId string, joinTime int64) *model.AppError {
|
||||
func (s SqlChannelMemberHistoryStore) LogJoinEvent(userId string, channelId string, joinTime int64) error {
|
||||
channelMemberHistory := &model.ChannelMemberHistory{
|
||||
UserId: userId,
|
||||
ChannelId: channelId,
|
||||
@@ -39,12 +40,12 @@ func (s SqlChannelMemberHistoryStore) LogJoinEvent(userId string, channelId stri
|
||||
}
|
||||
|
||||
if err := s.GetMaster().Insert(channelMemberHistory); err != nil {
|
||||
return model.NewAppError("SqlChannelMemberHistoryStore.LogJoinEvent", "store.sql_channel_member_history.log_join_event.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return errors.Wrapf(err, "LogJoinEvent userId=%s channelId=%s joinTime=%d", userId, channelId, joinTime)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlChannelMemberHistoryStore) LogLeaveEvent(userId string, channelId string, leaveTime int64) *model.AppError {
|
||||
func (s SqlChannelMemberHistoryStore) LogLeaveEvent(userId string, channelId string, leaveTime int64) error {
|
||||
query := `
|
||||
UPDATE ChannelMemberHistory
|
||||
SET LeaveTime = :LeaveTime
|
||||
@@ -55,7 +56,7 @@ func (s SqlChannelMemberHistoryStore) LogLeaveEvent(userId string, channelId str
|
||||
params := map[string]interface{}{"UserId": userId, "ChannelId": channelId, "LeaveTime": leaveTime}
|
||||
sqlResult, err := s.GetMaster().Exec(query, params)
|
||||
if err != nil {
|
||||
return model.NewAppError("SqlChannelMemberHistoryStore.LogLeaveEvent", "store.sql_channel_member_history.log_leave_event.update_error", params, err.Error(), http.StatusInternalServerError)
|
||||
return errors.Wrapf(err, "LogLeaveEvent userId=%s channelId=%s leaveTime=%d", userId, channelId, leaveTime)
|
||||
}
|
||||
|
||||
if rows, err := sqlResult.RowsAffected(); err == nil && rows != 1 {
|
||||
@@ -65,10 +66,10 @@ func (s SqlChannelMemberHistoryStore) LogLeaveEvent(userId string, channelId str
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlChannelMemberHistoryStore) GetUsersInChannelDuring(startTime int64, endTime int64, channelId string) ([]*model.ChannelMemberHistoryResult, *model.AppError) {
|
||||
func (s SqlChannelMemberHistoryStore) GetUsersInChannelDuring(startTime int64, endTime int64, channelId string) ([]*model.ChannelMemberHistoryResult, error) {
|
||||
useChannelMemberHistory, err := s.hasDataAtOrBefore(startTime)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlChannelMemberHistoryStore.GetUsersInChannelAt", "store.sql_channel_member_history.get_users_in_channel_during.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrapf(err, "hasDataAtOrBefore startTime=%d endTime=%d channelId=%s", startTime, endTime, channelId)
|
||||
}
|
||||
|
||||
if useChannelMemberHistory {
|
||||
@@ -76,7 +77,7 @@ func (s SqlChannelMemberHistoryStore) GetUsersInChannelDuring(startTime int64, e
|
||||
// data from it for our export
|
||||
channelMemberHistories, err2 := s.getFromChannelMemberHistoryTable(startTime, endTime, channelId)
|
||||
if err2 != nil {
|
||||
return nil, model.NewAppError("SqlChannelMemberHistoryStore.GetUsersInChannelAt", "store.sql_channel_member_history.get_users_in_channel_during.app_error", nil, err2.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrapf(err2, "getFromChannelMemberHistoryTable startTime=%d endTime=%d channelId=%s", startTime, endTime, channelId)
|
||||
}
|
||||
return channelMemberHistories, nil
|
||||
}
|
||||
@@ -86,7 +87,7 @@ func (s SqlChannelMemberHistoryStore) GetUsersInChannelDuring(startTime int64, e
|
||||
// this may not always be true, but it's better than saying that somebody wasn't there when they were
|
||||
channelMemberHistories, err := s.getFromChannelMembersTable(startTime, endTime, channelId)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlChannelMemberHistoryStore.GetUsersInChannelAt", "store.sql_channel_member_history.get_users_in_channel_during.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrapf(err, "getFromChannelMembersTable startTime=%d endTime=%d channelId=%s", startTime, endTime, channelId)
|
||||
}
|
||||
return channelMemberHistories, nil
|
||||
}
|
||||
@@ -126,9 +127,9 @@ func (s SqlChannelMemberHistoryStore) getFromChannelMemberHistoryTable(startTime
|
||||
var histories []*model.ChannelMemberHistoryResult
|
||||
if _, err := s.GetReplica().Select(&histories, query, params); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return histories, nil
|
||||
}
|
||||
|
||||
return histories, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelMemberHistoryStore) getFromChannelMembersTable(startTime int64, endTime int64, channelId string) ([]*model.ChannelMemberHistoryResult, error) {
|
||||
@@ -149,17 +150,16 @@ func (s SqlChannelMemberHistoryStore) getFromChannelMembersTable(startTime int64
|
||||
var histories []*model.ChannelMemberHistoryResult
|
||||
if _, err := s.GetReplica().Select(&histories, query, params); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
// we have to fill in the join/leave times, because that data doesn't exist in the channel members table
|
||||
for _, channelMemberHistory := range histories {
|
||||
channelMemberHistory.JoinTime = startTime
|
||||
channelMemberHistory.LeaveTime = model.NewInt64(endTime)
|
||||
}
|
||||
return histories, nil
|
||||
}
|
||||
// we have to fill in the join/leave times, because that data doesn't exist in the channel members table
|
||||
for _, channelMemberHistory := range histories {
|
||||
channelMemberHistory.JoinTime = startTime
|
||||
channelMemberHistory.LeaveTime = model.NewInt64(endTime)
|
||||
}
|
||||
return histories, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelMemberHistoryStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError) {
|
||||
func (s SqlChannelMemberHistoryStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, error) {
|
||||
var query string
|
||||
if s.DriverName() == model.DATABASE_DRIVER_POSTGRES {
|
||||
query =
|
||||
@@ -181,12 +181,12 @@ func (s SqlChannelMemberHistoryStore) PermanentDeleteBatch(endTime int64, limit
|
||||
params := map[string]interface{}{"EndTime": endTime, "Limit": limit}
|
||||
sqlResult, err := s.GetMaster().Exec(query, params)
|
||||
if err != nil {
|
||||
return int64(0), model.NewAppError("SqlChannelMemberHistoryStore.PermanentDeleteBatchForChannel", "store.sql_channel_member_history.permanent_delete_batch.app_error", params, err.Error(), http.StatusInternalServerError)
|
||||
return 0, errors.Wrapf(err, "PermanentDeleteBatch endTime=%d limit=%d", endTime, limit)
|
||||
}
|
||||
|
||||
rowsAffected, err := sqlResult.RowsAffected()
|
||||
if err != nil {
|
||||
return int64(0), model.NewAppError("SqlChannelMemberHistoryStore.PermanentDeleteBatchForChannel", "store.sql_channel_member_history.permanent_delete_batch.app_error", params, err.Error(), http.StatusInternalServerError)
|
||||
return 0, errors.Wrapf(err, "PermanentDeleteBatch endTime=%d limit=%d", endTime, limit)
|
||||
}
|
||||
return rowsAffected, nil
|
||||
}
|
||||
|
||||
@@ -225,10 +225,10 @@ type ChannelStore interface {
|
||||
}
|
||||
|
||||
type ChannelMemberHistoryStore interface {
|
||||
LogJoinEvent(userId string, channelId string, joinTime int64) *model.AppError
|
||||
LogLeaveEvent(userId string, channelId string, leaveTime int64) *model.AppError
|
||||
GetUsersInChannelDuring(startTime int64, endTime int64, channelId string) ([]*model.ChannelMemberHistoryResult, *model.AppError)
|
||||
PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError)
|
||||
LogJoinEvent(userId string, channelId string, joinTime int64) error
|
||||
LogLeaveEvent(userId string, channelId string, leaveTime int64) error
|
||||
GetUsersInChannelDuring(startTime int64, endTime int64, channelId string) ([]*model.ChannelMemberHistoryResult, error)
|
||||
PermanentDeleteBatch(endTime int64, limit int64) (int64, error)
|
||||
}
|
||||
|
||||
type PostStore interface {
|
||||
|
||||
@@ -1707,22 +1707,22 @@ func testChannelMembersToAdd(t *testing.T, ss store.Store) {
|
||||
require.Len(t, channelMembers, 1)
|
||||
|
||||
// Adding Channel (ChannelMemberHistory) should stop returning result
|
||||
err = ss.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis())
|
||||
require.Nil(t, err)
|
||||
nErr = ss.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis())
|
||||
require.Nil(t, nErr)
|
||||
channelMembers, err = ss.Group().ChannelMembersToAdd(0, nil)
|
||||
require.Nil(t, err)
|
||||
require.Empty(t, channelMembers)
|
||||
|
||||
// Leaving Channel (ChannelMemberHistory) should still not return result
|
||||
err = ss.ChannelMemberHistory().LogLeaveEvent(user.Id, channel.Id, model.GetMillis())
|
||||
require.Nil(t, err)
|
||||
nErr = ss.ChannelMemberHistory().LogLeaveEvent(user.Id, channel.Id, model.GetMillis())
|
||||
require.Nil(t, nErr)
|
||||
channelMembers, err = ss.Group().ChannelMembersToAdd(0, nil)
|
||||
require.Nil(t, err)
|
||||
require.Empty(t, channelMembers)
|
||||
|
||||
// Purging ChannelMemberHistory re-returns the result
|
||||
_, err = ss.ChannelMemberHistory().PermanentDeleteBatch(model.GetMillis()+1, 100)
|
||||
require.Nil(t, err)
|
||||
_, nErr = ss.ChannelMemberHistory().PermanentDeleteBatch(model.GetMillis()+1, 100)
|
||||
require.Nil(t, nErr)
|
||||
channelMembers, err = ss.Group().ChannelMembersToAdd(0, nil)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, channelMembers, 1)
|
||||
|
||||
@@ -15,7 +15,7 @@ type ChannelMemberHistoryStore struct {
|
||||
}
|
||||
|
||||
// GetUsersInChannelDuring provides a mock function with given fields: startTime, endTime, channelId
|
||||
func (_m *ChannelMemberHistoryStore) GetUsersInChannelDuring(startTime int64, endTime int64, channelId string) ([]*model.ChannelMemberHistoryResult, *model.AppError) {
|
||||
func (_m *ChannelMemberHistoryStore) GetUsersInChannelDuring(startTime int64, endTime int64, channelId string) ([]*model.ChannelMemberHistoryResult, error) {
|
||||
ret := _m.Called(startTime, endTime, channelId)
|
||||
|
||||
var r0 []*model.ChannelMemberHistoryResult
|
||||
@@ -27,12 +27,12 @@ func (_m *ChannelMemberHistoryStore) GetUsersInChannelDuring(startTime int64, en
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(int64, int64, string) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(int64, int64, string) error); ok {
|
||||
r1 = rf(startTime, endTime, channelId)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
r1 = ret.Get(1).(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,15 +40,15 @@ func (_m *ChannelMemberHistoryStore) GetUsersInChannelDuring(startTime int64, en
|
||||
}
|
||||
|
||||
// LogJoinEvent provides a mock function with given fields: userId, channelId, joinTime
|
||||
func (_m *ChannelMemberHistoryStore) LogJoinEvent(userId string, channelId string, joinTime int64) *model.AppError {
|
||||
func (_m *ChannelMemberHistoryStore) LogJoinEvent(userId string, channelId string, joinTime int64) error {
|
||||
ret := _m.Called(userId, channelId, joinTime)
|
||||
|
||||
var r0 *model.AppError
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64) *model.AppError); ok {
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64) error); ok {
|
||||
r0 = rf(userId, channelId, joinTime)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.AppError)
|
||||
r0 = ret.Get(0).(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,15 +56,15 @@ func (_m *ChannelMemberHistoryStore) LogJoinEvent(userId string, channelId strin
|
||||
}
|
||||
|
||||
// LogLeaveEvent provides a mock function with given fields: userId, channelId, leaveTime
|
||||
func (_m *ChannelMemberHistoryStore) LogLeaveEvent(userId string, channelId string, leaveTime int64) *model.AppError {
|
||||
func (_m *ChannelMemberHistoryStore) LogLeaveEvent(userId string, channelId string, leaveTime int64) error {
|
||||
ret := _m.Called(userId, channelId, leaveTime)
|
||||
|
||||
var r0 *model.AppError
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64) *model.AppError); ok {
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64) error); ok {
|
||||
r0 = rf(userId, channelId, leaveTime)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.AppError)
|
||||
r0 = ret.Get(0).(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func (_m *ChannelMemberHistoryStore) LogLeaveEvent(userId string, channelId stri
|
||||
}
|
||||
|
||||
// PermanentDeleteBatch provides a mock function with given fields: endTime, limit
|
||||
func (_m *ChannelMemberHistoryStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError) {
|
||||
func (_m *ChannelMemberHistoryStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, error) {
|
||||
ret := _m.Called(endTime, limit)
|
||||
|
||||
var r0 int64
|
||||
@@ -82,12 +82,12 @@ func (_m *ChannelMemberHistoryStore) PermanentDeleteBatch(endTime int64, limit i
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(int64, int64) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(int64, int64) error); ok {
|
||||
r1 = rf(endTime, limit)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
r1 = ret.Get(1).(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1841,7 +1841,7 @@ func (s *TimerLayerChannelStore) UserBelongsToChannels(userId string, channelIds
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelMemberHistoryStore) GetUsersInChannelDuring(startTime int64, endTime int64, channelId string) ([]*model.ChannelMemberHistoryResult, *model.AppError) {
|
||||
func (s *TimerLayerChannelMemberHistoryStore) GetUsersInChannelDuring(startTime int64, endTime int64, channelId string) ([]*model.ChannelMemberHistoryResult, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0, resultVar1 := s.ChannelMemberHistoryStore.GetUsersInChannelDuring(startTime, endTime, channelId)
|
||||
@@ -1857,7 +1857,7 @@ func (s *TimerLayerChannelMemberHistoryStore) GetUsersInChannelDuring(startTime
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelMemberHistoryStore) LogJoinEvent(userId string, channelId string, joinTime int64) *model.AppError {
|
||||
func (s *TimerLayerChannelMemberHistoryStore) LogJoinEvent(userId string, channelId string, joinTime int64) error {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0 := s.ChannelMemberHistoryStore.LogJoinEvent(userId, channelId, joinTime)
|
||||
@@ -1873,7 +1873,7 @@ func (s *TimerLayerChannelMemberHistoryStore) LogJoinEvent(userId string, channe
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelMemberHistoryStore) LogLeaveEvent(userId string, channelId string, leaveTime int64) *model.AppError {
|
||||
func (s *TimerLayerChannelMemberHistoryStore) LogLeaveEvent(userId string, channelId string, leaveTime int64) error {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0 := s.ChannelMemberHistoryStore.LogLeaveEvent(userId, channelId, leaveTime)
|
||||
@@ -1889,7 +1889,7 @@ func (s *TimerLayerChannelMemberHistoryStore) LogLeaveEvent(userId string, chann
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelMemberHistoryStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError) {
|
||||
func (s *TimerLayerChannelMemberHistoryStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0, resultVar1 := s.ChannelMemberHistoryStore.PermanentDeleteBatch(endTime, limit)
|
||||
|
||||
Reference in New Issue
Block a user