[MM-15296] Migrate "Preference.Save" to Sync by default (#10866)
* response format changes * Generated mocks Fixed all references of Preferences.Save * Remove old code from store.go (incorrect merge) * Review change - Add validations on count and error * Review change - return from root level * Review change - return 0 as nil value for int * fix initialisation of err in preference_store
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
c05cf5b033
Коммит
fb6c1debf0
@@ -1059,8 +1059,8 @@ func (a *App) AddDirectChannels(teamId string, user *model.User) *model.AppError
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.Preference().Save(&preferences); result.Err != nil {
|
||||
return model.NewAppError("AddDirectChannels", "api.user.add_direct_channels_and_forget.failed.error", map[string]interface{}{"UserId": user.Id, "TeamId": teamId, "Error": result.Err.Error()}, "", http.StatusInternalServerError)
|
||||
if _, err := a.Srv.Store.Preference().Save(&preferences); err != nil {
|
||||
return model.NewAppError("AddDirectChannels", "api.user.add_direct_channels_and_forget.failed.error", map[string]interface{}{"UserId": user.Id, "TeamId": teamId, "Error": err.Error()}, "", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -68,7 +68,7 @@ func (a *App) setCollapsePreference(args *model.CommandArgs, isCollapse bool) *m
|
||||
Value: strconv.FormatBool(isCollapse),
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.Preference().Save(&model.Preferences{pref}); result.Err != nil {
|
||||
if _, err := a.Srv.Store.Preference().Save(&model.Preferences{pref}); err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_expand_collapse.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
|
||||
@@ -115,12 +115,14 @@ func TestCheckPendingNotifications(t *testing.T) {
|
||||
channelMember.LastViewedAt = 9999999
|
||||
store.Must(th.App.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
|
||||
store.Must(th.App.Srv.Store.Preference().Save(&model.Preferences{{
|
||||
count, err := th.App.Srv.Store.Preference().Save(&model.Preferences{{
|
||||
UserId: th.BasicUser.Id,
|
||||
Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS,
|
||||
Name: model.PREFERENCE_NAME_EMAIL_INTERVAL,
|
||||
Value: "60",
|
||||
}}))
|
||||
}})
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, 1, count)
|
||||
|
||||
// test that notifications aren't sent before interval
|
||||
job.checkPendingNotifications(time.Unix(10001, 0), func(string, []*batchedNotification) {})
|
||||
@@ -256,12 +258,14 @@ func TestCheckPendingNotificationsCantParseInterval(t *testing.T) {
|
||||
store.Must(th.App.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
|
||||
// preference value is not an integer, so we'll fall back to the default 15min value
|
||||
store.Must(th.App.Srv.Store.Preference().Save(&model.Preferences{{
|
||||
count, err := th.App.Srv.Store.Preference().Save(&model.Preferences{{
|
||||
UserId: th.BasicUser.Id,
|
||||
Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS,
|
||||
Name: model.PREFERENCE_NAME_EMAIL_INTERVAL,
|
||||
Value: "notAnIntegerValue",
|
||||
}}))
|
||||
}})
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, 1, count)
|
||||
|
||||
job.pendingNotifications[th.BasicUser.Id] = []*batchedNotification{
|
||||
{
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
)
|
||||
|
||||
func TestReactionsOfPost(t *testing.T) {
|
||||
@@ -81,7 +80,10 @@ func TestExportUserChannels(t *testing.T) {
|
||||
}
|
||||
var preferences model.Preferences
|
||||
preferences = append(preferences, preference)
|
||||
store.Must(th.App.Srv.Store.Preference().Save(&preferences))
|
||||
count, err := th.App.Srv.Store.Preference().Save(&preferences)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, 1, count)
|
||||
|
||||
th.App.UpdateChannelMemberNotifyProps(notifyProps, channel.Id, user.Id)
|
||||
exportData, err := th.App.buildUserChannelMemberships(user.Id, team.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -636,8 +636,8 @@ func (a *App) ImportUser(data *UserImportData, dryRun bool) *model.AppError {
|
||||
}
|
||||
|
||||
if len(preferences) > 0 {
|
||||
if result := <-a.Srv.Store.Preference().Save(&preferences); result.Err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_user.save_preferences.error", nil, result.Err.Error(), http.StatusInternalServerError)
|
||||
if _, err := a.Srv.Store.Preference().Save(&preferences); err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_user.save_preferences.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -721,8 +721,8 @@ func (a *App) ImportUserTeams(user *model.User, data *[]UserTeamImportData) *mod
|
||||
}
|
||||
|
||||
if len(teamThemePreferences) > 0 {
|
||||
if result := <-a.Srv.Store.Preference().Save(&teamThemePreferences); result.Err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_user_teams.save_preferences.error", nil, result.Err.Error(), http.StatusInternalServerError)
|
||||
if _, err := a.Srv.Store.Preference().Save(&teamThemePreferences); err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_user_teams.save_preferences.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -818,8 +818,8 @@ func (a *App) ImportUserChannels(user *model.User, team *model.Team, teamMember
|
||||
}
|
||||
|
||||
if len(preferences) > 0 {
|
||||
if result := <-a.Srv.Store.Preference().Save(&preferences); result.Err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_user_channels.save_preferences.error", nil, result.Err.Error(), http.StatusInternalServerError)
|
||||
if _, err := a.Srv.Store.Preference().Save(&preferences); err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_user_channels.save_preferences.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1024,8 +1024,8 @@ func (a *App) ImportPost(data *PostImportData, dryRun bool) *model.AppError {
|
||||
}
|
||||
|
||||
if len(preferences) > 0 {
|
||||
if result := <-a.Srv.Store.Preference().Save(&preferences); result.Err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_post.save_preferences.error", nil, result.Err.Error(), http.StatusInternalServerError)
|
||||
if _, err := a.Srv.Store.Preference().Save(&preferences); err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_post.save_preferences.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1129,9 +1129,9 @@ func (a *App) ImportDirectChannel(data *DirectChannelImportData, dryRun bool) *m
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.Preference().Save(&preferences); result.Err != nil {
|
||||
result.Err.StatusCode = http.StatusBadRequest
|
||||
return result.Err
|
||||
if _, err := a.Srv.Store.Preference().Save(&preferences); err != nil {
|
||||
err.StatusCode = http.StatusBadRequest
|
||||
return err
|
||||
}
|
||||
|
||||
if data.Header != nil {
|
||||
@@ -1248,8 +1248,8 @@ func (a *App) ImportDirectPost(data *DirectPostImportData, dryRun bool) *model.A
|
||||
}
|
||||
|
||||
if len(preferences) > 0 {
|
||||
if result := <-a.Srv.Store.Preference().Save(&preferences); result.Err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_direct_post.save_preferences.error", nil, result.Err.Error(), http.StatusInternalServerError)
|
||||
if _, err := a.Srv.Store.Preference().Save(&preferences); err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_direct_post.save_preferences.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,8 +186,8 @@ func (a *App) AllowOAuthAppAccessToUser(userId string, authRequest *model.Author
|
||||
Value: authRequest.Scope,
|
||||
}
|
||||
|
||||
if result = <-a.Srv.Store.Preference().Save(&model.Preferences{authorizedApp}); result.Err != nil {
|
||||
mlog.Error(result.Err.Error())
|
||||
if _, err = a.Srv.Store.Preference().Save(&model.Preferences{authorizedApp}); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
return authRequest.RedirectUri + "?error=server_error&state=" + authRequest.State, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -48,9 +48,9 @@ func (a *App) UpdatePreferences(userId string, preferences model.Preferences) *m
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.Preference().Save(&preferences); result.Err != nil {
|
||||
result.Err.StatusCode = http.StatusBadRequest
|
||||
return result.Err
|
||||
if _, err := a.Srv.Store.Preference().Save(&preferences); err != nil {
|
||||
err.StatusCode = http.StatusBadRequest
|
||||
return err
|
||||
}
|
||||
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_PREFERENCES_CHANGED, "", "", userId, nil)
|
||||
|
||||
@@ -310,8 +310,8 @@ func (a *App) createUser(user *model.User) (*model.User, *model.AppError) {
|
||||
}
|
||||
|
||||
pref := model.Preference{UserId: ruser.Id, Category: model.PREFERENCE_CATEGORY_TUTORIAL_STEPS, Name: ruser.Id, Value: "0"}
|
||||
if presult := <-a.Srv.Store.Preference().Save(&model.Preferences{pref}); presult.Err != nil {
|
||||
mlog.Error(fmt.Sprintf("Encountered error saving tutorial preference, err=%v", presult.Err.Message))
|
||||
if _, err := a.Srv.Store.Preference().Save(&model.Preferences{pref}); err != nil {
|
||||
mlog.Error(fmt.Sprintf("Encountered error saving tutorial preference, err=%v", err.Message))
|
||||
}
|
||||
|
||||
ruser.Sanitize(map[string]bool{})
|
||||
|
||||
Ссылка в новой задаче
Block a user