* Starting migration

* Migration finished

* Fix i18n

* Fix some tests

* Fix typos

* Remove overwite of http status

* Add i18n string

* Fix i18n

* fix breakages

* fix tests

Co-authored-by: Rodrigo Villablanca <villa061004@gmail.com>
Этот коммит содержится в:
Agniva De Sarker
2020-07-28 10:27:24 +05:30
коммит произвёл GitHub
родитель 8f42177870
Коммит 83974d8a8d
19 изменённых файлов: 241 добавлений и 261 удалений

Просмотреть файл

@@ -95,13 +95,13 @@ func TestCheckPendingNotifications(t *testing.T) {
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember) _, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
require.Nil(t, err) require.Nil(t, err)
err = th.App.Srv().Store.Preference().Save(&model.Preferences{{ nErr := th.App.Srv().Store.Preference().Save(&model.Preferences{{
UserId: th.BasicUser.Id, UserId: th.BasicUser.Id,
Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS, Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS,
Name: model.PREFERENCE_NAME_EMAIL_INTERVAL, Name: model.PREFERENCE_NAME_EMAIL_INTERVAL,
Value: "60", Value: "60",
}}) }})
require.Nil(t, err) require.Nil(t, nErr)
// test that notifications aren't sent before interval // test that notifications aren't sent before interval
job.checkPendingNotifications(time.Unix(10001, 0), func(string, []*batchedNotification) {}) job.checkPendingNotifications(time.Unix(10001, 0), func(string, []*batchedNotification) {})
@@ -117,13 +117,13 @@ func TestCheckPendingNotifications(t *testing.T) {
require.Nil(t, err) require.Nil(t, err)
// We reset the interval to something shorter // We reset the interval to something shorter
err = th.App.Srv().Store.Preference().Save(&model.Preferences{{ nErr = th.App.Srv().Store.Preference().Save(&model.Preferences{{
UserId: th.BasicUser.Id, UserId: th.BasicUser.Id,
Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS, Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS,
Name: model.PREFERENCE_NAME_EMAIL_INTERVAL, Name: model.PREFERENCE_NAME_EMAIL_INTERVAL,
Value: "10", Value: "10",
}}) }})
require.Nil(t, err) require.Nil(t, nErr)
var wasCalled int32 var wasCalled int32
job.checkPendingNotifications(time.Unix(10050, 0), func(string, []*batchedNotification) { job.checkPendingNotifications(time.Unix(10050, 0), func(string, []*batchedNotification) {
@@ -253,13 +253,13 @@ func TestCheckPendingNotificationsCantParseInterval(t *testing.T) {
require.Nil(t, err) require.Nil(t, err)
// preference value is not an integer, so we'll fall back to the default 15min value // preference value is not an integer, so we'll fall back to the default 15min value
err = th.App.Srv().Store.Preference().Save(&model.Preferences{{ nErr := th.App.Srv().Store.Preference().Save(&model.Preferences{{
UserId: th.BasicUser.Id, UserId: th.BasicUser.Id,
Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS, Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS,
Name: model.PREFERENCE_NAME_EMAIL_INTERVAL, Name: model.PREFERENCE_NAME_EMAIL_INTERVAL,
Value: "notAnIntegerValue", Value: "notAnIntegerValue",
}}) }})
require.Nil(t, err) require.Nil(t, nErr)
job.pendingNotifications[th.BasicUser.Id] = []*batchedNotification{ job.pendingNotifications[th.BasicUser.Id] = []*batchedNotification{
{ {

Просмотреть файл

@@ -281,8 +281,8 @@ func (a *App) buildUserTeamAndChannelMemberships(userId string) (*[]UserTeamImpo
} }
// Get the user theme // Get the user theme
themePreference, err := a.Srv().Store.Preference().Get(member.UserId, model.PREFERENCE_CATEGORY_THEME, member.TeamId) themePreference, nErr := a.Srv().Store.Preference().Get(member.UserId, model.PREFERENCE_CATEGORY_THEME, member.TeamId)
if err == nil { if nErr == nil {
memberData.Theme = &themePreference.Value memberData.Theme = &themePreference.Value
} }

Просмотреть файл

@@ -1428,8 +1428,14 @@ func (a *App) importDirectChannel(data *DirectChannelImportData, dryRun bool) *m
} }
if err := a.Srv().Store.Preference().Save(&preferences); err != nil { if err := a.Srv().Store.Preference().Save(&preferences); err != nil {
err.StatusCode = http.StatusBadRequest var appErr *model.AppError
return err switch {
case errors.As(err, &appErr):
appErr.StatusCode = http.StatusBadRequest
return appErr
default:
return model.NewAppError("importDirectChannel", "app.preference.save.updating.app_error", nil, err.Error(), http.StatusBadRequest)
}
} }
if data.Header != nil { if data.Header != nil {

Просмотреть файл

@@ -215,8 +215,8 @@ func (a *App) AllowOAuthAppAccessToUser(userId string, authRequest *model.Author
Value: authRequest.Scope, Value: authRequest.Scope,
} }
if err = a.Srv().Store.Preference().Save(&model.Preferences{authorizedApp}); err != nil { if nErr := a.Srv().Store.Preference().Save(&model.Preferences{authorizedApp}); nErr != nil {
mlog.Error("error saving store prefrence", mlog.Err(err)) mlog.Error("error saving store preference", mlog.Err(nErr))
return authRequest.RedirectUri + "?error=server_error&state=" + authRequest.State, nil return authRequest.RedirectUri + "?error=server_error&state=" + authRequest.State, nil
} }
@@ -487,7 +487,7 @@ func (a *App) DeauthorizeOAuthAppForUser(userId, appId string) *model.AppError {
// Deauthorize the app // Deauthorize the app
if err := a.Srv().Store.Preference().Delete(userId, model.PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP, appId); err != nil { if err := a.Srv().Store.Preference().Delete(userId, model.PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP, appId); err != nil {
return err return model.NewAppError("DeauthorizeOAuthAppForUser", "app.preference.delete.app_error", nil, err.Error(), http.StatusInternalServerError)
} }
return nil return nil

Просмотреть файл

@@ -4,6 +4,7 @@
package app package app
import ( import (
"errors"
"net/http" "net/http"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
@@ -12,8 +13,7 @@ import (
func (a *App) GetPreferencesForUser(userId string) (model.Preferences, *model.AppError) { func (a *App) GetPreferencesForUser(userId string) (model.Preferences, *model.AppError) {
preferences, err := a.Srv().Store.Preference().GetAll(userId) preferences, err := a.Srv().Store.Preference().GetAll(userId)
if err != nil { if err != nil {
err.StatusCode = http.StatusBadRequest return nil, model.NewAppError("GetPreferencesForUser", "app.preference.get_all.app_error", nil, err.Error(), http.StatusBadRequest)
return nil, err
} }
return preferences, nil return preferences, nil
} }
@@ -21,11 +21,10 @@ func (a *App) GetPreferencesForUser(userId string) (model.Preferences, *model.Ap
func (a *App) GetPreferenceByCategoryForUser(userId string, category string) (model.Preferences, *model.AppError) { func (a *App) GetPreferenceByCategoryForUser(userId string, category string) (model.Preferences, *model.AppError) {
preferences, err := a.Srv().Store.Preference().GetCategory(userId, category) preferences, err := a.Srv().Store.Preference().GetCategory(userId, category)
if err != nil { if err != nil {
err.StatusCode = http.StatusBadRequest return nil, model.NewAppError("GetPreferenceByCategoryForUser", "app.preference.get_category.app_error", nil, err.Error(), http.StatusBadRequest)
return nil, err
} }
if len(preferences) == 0 { if len(preferences) == 0 {
err := model.NewAppError("getPreferenceCategory", "api.preference.preferences_category.get.app_error", nil, "", http.StatusNotFound) err := model.NewAppError("GetPreferenceByCategoryForUser", "api.preference.preferences_category.get.app_error", nil, "", http.StatusNotFound)
return nil, err return nil, err
} }
return preferences, nil return preferences, nil
@@ -34,8 +33,7 @@ func (a *App) GetPreferenceByCategoryForUser(userId string, category string) (mo
func (a *App) GetPreferenceByCategoryAndNameForUser(userId string, category string, preferenceName string) (*model.Preference, *model.AppError) { func (a *App) GetPreferenceByCategoryAndNameForUser(userId string, category string, preferenceName string) (*model.Preference, *model.AppError) {
res, err := a.Srv().Store.Preference().Get(userId, category, preferenceName) res, err := a.Srv().Store.Preference().Get(userId, category, preferenceName)
if err != nil { if err != nil {
err.StatusCode = http.StatusBadRequest return nil, model.NewAppError("GetPreferenceByCategoryAndNameForUser", "app.preference.get.app_error", nil, err.Error(), http.StatusBadRequest)
return nil, err
} }
return res, nil return res, nil
} }
@@ -49,8 +47,13 @@ func (a *App) UpdatePreferences(userId string, preferences model.Preferences) *m
} }
if err := a.Srv().Store.Preference().Save(&preferences); err != nil { if err := a.Srv().Store.Preference().Save(&preferences); err != nil {
err.StatusCode = http.StatusBadRequest var appErr *model.AppError
return err switch {
case errors.As(err, &appErr):
return appErr
default:
return model.NewAppError("UpdatePreferences", "app.preference.save.updating.app_error", nil, err.Error(), http.StatusBadRequest)
}
} }
if err := a.Srv().Store.Channel().UpdateSidebarChannelsByPreferences(&preferences); err != nil { if err := a.Srv().Store.Channel().UpdateSidebarChannelsByPreferences(&preferences); err != nil {
@@ -79,8 +82,7 @@ func (a *App) DeletePreferences(userId string, preferences model.Preferences) *m
for _, preference := range preferences { for _, preference := range preferences {
if err := a.Srv().Store.Preference().Delete(userId, preference.Category, preference.Name); err != nil { if err := a.Srv().Store.Preference().Delete(userId, preference.Category, preference.Name); err != nil {
err.StatusCode = http.StatusBadRequest return model.NewAppError("DeletePreferences", "app.preference.delete.app_error", nil, err.Error(), http.StatusBadRequest)
return err
} }
} }

Просмотреть файл

@@ -984,7 +984,7 @@ func (a *App) RemoveTeamMemberFromTeam(teamMember *model.TeamMember, requestorId
// delete the preferences that set the last channel used in the team and other team specific preferences // delete the preferences that set the last channel used in the team and other team specific preferences
if err := a.Srv().Store.Preference().DeleteCategory(user.Id, teamMember.TeamId); err != nil { if err := a.Srv().Store.Preference().DeleteCategory(user.Id, teamMember.TeamId); err != nil {
return err return model.NewAppError("RemoveTeamMemberFromTeam", "app.preference.delete.app_error", nil, err.Error(), http.StatusInternalServerError)
} }
a.ClearSessionCacheForUser(user.Id) a.ClearSessionCacheForUser(user.Id)

Просмотреть файл

@@ -1477,7 +1477,7 @@ func (a *App) PermanentDeleteUser(user *model.User) *model.AppError {
} }
if err := a.Srv().Store.Preference().PermanentDeleteByUser(user.Id); err != nil { if err := a.Srv().Store.Preference().PermanentDeleteByUser(user.Id); err != nil {
return err return model.NewAppError("PermanentDeleteUser", "app.preference.permanent_delete_by_user.app_error", nil, err.Error(), http.StatusInternalServerError)
} }
if err := a.Srv().Store.Channel().PermanentDeleteMembersByUser(user.Id); err != nil { if err := a.Srv().Store.Channel().PermanentDeleteMembersByUser(user.Id); err != nil {

Просмотреть файл

@@ -4246,6 +4246,30 @@
"id": "app.plugin.write_file.saving.app_error", "id": "app.plugin.write_file.saving.app_error",
"translation": "An error occurred while saving the file." "translation": "An error occurred while saving the file."
}, },
{
"id": "app.preference.delete.app_error",
"translation": "We encountered an error while deleting preferences."
},
{
"id": "app.preference.get.app_error",
"translation": "We encountered an error while finding preferences."
},
{
"id": "app.preference.get_all.app_error",
"translation": "We encountered an error while finding preferences."
},
{
"id": "app.preference.get_category.app_error",
"translation": "We encountered an error while finding preferences."
},
{
"id": "app.preference.permanent_delete_by_user.app_error",
"translation": "We encountered an error while deleteing preferences."
},
{
"id": "app.preference.save.updating.app_error",
"translation": "We encountered an error while updating preferences."
},
{ {
"id": "app.reaction.bulk_get_for_post_ids.app_error", "id": "app.reaction.bulk_get_for_post_ids.app_error",
"translation": "Unable to get reactions for post." "translation": "Unable to get reactions for post."
@@ -4738,6 +4762,10 @@
"id": "ent.data_retention.channel_member_history_batch.internal_error", "id": "ent.data_retention.channel_member_history_batch.internal_error",
"translation": "Failed to purge records." "translation": "Failed to purge records."
}, },
{
"id": "ent.data_retention.flags_batch.internal_error",
"translation": "We encountered an error cleaning up the batch of flags."
},
{ {
"id": "ent.data_retention.generic.license.error", "id": "ent.data_retention.generic.license.error",
"translation": "Your license does not support Data Retention." "translation": "Your license does not support Data Retention."
@@ -7138,58 +7166,6 @@
"id": "store.sql_post.update.app_error", "id": "store.sql_post.update.app_error",
"translation": "Unable to update the Post." "translation": "Unable to update the Post."
}, },
{
"id": "store.sql_preference.cleanup_flags_batch.app_error",
"translation": "We encountered an error cleaning up the batch of flags."
},
{
"id": "store.sql_preference.delete.app_error",
"translation": "We encountered an error while deleting preferences."
},
{
"id": "store.sql_preference.get.app_error",
"translation": "We encountered an error while finding preferences."
},
{
"id": "store.sql_preference.get_all.app_error",
"translation": "We encountered an error while finding preferences."
},
{
"id": "store.sql_preference.get_category.app_error",
"translation": "We encountered an error while finding preferences."
},
{
"id": "store.sql_preference.insert.exists.app_error",
"translation": "A preference with that user id, category, and name already exists."
},
{
"id": "store.sql_preference.insert.save.app_error",
"translation": "Unable to save the preference."
},
{
"id": "store.sql_preference.permanent_delete_by_user.app_error",
"translation": "We encountered an error while deleteing preferences."
},
{
"id": "store.sql_preference.save.commit_transaction.app_error",
"translation": "Unable to commit transaction to save preferences."
},
{
"id": "store.sql_preference.save.missing_driver.app_error",
"translation": "We encountered an error while updating preferences."
},
{
"id": "store.sql_preference.save.open_transaction.app_error",
"translation": "Unable to open transaction to save preferences."
},
{
"id": "store.sql_preference.save.updating.app_error",
"translation": "We encountered an error while updating preferences."
},
{
"id": "store.sql_preference.update.app_error",
"translation": "Unable to update the preference."
},
{ {
"id": "store.sql_role.delete.update.app_error", "id": "store.sql_role.delete.update.app_error",
"translation": "Unable to delete the role." "translation": "Unable to delete the role."

Просмотреть файл

@@ -102,3 +102,16 @@ func (e *ErrOutOfBounds) Error() string {
func NewErrOutOfBounds(value int) *ErrOutOfBounds { func NewErrOutOfBounds(value int) *ErrOutOfBounds {
return &ErrOutOfBounds{value: value} return &ErrOutOfBounds{value: value}
} }
// ErrNotImplemented indicates that some feature or requirement is not implemented yet.
type ErrNotImplemented struct {
detail string
}
func (e *ErrNotImplemented) Error() string {
return e.detail
}
func NewErrNotImplemented(detail string) *ErrNotImplemented {
return &ErrNotImplemented{detail: detail}
}

Просмотреть файл

@@ -5347,7 +5347,7 @@ func (s *OpenTracingLayerPostStore) Update(newPost *model.Post, oldPost *model.P
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *OpenTracingLayerPreferenceStore) CleanupFlagsBatch(limit int64) (int64, *model.AppError) { func (s *OpenTracingLayerPreferenceStore) CleanupFlagsBatch(limit int64) (int64, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.CleanupFlagsBatch") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.CleanupFlagsBatch")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -5365,7 +5365,7 @@ func (s *OpenTracingLayerPreferenceStore) CleanupFlagsBatch(limit int64) (int64,
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *OpenTracingLayerPreferenceStore) Delete(userId string, category string, name string) *model.AppError { func (s *OpenTracingLayerPreferenceStore) Delete(userId string, category string, name string) error {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.Delete") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.Delete")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -5383,7 +5383,7 @@ func (s *OpenTracingLayerPreferenceStore) Delete(userId string, category string,
return resultVar0 return resultVar0
} }
func (s *OpenTracingLayerPreferenceStore) DeleteCategory(userId string, category string) *model.AppError { func (s *OpenTracingLayerPreferenceStore) DeleteCategory(userId string, category string) error {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.DeleteCategory") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.DeleteCategory")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -5401,7 +5401,7 @@ func (s *OpenTracingLayerPreferenceStore) DeleteCategory(userId string, category
return resultVar0 return resultVar0
} }
func (s *OpenTracingLayerPreferenceStore) DeleteCategoryAndName(category string, name string) *model.AppError { func (s *OpenTracingLayerPreferenceStore) DeleteCategoryAndName(category string, name string) error {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.DeleteCategoryAndName") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.DeleteCategoryAndName")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -5419,7 +5419,7 @@ func (s *OpenTracingLayerPreferenceStore) DeleteCategoryAndName(category string,
return resultVar0 return resultVar0
} }
func (s *OpenTracingLayerPreferenceStore) Get(userId string, category string, name string) (*model.Preference, *model.AppError) { func (s *OpenTracingLayerPreferenceStore) Get(userId string, category string, name string) (*model.Preference, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.Get") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.Get")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -5437,7 +5437,7 @@ func (s *OpenTracingLayerPreferenceStore) Get(userId string, category string, na
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *OpenTracingLayerPreferenceStore) GetAll(userId string) (model.Preferences, *model.AppError) { func (s *OpenTracingLayerPreferenceStore) GetAll(userId string) (model.Preferences, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.GetAll") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.GetAll")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -5455,7 +5455,7 @@ func (s *OpenTracingLayerPreferenceStore) GetAll(userId string) (model.Preferenc
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *OpenTracingLayerPreferenceStore) GetCategory(userId string, category string) (model.Preferences, *model.AppError) { func (s *OpenTracingLayerPreferenceStore) GetCategory(userId string, category string) (model.Preferences, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.GetCategory") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.GetCategory")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -5473,7 +5473,7 @@ func (s *OpenTracingLayerPreferenceStore) GetCategory(userId string, category st
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *OpenTracingLayerPreferenceStore) PermanentDeleteByUser(userId string) *model.AppError { func (s *OpenTracingLayerPreferenceStore) PermanentDeleteByUser(userId string) error {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.PermanentDeleteByUser") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.PermanentDeleteByUser")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -5491,7 +5491,7 @@ func (s *OpenTracingLayerPreferenceStore) PermanentDeleteByUser(userId string) *
return resultVar0 return resultVar0
} }
func (s *OpenTracingLayerPreferenceStore) Save(preferences *model.Preferences) *model.AppError { func (s *OpenTracingLayerPreferenceStore) Save(preferences *model.Preferences) error {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.Save") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.Save")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)

Просмотреть файл

@@ -3958,7 +3958,7 @@ func (s SqlChannelStore) UpdateSidebarCategories(userId, teamId string, categori
for _, channelID := range category.Channels { for _, channelID := range category.Channels {
// This breaks the PreferenceStore abstraction, but it should be safe to assume that everything is a SQL // This breaks the PreferenceStore abstraction, but it should be safe to assume that everything is a SQL
// store in this package. // store in this package.
if err := s.Preference().(*SqlPreferenceStore).save(transaction, &model.Preference{ if err = s.Preference().(*SqlPreferenceStore).save(transaction, &model.Preference{
Name: channelID, Name: channelID,
UserId: userId, UserId: userId,
Category: model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, Category: model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL,

Просмотреть файл

@@ -4,10 +4,11 @@
package sqlstore package sqlstore
import ( import (
"net/http" "fmt"
"github.com/pkg/errors"
"github.com/mattermost/gorp" "github.com/mattermost/gorp"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store" "github.com/mattermost/mattermost-server/v5/store"
@@ -51,14 +52,17 @@ func (s SqlPreferenceStore) deleteUnusedFeatures() {
"Category": model.PREFERENCE_CATEGORY_ADVANCED_SETTINGS, "Category": model.PREFERENCE_CATEGORY_ADVANCED_SETTINGS,
"Value": "false", "Value": "false",
} }
s.GetMaster().Exec(sql, queryParams) _, err := s.GetMaster().Exec(sql, queryParams)
if err != nil {
mlog.Warn("Failed to delete unused features", mlog.Err(err))
}
} }
func (s SqlPreferenceStore) Save(preferences *model.Preferences) *model.AppError { func (s SqlPreferenceStore) Save(preferences *model.Preferences) error {
// wrap in a transaction so that if one fails, everything fails // wrap in a transaction so that if one fails, everything fails
transaction, err := s.GetMaster().Begin() transaction, err := s.GetMaster().Begin()
if err != nil { if err != nil {
return model.NewAppError("SqlPreferenceStore.Save", "store.sql_preference.save.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) return errors.Wrap(err, "begin_transaction")
} }
defer finalizeTransaction(transaction) defer finalizeTransaction(transaction)
@@ -71,12 +75,12 @@ func (s SqlPreferenceStore) Save(preferences *model.Preferences) *model.AppError
if err := transaction.Commit(); err != nil { if err := transaction.Commit(); err != nil {
// don't need to rollback here since the transaction is already closed // don't need to rollback here since the transaction is already closed
return model.NewAppError("SqlPreferenceStore.Save", "store.sql_preference.save.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) return errors.Wrap(err, "commit_transaction")
} }
return nil return nil
} }
func (s SqlPreferenceStore) save(transaction *gorp.Transaction, preference *model.Preference) *model.AppError { func (s SqlPreferenceStore) save(transaction *gorp.Transaction, preference *model.Preference) error {
preference.PreUpdate() preference.PreUpdate()
if err := preference.IsValid(); err != nil { if err := preference.IsValid(); err != nil {
@@ -99,7 +103,7 @@ func (s SqlPreferenceStore) save(transaction *gorp.Transaction, preference *mode
(:UserId, :Category, :Name, :Value) (:UserId, :Category, :Name, :Value)
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
Value = :Value`, params); err != nil { Value = :Value`, params); err != nil {
return model.NewAppError("SqlPreferenceStore.save", "store.sql_preference.save.updating.app_error", nil, err.Error(), http.StatusInternalServerError) return errors.Wrap(err, "failed to save Preference")
} }
return nil return nil
} else if s.DriverName() == model.DATABASE_DRIVER_POSTGRES { } else if s.DriverName() == model.DATABASE_DRIVER_POSTGRES {
@@ -114,7 +118,7 @@ func (s SqlPreferenceStore) save(transaction *gorp.Transaction, preference *mode
AND Category = :Category AND Category = :Category
AND Name = :Name`, params) AND Name = :Name`, params)
if err != nil { if err != nil {
return model.NewAppError("SqlPreferenceStore.save", "store.sql_preference.save.updating.app_error", nil, err.Error(), http.StatusInternalServerError) return errors.Wrap(err, "failed to count Preferences")
} }
if count == 1 { if count == 1 {
@@ -122,32 +126,29 @@ func (s SqlPreferenceStore) save(transaction *gorp.Transaction, preference *mode
} }
return s.insert(transaction, preference) return s.insert(transaction, preference)
} }
return model.NewAppError("SqlPreferenceStore.save", "store.sql_preference.save.missing_driver.app_error", nil, "Failed to update preference because of missing driver", http.StatusNotImplemented) return store.NewErrNotImplemented("failed to update preference because of missing driver")
} }
func (s SqlPreferenceStore) insert(transaction *gorp.Transaction, preference *model.Preference) *model.AppError { func (s SqlPreferenceStore) insert(transaction *gorp.Transaction, preference *model.Preference) error {
if err := transaction.Insert(preference); err != nil { if err := transaction.Insert(preference); err != nil {
if IsUniqueConstraintError(err, []string{"UserId", "preferences_pkey"}) { if IsUniqueConstraintError(err, []string{"UserId", "preferences_pkey"}) {
return model.NewAppError("SqlPreferenceStore.insert", "store.sql_preference.insert.exists.app_error", nil, return store.NewErrInvalidInput("Preference", "<userId, category, name>", fmt.Sprintf("<%s, %s, %s>", preference.UserId, preference.Category, preference.Name))
"user_id="+preference.UserId+", category="+preference.Category+", name="+preference.Name+", "+err.Error(), http.StatusBadRequest)
} }
return model.NewAppError("SqlPreferenceStore.insert", "store.sql_preference.insert.save.app_error", nil, return errors.Wrapf(err, "failed to save Preference with userId=%s, category=%s, name=%s", preference.UserId, preference.Category, preference.Name)
"user_id="+preference.UserId+", category="+preference.Category+", name="+preference.Name+", "+err.Error(), http.StatusInternalServerError)
} }
return nil return nil
} }
func (s SqlPreferenceStore) update(transaction *gorp.Transaction, preference *model.Preference) *model.AppError { func (s SqlPreferenceStore) update(transaction *gorp.Transaction, preference *model.Preference) error {
if _, err := transaction.Update(preference); err != nil { if _, err := transaction.Update(preference); err != nil {
return model.NewAppError("SqlPreferenceStore.update", "store.sql_preference.update.app_error", nil, return errors.Wrapf(err, "failed to update Preference with userId=%s, category=%s, name=%s", preference.UserId, preference.Category, preference.Name)
"user_id="+preference.UserId+", category="+preference.Category+", name="+preference.Name+", "+err.Error(), http.StatusInternalServerError)
} }
return nil return nil
} }
func (s SqlPreferenceStore) Get(userId string, category string, name string) (*model.Preference, *model.AppError) { func (s SqlPreferenceStore) Get(userId string, category string, name string) (*model.Preference, error) {
var preference *model.Preference var preference *model.Preference
if err := s.GetReplica().SelectOne(&preference, if err := s.GetReplica().SelectOne(&preference,
@@ -159,12 +160,12 @@ func (s SqlPreferenceStore) Get(userId string, category string, name string) (*m
UserId = :UserId UserId = :UserId
AND Category = :Category AND Category = :Category
AND Name = :Name`, map[string]interface{}{"UserId": userId, "Category": category, "Name": name}); err != nil { AND Name = :Name`, map[string]interface{}{"UserId": userId, "Category": category, "Name": name}); err != nil {
return nil, model.NewAppError("SqlPreferenceStore.Get", "store.sql_preference.get.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "failed to find Preference with userId=%s, category=%s, name=%s", userId, category, name)
} }
return preference, nil return preference, nil
} }
func (s SqlPreferenceStore) GetCategory(userId string, category string) (model.Preferences, *model.AppError) { func (s SqlPreferenceStore) GetCategory(userId string, category string) (model.Preferences, error) {
var preferences model.Preferences var preferences model.Preferences
if _, err := s.GetReplica().Select(&preferences, if _, err := s.GetReplica().Select(&preferences,
@@ -175,14 +176,14 @@ func (s SqlPreferenceStore) GetCategory(userId string, category string) (model.P
WHERE WHERE
UserId = :UserId UserId = :UserId
AND Category = :Category`, map[string]interface{}{"UserId": userId, "Category": category}); err != nil { AND Category = :Category`, map[string]interface{}{"UserId": userId, "Category": category}); err != nil {
return nil, model.NewAppError("SqlPreferenceStore.GetCategory", "store.sql_preference.get_category.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "failed to find Preferences with userId=%s and category=%s", userId, category)
} }
return preferences, nil return preferences, nil
} }
func (s SqlPreferenceStore) GetAll(userId string) (model.Preferences, *model.AppError) { func (s SqlPreferenceStore) GetAll(userId string) (model.Preferences, error) {
var preferences model.Preferences var preferences model.Preferences
if _, err := s.GetReplica().Select(&preferences, if _, err := s.GetReplica().Select(&preferences,
@@ -192,12 +193,12 @@ func (s SqlPreferenceStore) GetAll(userId string) (model.Preferences, *model.App
Preferences Preferences
WHERE WHERE
UserId = :UserId`, map[string]interface{}{"UserId": userId}); err != nil { UserId = :UserId`, map[string]interface{}{"UserId": userId}); err != nil {
return nil, model.NewAppError("SqlPreferenceStore.GetAll", "store.sql_preference.get_all.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "failed to find Preferences with userId=%s", userId)
} }
return preferences, nil return preferences, nil
} }
func (s SqlPreferenceStore) PermanentDeleteByUser(userId string) *model.AppError { func (s SqlPreferenceStore) PermanentDeleteByUser(userId string) error {
query := query :=
`DELETE FROM `DELETE FROM
Preferences Preferences
@@ -205,13 +206,13 @@ func (s SqlPreferenceStore) PermanentDeleteByUser(userId string) *model.AppError
UserId = :UserId` UserId = :UserId`
if _, err := s.GetMaster().Exec(query, map[string]interface{}{"UserId": userId}); err != nil { if _, err := s.GetMaster().Exec(query, map[string]interface{}{"UserId": userId}); err != nil {
return model.NewAppError("SqlPreferenceStore.Delete", "store.sql_preference.permanent_delete_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) return errors.Wrapf(err, "failed to delete Preference with userId=%s", userId)
} }
return nil return nil
} }
func (s SqlPreferenceStore) Delete(userId, category, name string) *model.AppError { func (s SqlPreferenceStore) Delete(userId, category, name string) error {
query := query :=
`DELETE FROM Preferences `DELETE FROM Preferences
WHERE WHERE
@@ -222,13 +223,13 @@ func (s SqlPreferenceStore) Delete(userId, category, name string) *model.AppErro
_, err := s.GetMaster().Exec(query, map[string]interface{}{"UserId": userId, "Category": category, "Name": name}) _, err := s.GetMaster().Exec(query, map[string]interface{}{"UserId": userId, "Category": category, "Name": name})
if err != nil { if err != nil {
return model.NewAppError("SqlPreferenceStore.Delete", "store.sql_preference.delete.app_error", nil, err.Error(), http.StatusInternalServerError) return errors.Wrapf(err, "failed to delete Preference with userId=%s, category=%s and name=%s", userId, category, name)
} }
return nil return nil
} }
func (s SqlPreferenceStore) DeleteCategory(userId string, category string) *model.AppError { func (s SqlPreferenceStore) DeleteCategory(userId string, category string) error {
_, err := s.GetMaster().Exec( _, err := s.GetMaster().Exec(
`DELETE FROM `DELETE FROM
Preferences Preferences
@@ -237,13 +238,13 @@ func (s SqlPreferenceStore) DeleteCategory(userId string, category string) *mode
AND Category = :Category`, map[string]interface{}{"UserId": userId, "Category": category}) AND Category = :Category`, map[string]interface{}{"UserId": userId, "Category": category})
if err != nil { if err != nil {
return model.NewAppError("SqlPreferenceStore.DeleteCategory", "store.sql_preference.delete.app_error", nil, err.Error(), http.StatusInternalServerError) return errors.Wrapf(err, "failed to delete Preference with userId=%s and category=%s", userId, category)
} }
return nil return nil
} }
func (s SqlPreferenceStore) DeleteCategoryAndName(category string, name string) *model.AppError { func (s SqlPreferenceStore) DeleteCategoryAndName(category string, name string) error {
_, err := s.GetMaster().Exec( _, err := s.GetMaster().Exec(
`DELETE FROM `DELETE FROM
Preferences Preferences
@@ -252,13 +253,13 @@ func (s SqlPreferenceStore) DeleteCategoryAndName(category string, name string)
AND Category = :Category`, map[string]interface{}{"Name": name, "Category": category}) AND Category = :Category`, map[string]interface{}{"Name": name, "Category": category})
if err != nil { if err != nil {
return model.NewAppError("SqlPreferenceStore.DeleteCategoryAndName", "store.sql_preference.delete.app_error", nil, err.Error(), http.StatusInternalServerError) return errors.Wrapf(err, "failed to delete Preference with category=%s and name=%s", category, name)
} }
return nil return nil
} }
func (s SqlPreferenceStore) CleanupFlagsBatch(limit int64) (int64, *model.AppError) { func (s SqlPreferenceStore) CleanupFlagsBatch(limit int64) (int64, error) {
query := query :=
`DELETE FROM `DELETE FROM
Preferences Preferences
@@ -287,12 +288,12 @@ func (s SqlPreferenceStore) CleanupFlagsBatch(limit int64) (int64, *model.AppErr
sqlResult, err := s.GetMaster().Exec(query, map[string]interface{}{"Category": model.PREFERENCE_CATEGORY_FLAGGED_POST, "Limit": limit}) sqlResult, err := s.GetMaster().Exec(query, map[string]interface{}{"Category": model.PREFERENCE_CATEGORY_FLAGGED_POST, "Limit": limit})
if err != nil { if err != nil {
return int64(0), model.NewAppError("SqlPostStore.CleanupFlagsBatch", "store.sql_preference.cleanup_flags_batch.app_error", nil, ""+err.Error(), http.StatusInternalServerError) return int64(0), errors.Wrap(err, "failed to delete Preference")
} }
rowsAffected, err := sqlResult.RowsAffected() rowsAffected, err := sqlResult.RowsAffected()
if err != nil { if err != nil {
return int64(0), model.NewAppError("SqlPostStore.CleanupFlagsBatch", "store.sql_preference.cleanup_flags_batch.app_error", nil, ""+err.Error(), http.StatusInternalServerError) return int64(0), errors.Wrap(err, "unable to get rows affected")
} }
return rowsAffected, nil return rowsAffected, nil

Просмотреть файл

@@ -494,15 +494,15 @@ type CommandWebhookStore interface {
} }
type PreferenceStore interface { type PreferenceStore interface {
Save(preferences *model.Preferences) *model.AppError Save(preferences *model.Preferences) error
GetCategory(userId string, category string) (model.Preferences, *model.AppError) GetCategory(userId string, category string) (model.Preferences, error)
Get(userId string, category string, name string) (*model.Preference, *model.AppError) Get(userId string, category string, name string) (*model.Preference, error)
GetAll(userId string) (model.Preferences, *model.AppError) GetAll(userId string) (model.Preferences, error)
Delete(userId, category, name string) *model.AppError Delete(userId, category, name string) error
DeleteCategory(userId string, category string) *model.AppError DeleteCategory(userId string, category string) error
DeleteCategoryAndName(category string, name string) *model.AppError DeleteCategoryAndName(category string, name string) error
PermanentDeleteByUser(userId string) *model.AppError PermanentDeleteByUser(userId string) error
CleanupFlagsBatch(limit int64) (int64, *model.AppError) CleanupFlagsBatch(limit int64) (int64, error)
} }
type LicenseStore interface { type LicenseStore interface {

Просмотреть файл

@@ -7286,8 +7286,8 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store, s SqlSupplier) {
}) })
assert.Nil(t, err) assert.Nil(t, err)
res, err := ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id) res, nErr := ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id)
assert.Nil(t, err) assert.Nil(t, nErr)
assert.NotNil(t, res) assert.NotNil(t, res)
assert.Equal(t, "true", res.Value) assert.Equal(t, "true", res.Value)
@@ -7303,9 +7303,9 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store, s SqlSupplier) {
}) })
assert.Nil(t, err) assert.Nil(t, err)
res, err = ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id) res, nErr = ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id)
assert.NotNil(t, err) assert.NotNil(t, nErr)
assert.Equal(t, sql.ErrNoRows.Error(), err.DetailedError) assert.True(t, errors.Is(nErr, sql.ErrNoRows))
assert.Nil(t, res) assert.Nil(t, res)
}) })
@@ -7351,8 +7351,8 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store, s SqlSupplier) {
}) })
assert.Nil(t, err) assert.Nil(t, err)
res, err := ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, dmChannel.Id) res, nErr := ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, dmChannel.Id)
assert.Nil(t, err) assert.Nil(t, nErr)
assert.NotNil(t, res) assert.NotNil(t, res)
assert.Equal(t, "true", res.Value) assert.Equal(t, "true", res.Value)
@@ -7368,9 +7368,9 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store, s SqlSupplier) {
}) })
assert.Nil(t, err) assert.Nil(t, err)
res, err = ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, dmChannel.Id) res, nErr = ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, dmChannel.Id)
assert.NotNil(t, err) assert.NotNil(t, nErr)
assert.Equal(t, sql.ErrNoRows.Error(), err.DetailedError) assert.True(t, errors.Is(nErr, sql.ErrNoRows))
assert.Nil(t, res) assert.Nil(t, res)
}) })
@@ -7426,8 +7426,8 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store, s SqlSupplier) {
}) })
assert.Nil(t, err) assert.Nil(t, err)
res, err := ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, dmChannel.Id) res, nErr := ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, dmChannel.Id)
assert.Nil(t, err) assert.Nil(t, nErr)
assert.NotNil(t, res) assert.NotNil(t, res)
assert.Equal(t, "true", res.Value) assert.Equal(t, "true", res.Value)
@@ -7441,8 +7441,8 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store, s SqlSupplier) {
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, []string{dmChannel.Id}, updated[0].Channels) assert.Equal(t, []string{dmChannel.Id}, updated[0].Channels)
res, err = ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, dmChannel.Id) res, nErr = ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, dmChannel.Id)
assert.Nil(t, err) assert.NoError(t, nErr)
assert.NotNil(t, res) assert.NotNil(t, res)
assert.Equal(t, "true", res.Value) assert.Equal(t, "true", res.Value)
@@ -7455,8 +7455,8 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store, s SqlSupplier) {
}) })
assert.Nil(t, err) assert.Nil(t, err)
res, err = ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, dmChannel.Id) res, nErr = ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, dmChannel.Id)
assert.Equal(t, sql.ErrNoRows.Error(), err.DetailedError) require.Error(t, nErr)
assert.Nil(t, res) assert.Nil(t, res)
// Remove it from favorites on the second team. The favorites preference was already deleted. // Remove it from favorites on the second team. The favorites preference was already deleted.
@@ -7468,8 +7468,8 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store, s SqlSupplier) {
}) })
assert.Nil(t, err) assert.Nil(t, err)
res, err = ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, dmChannel.Id) res, nErr = ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, dmChannel.Id)
assert.Equal(t, sql.ErrNoRows.Error(), err.DetailedError) require.Error(t, nErr)
assert.Nil(t, res) assert.Nil(t, res)
}) })
@@ -7536,13 +7536,13 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store, s SqlSupplier) {
}) })
assert.Nil(t, err) assert.Nil(t, err)
res, err := ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id) res, nErr := ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id)
assert.Nil(t, err) assert.Nil(t, nErr)
assert.NotNil(t, res) assert.NotNil(t, res)
assert.Equal(t, "true", res.Value) assert.Equal(t, "true", res.Value)
res, err = ss.Preference().Get(userId2, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id) res, nErr = ss.Preference().Get(userId2, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id)
assert.Equal(t, sql.ErrNoRows.Error(), err.DetailedError) assert.True(t, errors.Is(nErr, sql.ErrNoRows))
assert.Nil(t, res) assert.Nil(t, res)
// And user2 favorite it // And user2 favorite it
@@ -7558,13 +7558,13 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store, s SqlSupplier) {
}) })
assert.Nil(t, err) assert.Nil(t, err)
res, err = ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id) res, nErr = ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id)
assert.Nil(t, err) assert.Nil(t, nErr)
assert.NotNil(t, res) assert.NotNil(t, res)
assert.Equal(t, "true", res.Value) assert.Equal(t, "true", res.Value)
res, err = ss.Preference().Get(userId2, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id) res, nErr = ss.Preference().Get(userId2, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id)
assert.Nil(t, err) assert.Nil(t, nErr)
assert.NotNil(t, res) assert.NotNil(t, res)
assert.Equal(t, "true", res.Value) assert.Equal(t, "true", res.Value)
@@ -7581,12 +7581,12 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store, s SqlSupplier) {
}) })
assert.Nil(t, err) assert.Nil(t, err)
res, err = ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id) res, nErr = ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id)
assert.Equal(t, sql.ErrNoRows.Error(), err.DetailedError) assert.True(t, errors.Is(nErr, sql.ErrNoRows))
assert.Nil(t, res) assert.Nil(t, res)
res, err = ss.Preference().Get(userId2, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id) res, nErr = ss.Preference().Get(userId2, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id)
assert.Nil(t, err) assert.Nil(t, nErr)
assert.NotNil(t, res) assert.NotNil(t, res)
assert.Equal(t, "true", res.Value) assert.Equal(t, "true", res.Value)
@@ -7603,12 +7603,12 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store, s SqlSupplier) {
}) })
assert.Nil(t, err) assert.Nil(t, err)
res, err = ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id) res, nErr = ss.Preference().Get(userId, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id)
assert.Equal(t, sql.ErrNoRows.Error(), err.DetailedError) assert.True(t, errors.Is(nErr, sql.ErrNoRows))
assert.Nil(t, res) assert.Nil(t, res)
res, err = ss.Preference().Get(userId2, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id) res, nErr = ss.Preference().Get(userId2, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id)
assert.Equal(t, sql.ErrNoRows.Error(), err.DetailedError) assert.True(t, errors.Is(nErr, sql.ErrNoRows))
assert.Nil(t, res) assert.Nil(t, res)
}) })
@@ -7939,7 +7939,7 @@ func testCreateInitialSidebarCategories(t *testing.T, ss store.Store) {
}) })
require.Nil(t, err) require.Nil(t, err)
err = ss.Preference().Save(&model.Preferences{ nErr = ss.Preference().Save(&model.Preferences{
{ {
UserId: userId, UserId: userId,
Category: model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, Category: model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL,
@@ -7947,7 +7947,7 @@ func testCreateInitialSidebarCategories(t *testing.T, ss store.Store) {
Value: "true", Value: "true",
}, },
}) })
require.Nil(t, err) require.Nil(t, nErr)
// Create the categories // Create the categories
nErr = ss.Channel().CreateInitialSidebarCategories(userId, teamId) nErr = ss.Channel().CreateInitialSidebarCategories(userId, teamId)
@@ -7996,7 +7996,7 @@ func testCreateInitialSidebarCategories(t *testing.T, ss store.Store) {
}) })
require.Nil(t, err) require.Nil(t, err)
err = ss.Preference().Save(&model.Preferences{ nErr = ss.Preference().Save(&model.Preferences{
{ {
UserId: userId, UserId: userId,
Category: model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, Category: model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL,
@@ -8010,7 +8010,7 @@ func testCreateInitialSidebarCategories(t *testing.T, ss store.Store) {
Value: "true", Value: "true",
}, },
}) })
require.Nil(t, err) require.Nil(t, nErr)
// Create the categories // Create the categories
nErr = ss.Channel().CreateInitialSidebarCategories(userId, teamId) nErr = ss.Channel().CreateInitialSidebarCategories(userId, teamId)
@@ -8107,7 +8107,7 @@ func testCreateInitialSidebarCategories(t *testing.T, ss store.Store) {
}) })
require.Nil(t, err) require.Nil(t, err)
err = ss.Preference().Save(&model.Preferences{ nErr = ss.Preference().Save(&model.Preferences{
{ {
UserId: userId, UserId: userId,
Category: model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, Category: model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL,
@@ -8115,7 +8115,7 @@ func testCreateInitialSidebarCategories(t *testing.T, ss store.Store) {
Value: "true", Value: "true",
}, },
}) })
require.Nil(t, err) require.Nil(t, nErr)
// Create the categories // Create the categories
nErr = ss.Channel().CreateInitialSidebarCategories(userId, teamId) nErr = ss.Channel().CreateInitialSidebarCategories(userId, teamId)

Просмотреть файл

@@ -15,7 +15,7 @@ type PreferenceStore struct {
} }
// CleanupFlagsBatch provides a mock function with given fields: limit // CleanupFlagsBatch provides a mock function with given fields: limit
func (_m *PreferenceStore) CleanupFlagsBatch(limit int64) (int64, *model.AppError) { func (_m *PreferenceStore) CleanupFlagsBatch(limit int64) (int64, error) {
ret := _m.Called(limit) ret := _m.Called(limit)
var r0 int64 var r0 int64
@@ -25,68 +25,60 @@ func (_m *PreferenceStore) CleanupFlagsBatch(limit int64) (int64, *model.AppErro
r0 = ret.Get(0).(int64) r0 = ret.Get(0).(int64)
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(int64) *model.AppError); ok { if rf, ok := ret.Get(1).(func(int64) error); ok {
r1 = rf(limit) r1 = rf(limit)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
} }
// Delete provides a mock function with given fields: userId, category, name // Delete provides a mock function with given fields: userId, category, name
func (_m *PreferenceStore) Delete(userId string, category string, name string) *model.AppError { func (_m *PreferenceStore) Delete(userId string, category string, name string) error {
ret := _m.Called(userId, category, name) ret := _m.Called(userId, category, name)
var r0 *model.AppError var r0 error
if rf, ok := ret.Get(0).(func(string, string, string) *model.AppError); ok { if rf, ok := ret.Get(0).(func(string, string, string) error); ok {
r0 = rf(userId, category, name) r0 = rf(userId, category, name)
} else { } else {
if ret.Get(0) != nil { r0 = ret.Error(0)
r0 = ret.Get(0).(*model.AppError)
}
} }
return r0 return r0
} }
// DeleteCategory provides a mock function with given fields: userId, category // DeleteCategory provides a mock function with given fields: userId, category
func (_m *PreferenceStore) DeleteCategory(userId string, category string) *model.AppError { func (_m *PreferenceStore) DeleteCategory(userId string, category string) error {
ret := _m.Called(userId, category) ret := _m.Called(userId, category)
var r0 *model.AppError var r0 error
if rf, ok := ret.Get(0).(func(string, string) *model.AppError); ok { if rf, ok := ret.Get(0).(func(string, string) error); ok {
r0 = rf(userId, category) r0 = rf(userId, category)
} else { } else {
if ret.Get(0) != nil { r0 = ret.Error(0)
r0 = ret.Get(0).(*model.AppError)
}
} }
return r0 return r0
} }
// DeleteCategoryAndName provides a mock function with given fields: category, name // DeleteCategoryAndName provides a mock function with given fields: category, name
func (_m *PreferenceStore) DeleteCategoryAndName(category string, name string) *model.AppError { func (_m *PreferenceStore) DeleteCategoryAndName(category string, name string) error {
ret := _m.Called(category, name) ret := _m.Called(category, name)
var r0 *model.AppError var r0 error
if rf, ok := ret.Get(0).(func(string, string) *model.AppError); ok { if rf, ok := ret.Get(0).(func(string, string) error); ok {
r0 = rf(category, name) r0 = rf(category, name)
} else { } else {
if ret.Get(0) != nil { r0 = ret.Error(0)
r0 = ret.Get(0).(*model.AppError)
}
} }
return r0 return r0
} }
// Get provides a mock function with given fields: userId, category, name // Get provides a mock function with given fields: userId, category, name
func (_m *PreferenceStore) Get(userId string, category string, name string) (*model.Preference, *model.AppError) { func (_m *PreferenceStore) Get(userId string, category string, name string) (*model.Preference, error) {
ret := _m.Called(userId, category, name) ret := _m.Called(userId, category, name)
var r0 *model.Preference var r0 *model.Preference
@@ -98,20 +90,18 @@ func (_m *PreferenceStore) Get(userId string, category string, name string) (*mo
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string, string, string) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string, string, string) error); ok {
r1 = rf(userId, category, name) r1 = rf(userId, category, name)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
} }
// GetAll provides a mock function with given fields: userId // GetAll provides a mock function with given fields: userId
func (_m *PreferenceStore) GetAll(userId string) (model.Preferences, *model.AppError) { func (_m *PreferenceStore) GetAll(userId string) (model.Preferences, error) {
ret := _m.Called(userId) ret := _m.Called(userId)
var r0 model.Preferences var r0 model.Preferences
@@ -123,20 +113,18 @@ func (_m *PreferenceStore) GetAll(userId string) (model.Preferences, *model.AppE
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(userId) r1 = rf(userId)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
} }
// GetCategory provides a mock function with given fields: userId, category // GetCategory provides a mock function with given fields: userId, category
func (_m *PreferenceStore) GetCategory(userId string, category string) (model.Preferences, *model.AppError) { func (_m *PreferenceStore) GetCategory(userId string, category string) (model.Preferences, error) {
ret := _m.Called(userId, category) ret := _m.Called(userId, category)
var r0 model.Preferences var r0 model.Preferences
@@ -148,45 +136,39 @@ func (_m *PreferenceStore) GetCategory(userId string, category string) (model.Pr
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string, string) error); ok {
r1 = rf(userId, category) r1 = rf(userId, category)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
} }
// PermanentDeleteByUser provides a mock function with given fields: userId // PermanentDeleteByUser provides a mock function with given fields: userId
func (_m *PreferenceStore) PermanentDeleteByUser(userId string) *model.AppError { func (_m *PreferenceStore) PermanentDeleteByUser(userId string) error {
ret := _m.Called(userId) ret := _m.Called(userId)
var r0 *model.AppError var r0 error
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok { if rf, ok := ret.Get(0).(func(string) error); ok {
r0 = rf(userId) r0 = rf(userId)
} else { } else {
if ret.Get(0) != nil { r0 = ret.Error(0)
r0 = ret.Get(0).(*model.AppError)
}
} }
return r0 return r0
} }
// Save provides a mock function with given fields: preferences // Save provides a mock function with given fields: preferences
func (_m *PreferenceStore) Save(preferences *model.Preferences) *model.AppError { func (_m *PreferenceStore) Save(preferences *model.Preferences) error {
ret := _m.Called(preferences) ret := _m.Called(preferences)
var r0 *model.AppError var r0 error
if rf, ok := ret.Get(0).(func(*model.Preferences) *model.AppError); ok { if rf, ok := ret.Get(0).(func(*model.Preferences) error); ok {
r0 = rf(preferences) r0 = rf(preferences)
} else { } else {
if ret.Get(0) != nil { r0 = ret.Error(0)
r0 = ret.Get(0).(*model.AppError)
}
} }
return r0 return r0

Просмотреть файл

@@ -303,8 +303,8 @@ func testOAuthGetAuthorizedApps(t *testing.T, ss store.Store) {
p.Category = model.PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP p.Category = model.PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP
p.Name = a1.Id p.Name = a1.Id
p.Value = "true" p.Value = "true"
err = ss.Preference().Save(&model.Preferences{p}) nErr := ss.Preference().Save(&model.Preferences{p})
require.Nil(t, err) require.Nil(t, nErr)
apps, err = ss.OAuth().GetAuthorizedApps(a1.CreatorId, 0, 1000) apps, err = ss.OAuth().GetAuthorizedApps(a1.CreatorId, 0, 1000)
require.Nil(t, err) require.Nil(t, err)
@@ -326,8 +326,8 @@ func testOAuthGetAccessDataByUserForApp(t *testing.T, ss store.Store) {
p.Category = model.PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP p.Category = model.PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP
p.Name = a1.Id p.Name = a1.Id
p.Value = "true" p.Value = "true"
err = ss.Preference().Save(&model.Preferences{p}) nErr := ss.Preference().Save(&model.Preferences{p})
require.Nil(t, err) require.Nil(t, nErr)
apps, err := ss.OAuth().GetAuthorizedApps(a1.CreatorId, 0, 1000) apps, err := ss.OAuth().GetAuthorizedApps(a1.CreatorId, 0, 1000)
require.Nil(t, err) require.Nil(t, err)

Просмотреть файл

@@ -1902,8 +1902,8 @@ func testPostStoreGetFlaggedPosts(t *testing.T, ss store.Store) {
}, },
} }
err = ss.Preference().Save(&preferences) nErr := ss.Preference().Save(&preferences)
require.Nil(t, err) require.Nil(t, nErr)
r2, err := ss.Post().GetFlaggedPosts(o1.UserId, 0, 2) r2, err := ss.Post().GetFlaggedPosts(o1.UserId, 0, 2)
require.Nil(t, err) require.Nil(t, err)
@@ -1918,8 +1918,8 @@ func testPostStoreGetFlaggedPosts(t *testing.T, ss store.Store) {
}, },
} }
err = ss.Preference().Save(&preferences) nErr = ss.Preference().Save(&preferences)
require.Nil(t, err) require.Nil(t, nErr)
r3, err := ss.Post().GetFlaggedPosts(o1.UserId, 0, 1) r3, err := ss.Post().GetFlaggedPosts(o1.UserId, 0, 1)
require.Nil(t, err) require.Nil(t, err)
@@ -1946,8 +1946,8 @@ func testPostStoreGetFlaggedPosts(t *testing.T, ss store.Store) {
}, },
} }
err = ss.Preference().Save(&preferences) nErr = ss.Preference().Save(&preferences)
require.Nil(t, err) require.Nil(t, nErr)
r4, err = ss.Post().GetFlaggedPosts(o1.UserId, 0, 2) r4, err = ss.Post().GetFlaggedPosts(o1.UserId, 0, 2)
require.Nil(t, err) require.Nil(t, err)
@@ -2000,20 +2000,20 @@ func testPostStoreGetFlaggedPostsForChannel(t *testing.T, ss store.Store) {
Value: "true", Value: "true",
} }
err = ss.Preference().Save(&model.Preferences{preference}) nErr := ss.Preference().Save(&model.Preferences{preference})
require.Nil(t, err) require.Nil(t, nErr)
r, err = ss.Post().GetFlaggedPostsForChannel(o1.UserId, o1.ChannelId, 0, 10) r, err = ss.Post().GetFlaggedPostsForChannel(o1.UserId, o1.ChannelId, 0, 10)
require.Nil(t, err) require.Nil(t, err)
require.Len(t, r.Order, 1, "should have 1 post") require.Len(t, r.Order, 1, "should have 1 post")
preference.Name = o2.Id preference.Name = o2.Id
err = ss.Preference().Save(&model.Preferences{preference}) nErr = ss.Preference().Save(&model.Preferences{preference})
require.Nil(t, err) require.Nil(t, nErr)
preference.Name = o3.Id preference.Name = o3.Id
err = ss.Preference().Save(&model.Preferences{preference}) nErr = ss.Preference().Save(&model.Preferences{preference})
require.Nil(t, err) require.Nil(t, nErr)
r, err = ss.Post().GetFlaggedPostsForChannel(o1.UserId, o1.ChannelId, 0, 1) r, err = ss.Post().GetFlaggedPostsForChannel(o1.UserId, o1.ChannelId, 0, 1)
require.Nil(t, err) require.Nil(t, err)
@@ -2032,8 +2032,8 @@ func testPostStoreGetFlaggedPostsForChannel(t *testing.T, ss store.Store) {
require.Len(t, r.Order, 2, "should have 2 posts") require.Len(t, r.Order, 2, "should have 2 posts")
preference.Name = o4.Id preference.Name = o4.Id
err = ss.Preference().Save(&model.Preferences{preference}) nErr = ss.Preference().Save(&model.Preferences{preference})
require.Nil(t, err) require.Nil(t, nErr)
r, err = ss.Post().GetFlaggedPostsForChannel(o1.UserId, o4.ChannelId, 0, 10) r, err = ss.Post().GetFlaggedPostsForChannel(o1.UserId, o4.ChannelId, 0, 10)
require.Nil(t, err) require.Nil(t, err)

Просмотреть файл

@@ -356,15 +356,15 @@ func testPreferenceCleanupFlagsBatch(t *testing.T, ss store.Store) {
Value: "true", Value: "true",
} }
err = ss.Preference().Save(&model.Preferences{preference1, preference2}) nErr := ss.Preference().Save(&model.Preferences{preference1, preference2})
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Preference().CleanupFlagsBatch(10000) _, nErr = ss.Preference().CleanupFlagsBatch(10000)
assert.Nil(t, err) assert.Nil(t, nErr)
_, err = ss.Preference().Get(userId, category, preference1.Name) _, nErr = ss.Preference().Get(userId, category, preference1.Name)
assert.Nil(t, err) assert.Nil(t, nErr)
_, err = ss.Preference().Get(userId, category, preference2.Name) _, nErr = ss.Preference().Get(userId, category, preference2.Name)
assert.NotNil(t, err) assert.NotNil(t, nErr)
} }

Просмотреть файл

@@ -4845,7 +4845,7 @@ func (s *TimerLayerPostStore) Update(newPost *model.Post, oldPost *model.Post) (
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *TimerLayerPreferenceStore) CleanupFlagsBatch(limit int64) (int64, *model.AppError) { func (s *TimerLayerPreferenceStore) CleanupFlagsBatch(limit int64) (int64, error) {
start := timemodule.Now() start := timemodule.Now()
resultVar0, resultVar1 := s.PreferenceStore.CleanupFlagsBatch(limit) resultVar0, resultVar1 := s.PreferenceStore.CleanupFlagsBatch(limit)
@@ -4861,7 +4861,7 @@ func (s *TimerLayerPreferenceStore) CleanupFlagsBatch(limit int64) (int64, *mode
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *TimerLayerPreferenceStore) Delete(userId string, category string, name string) *model.AppError { func (s *TimerLayerPreferenceStore) Delete(userId string, category string, name string) error {
start := timemodule.Now() start := timemodule.Now()
resultVar0 := s.PreferenceStore.Delete(userId, category, name) resultVar0 := s.PreferenceStore.Delete(userId, category, name)
@@ -4877,7 +4877,7 @@ func (s *TimerLayerPreferenceStore) Delete(userId string, category string, name
return resultVar0 return resultVar0
} }
func (s *TimerLayerPreferenceStore) DeleteCategory(userId string, category string) *model.AppError { func (s *TimerLayerPreferenceStore) DeleteCategory(userId string, category string) error {
start := timemodule.Now() start := timemodule.Now()
resultVar0 := s.PreferenceStore.DeleteCategory(userId, category) resultVar0 := s.PreferenceStore.DeleteCategory(userId, category)
@@ -4893,7 +4893,7 @@ func (s *TimerLayerPreferenceStore) DeleteCategory(userId string, category strin
return resultVar0 return resultVar0
} }
func (s *TimerLayerPreferenceStore) DeleteCategoryAndName(category string, name string) *model.AppError { func (s *TimerLayerPreferenceStore) DeleteCategoryAndName(category string, name string) error {
start := timemodule.Now() start := timemodule.Now()
resultVar0 := s.PreferenceStore.DeleteCategoryAndName(category, name) resultVar0 := s.PreferenceStore.DeleteCategoryAndName(category, name)
@@ -4909,7 +4909,7 @@ func (s *TimerLayerPreferenceStore) DeleteCategoryAndName(category string, name
return resultVar0 return resultVar0
} }
func (s *TimerLayerPreferenceStore) Get(userId string, category string, name string) (*model.Preference, *model.AppError) { func (s *TimerLayerPreferenceStore) Get(userId string, category string, name string) (*model.Preference, error) {
start := timemodule.Now() start := timemodule.Now()
resultVar0, resultVar1 := s.PreferenceStore.Get(userId, category, name) resultVar0, resultVar1 := s.PreferenceStore.Get(userId, category, name)
@@ -4925,7 +4925,7 @@ func (s *TimerLayerPreferenceStore) Get(userId string, category string, name str
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *TimerLayerPreferenceStore) GetAll(userId string) (model.Preferences, *model.AppError) { func (s *TimerLayerPreferenceStore) GetAll(userId string) (model.Preferences, error) {
start := timemodule.Now() start := timemodule.Now()
resultVar0, resultVar1 := s.PreferenceStore.GetAll(userId) resultVar0, resultVar1 := s.PreferenceStore.GetAll(userId)
@@ -4941,7 +4941,7 @@ func (s *TimerLayerPreferenceStore) GetAll(userId string) (model.Preferences, *m
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *TimerLayerPreferenceStore) GetCategory(userId string, category string) (model.Preferences, *model.AppError) { func (s *TimerLayerPreferenceStore) GetCategory(userId string, category string) (model.Preferences, error) {
start := timemodule.Now() start := timemodule.Now()
resultVar0, resultVar1 := s.PreferenceStore.GetCategory(userId, category) resultVar0, resultVar1 := s.PreferenceStore.GetCategory(userId, category)
@@ -4957,7 +4957,7 @@ func (s *TimerLayerPreferenceStore) GetCategory(userId string, category string)
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *TimerLayerPreferenceStore) PermanentDeleteByUser(userId string) *model.AppError { func (s *TimerLayerPreferenceStore) PermanentDeleteByUser(userId string) error {
start := timemodule.Now() start := timemodule.Now()
resultVar0 := s.PreferenceStore.PermanentDeleteByUser(userId) resultVar0 := s.PreferenceStore.PermanentDeleteByUser(userId)
@@ -4973,7 +4973,7 @@ func (s *TimerLayerPreferenceStore) PermanentDeleteByUser(userId string) *model.
return resultVar0 return resultVar0
} }
func (s *TimerLayerPreferenceStore) Save(preferences *model.Preferences) *model.AppError { func (s *TimerLayerPreferenceStore) Save(preferences *model.Preferences) error {
start := timemodule.Now() start := timemodule.Now()
resultVar0 := s.PreferenceStore.Save(preferences) resultVar0 := s.PreferenceStore.Save(preferences)