MM-26031: Migrate reaction store to plain errors (#14931)
* ReactionStore migration to return plain errors * Fix translations * FixImports * Rollback fix imports * Fix merge conflict * add ent translation Co-authored-by: Rodrigo Villablanca <villa061004@gmail.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
00aeca0e5c
Коммит
71925ea224
@@ -403,14 +403,13 @@ func (a *App) buildPostReplies(postId string) (*[]ReplyImportData, *model.AppErr
|
||||
func (a *App) BuildPostReactions(postId string) (*[]ReactionImportData, *model.AppError) {
|
||||
var reactionsOfPost []ReactionImportData
|
||||
|
||||
reactions, err := a.Srv().Store.Reaction().GetForPost(postId, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
reactions, nErr := a.Srv().Store.Reaction().GetForPost(postId, true)
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("BuildPostReactions", "app.reaction.get_for_post.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
for _, reaction := range reactions {
|
||||
var user *model.User
|
||||
user, err = a.Srv().Store.User().Get(reaction.UserId)
|
||||
user, err := a.Srv().Store.User().Get(reaction.UserId)
|
||||
if err != nil {
|
||||
if err.Id == store.MISSING_ACCOUNT_ERROR { // this is a valid case, the user that reacted might've been deleted by now
|
||||
mlog.Info("Skipping reactions by user since the entity doesn't exist anymore", mlog.String("user_id", reaction.UserId))
|
||||
|
||||
@@ -953,8 +953,14 @@ func (a *App) importReaction(data *ReactionImportData, post *model.Post, dryRun
|
||||
EmojiName: *data.EmojiName,
|
||||
CreateAt: *data.CreateAt,
|
||||
}
|
||||
if _, err = a.Srv().Store.Reaction().Save(reaction); err != nil {
|
||||
return err
|
||||
if _, nErr := a.Srv().Store.Reaction().Save(reaction); nErr != nil {
|
||||
var appErr *model.AppError
|
||||
switch {
|
||||
case errors.As(nErr, &appErr):
|
||||
return appErr
|
||||
default:
|
||||
return model.NewAppError("importReaction", "app.reaction.save.save.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -2278,8 +2278,8 @@ func TestImportimportMultiplePostLines(t *testing.T) {
|
||||
postBool = post.Message != *data.Post.Message || post.CreateAt != *data.Post.CreateAt || post.UserId != user.Id || !post.HasReactions
|
||||
require.False(t, postBool, "Post properties not as expected")
|
||||
|
||||
reactions, err := th.App.Srv().Store.Reaction().GetForPost(post.Id, false)
|
||||
require.Nil(t, err, "Can't get reaction")
|
||||
reactions, nErr := th.App.Srv().Store.Reaction().GetForPost(post.Id, false)
|
||||
require.Nil(t, nErr, "Can't get reaction")
|
||||
|
||||
require.Len(t, reactions, 1, "Invalid number of reactions")
|
||||
|
||||
@@ -2768,8 +2768,8 @@ func TestImportImportPost(t *testing.T) {
|
||||
postBool := post.Message != *data.Post.Message || post.CreateAt != *data.Post.CreateAt || post.UserId != user.Id || !post.HasReactions
|
||||
require.False(t, postBool, "Post properties not as expected")
|
||||
|
||||
reactions, err := th.App.Srv().Store.Reaction().GetForPost(post.Id, false)
|
||||
require.Nil(t, err, "Can't get reaction")
|
||||
reactions, nErr := th.App.Srv().Store.Reaction().GetForPost(post.Id, false)
|
||||
require.Nil(t, nErr, "Can't get reaction")
|
||||
|
||||
require.Len(t, reactions, 1, "Invalid number of reactions")
|
||||
})
|
||||
@@ -3635,8 +3635,8 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
postBool := post.Message != *data.DirectPost.Message || post.CreateAt != *data.DirectPost.CreateAt || post.UserId != th.BasicUser.Id || !post.HasReactions
|
||||
require.False(t, postBool, "Post properties not as expected")
|
||||
|
||||
reactions, err := th.App.Srv().Store.Reaction().GetForPost(post.Id, false)
|
||||
require.Nil(t, err, "Can't get reaction")
|
||||
reactions, nErr := th.App.Srv().Store.Reaction().GetForPost(post.Id, false)
|
||||
require.Nil(t, nErr, "Can't get reaction")
|
||||
|
||||
require.Len(t, reactions, 1, "Invalid number of reactions")
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
@@ -36,9 +37,15 @@ func (a *App) SaveReactionForPost(reaction *model.Reaction) (*model.Reaction, *m
|
||||
}
|
||||
}
|
||||
|
||||
reaction, err = a.Srv().Store.Reaction().Save(reaction)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
reaction, nErr := a.Srv().Store.Reaction().Save(reaction)
|
||||
if nErr != nil {
|
||||
var appErr *model.AppError
|
||||
switch {
|
||||
case errors.As(nErr, &appErr):
|
||||
return nil, appErr
|
||||
default:
|
||||
return nil, model.NewAppError("SaveReactionForPost", "app.reaction.save.save.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
// The post is always modified since the UpdateAt always changes
|
||||
@@ -52,7 +59,11 @@ func (a *App) SaveReactionForPost(reaction *model.Reaction) (*model.Reaction, *m
|
||||
}
|
||||
|
||||
func (a *App) GetReactionsForPost(postId string) ([]*model.Reaction, *model.AppError) {
|
||||
return a.Srv().Store.Reaction().GetForPost(postId, true)
|
||||
reactions, err := a.Srv().Store.Reaction().GetForPost(postId, true)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetReactionsForPost", "app.reaction.get_for_post.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reactions, nil
|
||||
}
|
||||
|
||||
func (a *App) GetBulkReactionsForPosts(postIds []string) (map[string][]*model.Reaction, *model.AppError) {
|
||||
@@ -60,7 +71,7 @@ func (a *App) GetBulkReactionsForPosts(postIds []string) (map[string][]*model.Re
|
||||
|
||||
allReactions, err := a.Srv().Store.Reaction().BulkGetForPosts(postIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, model.NewAppError("GetBulkReactionsForPosts", "app.reaction.bulk_get_for_post_ids.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
for _, reaction := range allReactions {
|
||||
@@ -95,7 +106,7 @@ func (a *App) DeleteReactionForPost(reaction *model.Reaction) *model.AppError {
|
||||
}
|
||||
|
||||
if channel.DeleteAt > 0 {
|
||||
return model.NewAppError("deleteReactionForPost", "api.reaction.delete.archived_channel.app_error", nil, "", http.StatusForbidden)
|
||||
return model.NewAppError("DeleteReactionForPost", "api.reaction.delete.archived_channel.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
|
||||
if a.Srv().License() != nil && *a.Config().TeamSettings.ExperimentalTownSquareIsReadOnly && channel.Name == model.DEFAULT_CHANNEL {
|
||||
@@ -105,7 +116,7 @@ func (a *App) DeleteReactionForPost(reaction *model.Reaction) *model.AppError {
|
||||
}
|
||||
|
||||
if !a.RolesGrantPermission(user.GetRoles(), model.PERMISSION_MANAGE_SYSTEM.Id) {
|
||||
return model.NewAppError("deleteReactionForPost", "api.reaction.town_square_read_only", nil, "", http.StatusForbidden)
|
||||
return model.NewAppError("DeleteReactionForPost", "api.reaction.town_square_read_only", nil, "", http.StatusForbidden)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +126,7 @@ func (a *App) DeleteReactionForPost(reaction *model.Reaction) *model.AppError {
|
||||
}
|
||||
|
||||
if _, err := a.Srv().Store.Reaction().Delete(reaction); err != nil {
|
||||
return err
|
||||
return model.NewAppError("DeleteReactionForPost", "app.reaction.delete_all_with_emoji_name.get_reactions.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
// The post is always modified since the UpdateAt always changes
|
||||
|
||||
Ссылка в новой задаче
Block a user