* 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 удалений

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

@@ -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)
}
}