preferencestore (#15018)
* 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>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8f42177870
Коммит
83974d8a8d
@@ -95,13 +95,13 @@ func TestCheckPendingNotifications(t *testing.T) {
|
||||
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
|
||||
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,
|
||||
Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS,
|
||||
Name: model.PREFERENCE_NAME_EMAIL_INTERVAL,
|
||||
Value: "60",
|
||||
}})
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
// test that notifications aren't sent before interval
|
||||
job.checkPendingNotifications(time.Unix(10001, 0), func(string, []*batchedNotification) {})
|
||||
@@ -117,13 +117,13 @@ func TestCheckPendingNotifications(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// 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,
|
||||
Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS,
|
||||
Name: model.PREFERENCE_NAME_EMAIL_INTERVAL,
|
||||
Value: "10",
|
||||
}})
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
var wasCalled int32
|
||||
job.checkPendingNotifications(time.Unix(10050, 0), func(string, []*batchedNotification) {
|
||||
@@ -253,13 +253,13 @@ func TestCheckPendingNotificationsCantParseInterval(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// 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,
|
||||
Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS,
|
||||
Name: model.PREFERENCE_NAME_EMAIL_INTERVAL,
|
||||
Value: "notAnIntegerValue",
|
||||
}})
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
job.pendingNotifications[th.BasicUser.Id] = []*batchedNotification{
|
||||
{
|
||||
|
||||
@@ -281,8 +281,8 @@ func (a *App) buildUserTeamAndChannelMemberships(userId string) (*[]UserTeamImpo
|
||||
}
|
||||
|
||||
// Get the user theme
|
||||
themePreference, err := a.Srv().Store.Preference().Get(member.UserId, model.PREFERENCE_CATEGORY_THEME, member.TeamId)
|
||||
if err == nil {
|
||||
themePreference, nErr := a.Srv().Store.Preference().Get(member.UserId, model.PREFERENCE_CATEGORY_THEME, member.TeamId)
|
||||
if nErr == nil {
|
||||
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 {
|
||||
err.StatusCode = http.StatusBadRequest
|
||||
return err
|
||||
var appErr *model.AppError
|
||||
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 {
|
||||
|
||||
@@ -215,8 +215,8 @@ func (a *App) AllowOAuthAppAccessToUser(userId string, authRequest *model.Author
|
||||
Value: authRequest.Scope,
|
||||
}
|
||||
|
||||
if err = a.Srv().Store.Preference().Save(&model.Preferences{authorizedApp}); err != nil {
|
||||
mlog.Error("error saving store prefrence", mlog.Err(err))
|
||||
if nErr := a.Srv().Store.Preference().Save(&model.Preferences{authorizedApp}); nErr != nil {
|
||||
mlog.Error("error saving store preference", mlog.Err(nErr))
|
||||
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
|
||||
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
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
@@ -12,8 +13,7 @@ import (
|
||||
func (a *App) GetPreferencesForUser(userId string) (model.Preferences, *model.AppError) {
|
||||
preferences, err := a.Srv().Store.Preference().GetAll(userId)
|
||||
if err != nil {
|
||||
err.StatusCode = http.StatusBadRequest
|
||||
return nil, err
|
||||
return nil, model.NewAppError("GetPreferencesForUser", "app.preference.get_all.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
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) {
|
||||
preferences, err := a.Srv().Store.Preference().GetCategory(userId, category)
|
||||
if err != nil {
|
||||
err.StatusCode = http.StatusBadRequest
|
||||
return nil, err
|
||||
return nil, model.NewAppError("GetPreferenceByCategoryForUser", "app.preference.get_category.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
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 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) {
|
||||
res, err := a.Srv().Store.Preference().Get(userId, category, preferenceName)
|
||||
if err != nil {
|
||||
err.StatusCode = http.StatusBadRequest
|
||||
return nil, err
|
||||
return nil, model.NewAppError("GetPreferenceByCategoryAndNameForUser", "app.preference.get.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
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 {
|
||||
err.StatusCode = http.StatusBadRequest
|
||||
return err
|
||||
var appErr *model.AppError
|
||||
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 {
|
||||
@@ -79,8 +82,7 @@ func (a *App) DeletePreferences(userId string, preferences model.Preferences) *m
|
||||
|
||||
for _, preference := range preferences {
|
||||
if err := a.Srv().Store.Preference().Delete(userId, preference.Category, preference.Name); err != nil {
|
||||
err.StatusCode = http.StatusBadRequest
|
||||
return err
|
||||
return model.NewAppError("DeletePreferences", "app.preference.delete.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
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)
|
||||
|
||||
@@ -1477,7 +1477,7 @@ func (a *App) PermanentDeleteUser(user *model.User) *model.AppError {
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
Ссылка в новой задаче
Block a user