implement GET /emoji for apiV4 (#6007)
Этот коммит содержится в:
коммит произвёл
Corey Hulen
родитель
08a469a006
Коммит
1bd19f006d
@@ -19,37 +19,33 @@ func InitEmoji() {
|
||||
l4g.Debug(utils.T("api.emoji.init.debug"))
|
||||
|
||||
BaseRoutes.Emojis.Handle("", ApiSessionRequired(createEmoji)).Methods("POST")
|
||||
BaseRoutes.Emojis.Handle("", ApiSessionRequired(getEmojiList)).Methods("GET")
|
||||
}
|
||||
|
||||
func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !*utils.Cfg.ServiceSettings.EnableCustomEmoji {
|
||||
c.Err = model.NewLocAppError("createEmoji", "api.emoji.disabled.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusNotImplemented
|
||||
c.Err = model.NewAppError("createEmoji", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
|
||||
if emojiInterface := einterfaces.GetEmojiInterface(); emojiInterface != nil &&
|
||||
!emojiInterface.CanUserCreateEmoji(c.Session.Roles, c.Session.TeamMembers) {
|
||||
c.Err = model.NewLocAppError("createEmoji", "api.emoji.create.permissions.app_error", nil, "user_id="+c.Session.UserId)
|
||||
c.Err.StatusCode = http.StatusUnauthorized
|
||||
c.Err = model.NewAppError("getEmoji", "api.emoji.disabled.app_error", nil, "user_id="+c.Session.UserId, http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
if len(utils.Cfg.FileSettings.DriverName) == 0 {
|
||||
c.Err = model.NewLocAppError("createEmoji", "api.emoji.storage.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusNotImplemented
|
||||
c.Err = model.NewAppError("createEmoji", "api.emoji.storage.app_error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
|
||||
if r.ContentLength > app.MaxEmojiFileSize {
|
||||
c.Err = model.NewLocAppError("createEmoji", "api.emoji.create.too_large.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusRequestEntityTooLarge
|
||||
c.Err = model.NewAppError("createEmoji", "api.emoji.create.too_large.app_error", nil, "", http.StatusRequestEntityTooLarge)
|
||||
return
|
||||
}
|
||||
|
||||
if err := r.ParseMultipartForm(app.MaxEmojiFileSize); err != nil {
|
||||
c.Err = model.NewLocAppError("createEmoji", "api.emoji.create.parse.app_error", nil, err.Error())
|
||||
c.Err.StatusCode = http.StatusBadRequest
|
||||
c.Err = model.NewAppError("createEmoji", "api.emoji.create.parse.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -70,3 +66,18 @@ func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(newEmoji.ToJson()))
|
||||
}
|
||||
}
|
||||
|
||||
func getEmojiList(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !*utils.Cfg.ServiceSettings.EnableCustomEmoji {
|
||||
c.Err = model.NewAppError("getEmoji", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
|
||||
listEmoji, err := app.GetEmojiList()
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
w.Write([]byte(model.EmojiListToJson(listEmoji)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,3 +137,54 @@ func TestCreateEmoji(t *testing.T) {
|
||||
_, resp = Client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
CheckForbiddenStatus(t, resp)
|
||||
}
|
||||
|
||||
func TestGetEmojiList(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer TearDown()
|
||||
Client := th.Client
|
||||
|
||||
EnableCustomEmoji := *utils.Cfg.ServiceSettings.EnableCustomEmoji
|
||||
defer func() {
|
||||
*utils.Cfg.ServiceSettings.EnableCustomEmoji = EnableCustomEmoji
|
||||
}()
|
||||
*utils.Cfg.ServiceSettings.EnableCustomEmoji = true
|
||||
|
||||
emojis := []*model.Emoji{
|
||||
{
|
||||
CreatorId: th.BasicUser.Id,
|
||||
Name: model.NewId(),
|
||||
},
|
||||
{
|
||||
CreatorId: th.BasicUser.Id,
|
||||
Name: model.NewId(),
|
||||
},
|
||||
{
|
||||
CreatorId: th.BasicUser.Id,
|
||||
Name: model.NewId(),
|
||||
},
|
||||
}
|
||||
|
||||
for idx, emoji := range emojis {
|
||||
emoji, resp := Client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
CheckNoError(t, resp)
|
||||
emojis[idx] = emoji
|
||||
}
|
||||
|
||||
listEmoji, resp := Client.GetEmojiList()
|
||||
CheckNoError(t, resp)
|
||||
for _, emoji := range emojis {
|
||||
found := false
|
||||
for _, savedEmoji := range listEmoji {
|
||||
if emoji.Id == savedEmoji.Id {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("failed to get emoji with id %v", emoji.Id)
|
||||
}
|
||||
}
|
||||
|
||||
// ADD delete test when create the delete endpoint
|
||||
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user