Migrate emojiStore to use request.CTX instead of context.Context (#24514)
* migrate emojistore to request.ctx * use mlog.CreateConsoleTestLogger * Add comment to WithMaster and RequestContextWithMaster
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e9cc03c1c8
Коммит
f65dad83bb
@@ -5,7 +5,6 @@ package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -60,7 +59,7 @@ func (a *App) CreateEmoji(c request.CTX, sessionUserId string, emoji *model.Emoj
|
||||
return nil, model.NewAppError("createEmoji", "api.emoji.create.other_user.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
|
||||
if existingEmoji, err := a.Srv().Store().Emoji().GetByName(context.Background(), emoji.Name, true); err == nil && existingEmoji != nil {
|
||||
if existingEmoji, err := a.Srv().Store().Emoji().GetByName(c, emoji.Name, true); err == nil && existingEmoji != nil {
|
||||
return nil, model.NewAppError("createEmoji", "api.emoji.create.duplicate.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
|
||||
@@ -191,7 +190,7 @@ func (a *App) GetEmoji(c request.CTX, emojiId string) (*model.Emoji, *model.AppE
|
||||
return nil, model.NewAppError("GetEmoji", "api.emoji.storage.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
|
||||
emoji, err := a.Srv().Store().Emoji().Get(c.Context(), emojiId, true)
|
||||
emoji, err := a.Srv().Store().Emoji().Get(c, emojiId, true)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
@@ -214,7 +213,7 @@ func (a *App) GetEmojiByName(c request.CTX, emojiName string) (*model.Emoji, *mo
|
||||
return nil, model.NewAppError("GetEmojiByName", "api.emoji.storage.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
|
||||
emoji, err := a.Srv().Store().Emoji().GetByName(c.Context(), emojiName, true)
|
||||
emoji, err := a.Srv().Store().Emoji().GetByName(c, emojiName, true)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
@@ -247,7 +246,7 @@ func (a *App) GetMultipleEmojiByName(c request.CTX, names []string) ([]*model.Em
|
||||
return []*model.Emoji{}, nil
|
||||
}
|
||||
|
||||
emoji, err := a.Srv().Store().Emoji().GetMultipleByName(c.Context(), names)
|
||||
emoji, err := a.Srv().Store().Emoji().GetMultipleByName(c, names)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetMultipleEmojiByName", "app.emoji.get_by_name.app_error", nil, fmt.Sprintf("names=%v, %v", names, err.Error()), http.StatusInternalServerError)
|
||||
}
|
||||
@@ -256,7 +255,7 @@ func (a *App) GetMultipleEmojiByName(c request.CTX, names []string) ([]*model.Em
|
||||
}
|
||||
|
||||
func (a *App) GetEmojiImage(c request.CTX, emojiId string) ([]byte, string, *model.AppError) {
|
||||
_, storeErr := a.Srv().Store().Emoji().Get(c.Context(), emojiId, true)
|
||||
_, storeErr := a.Srv().Store().Emoji().Get(c, emojiId, true)
|
||||
if storeErr != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
@@ -302,7 +301,7 @@ func (a *App) GetEmojiStaticURL(c request.CTX, emojiName string) (string, *model
|
||||
return path.Join(subPath, "/static/emoji", id+".png"), nil
|
||||
}
|
||||
|
||||
emoji, err := a.Srv().Store().Emoji().GetByName(context.Background(), emojiName, true)
|
||||
emoji, err := a.Srv().Store().Emoji().GetByName(c, emojiName, true)
|
||||
if err == nil {
|
||||
return path.Join(subPath, "/api/v4/emoji", emoji.Id, "image"), nil
|
||||
}
|
||||
|
||||
@@ -1953,7 +1953,7 @@ func (a *App) importEmoji(c request.CTX, data *imports.EmojiImportData, dryRun b
|
||||
|
||||
var emoji *model.Emoji
|
||||
|
||||
emoji, err := a.Srv().Store().Emoji().GetByName(context.Background(), *data.Name, true)
|
||||
emoji, err := a.Srv().Store().Emoji().GetByName(c, *data.Name, true)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
if !errors.As(err, &nfErr) {
|
||||
|
||||
@@ -4168,7 +4168,7 @@ func TestImportImportEmoji(t *testing.T) {
|
||||
appErr := th.App.importEmoji(th.Context, &data, true)
|
||||
assert.NotNil(t, appErr, "Invalid emoji should have failed dry run")
|
||||
|
||||
emoji, nErr := th.App.Srv().Store().Emoji().GetByName(context.Background(), *data.Name, true)
|
||||
emoji, nErr := th.App.Srv().Store().Emoji().GetByName(th.Context, *data.Name, true)
|
||||
assert.Nil(t, emoji, "Emoji should not have been imported")
|
||||
assert.Error(t, nErr)
|
||||
|
||||
@@ -4188,7 +4188,7 @@ func TestImportImportEmoji(t *testing.T) {
|
||||
appErr = th.App.importEmoji(th.Context, &data, false)
|
||||
assert.Nil(t, appErr, "Valid emoji should have succeeded apply mode")
|
||||
|
||||
emoji, nErr = th.App.Srv().Store().Emoji().GetByName(context.Background(), *data.Name, true)
|
||||
emoji, nErr = th.App.Srv().Store().Emoji().GetByName(th.Context, *data.Name, true)
|
||||
assert.NotNil(t, emoji, "Emoji should have been imported")
|
||||
assert.NoError(t, nErr, "Emoji should have been imported without any error")
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user