MM-16872 - Extend Plugin API to set LHS bot icon (#11601)

* MM-16872 - Extend Plugin API to set LHS bot icon

* MM-16872 - Using ReadSeeker as opposed to Reader for reading svg image file

* MM-16872 - PR feedback

* MM-16872 - Using userId rather than bot.UserId

* MM-16872 - Minor stylistic changes

* MM-16872 - Removing DriverName check
Этот коммит содержится в:
Ali Farooq
2019-07-11 12:00:12 -04:00
коммит произвёл GitHub
родитель 76f4fccf8a
Коммит 5ed40a48c8
10 изменённых файлов: 388 добавлений и 57 удалений

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

@@ -244,13 +244,15 @@ func getBotIconImage(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
user, err := c.App.GetUser(botUserId)
img, err := c.App.GetBotIconImage(botUserId)
if err != nil {
c.Err = err
return
}
if !user.IsBot {
c.Err = model.MakeBotNotFoundError(botUserId)
user, err := c.App.GetUser(botUserId)
if err != nil {
c.Err = err
return
}
@@ -259,19 +261,8 @@ func getBotIconImage(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
img, readFailed, err := c.App.GetBotIconImage(user.Id)
if err != nil {
c.Err = err
return
}
if readFailed {
w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%v, public", 5*60)) // 5 mins
} else {
w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%v, public", 24*60*60)) // 24 hrs
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
}
w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%v, public", 24*60*60)) // 24 hrs
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
w.Header().Set("Content-Type", "image/svg+xml")
w.Write(img)
}
@@ -290,11 +281,6 @@ func setBotIconImage(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if _, err := c.App.GetBot(botUserId, true); err != nil {
c.Err = model.MakeBotNotFoundError(botUserId)
return
}
if r.ContentLength > *c.App.Config().FileSettings.MaxFileSize {
c.Err = model.NewAppError("setBotIconImage", "api.bot.set_bot_icon_image.too_large.app_error", nil, "", http.StatusRequestEntityTooLarge)
return
@@ -318,7 +304,7 @@ func setBotIconImage(c *Context, w http.ResponseWriter, r *http.Request) {
}
imageData := imageArray[0]
if err := c.App.SetBotIconImage(botUserId, imageData); err != nil {
if err := c.App.SetBotIconImageFromMultiPartFile(botUserId, imageData); err != nil {
c.Err = err
return
}

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

@@ -1155,7 +1155,13 @@ func TestSetBotIconImage(t *testing.T) {
_, resp = th.SystemAdminClient.SetBotIconImage(bot.UserId, goodData)
CheckNoError(t, resp)
info := &model.FileInfo{Path: "/bots/" + bot.UserId + "/icon.svg"}
fpath := fmt.Sprintf("/bots/%v/icon.svg", bot.UserId)
actualData, err := th.App.ReadFile(fpath)
require.Nil(t, err)
require.NotNil(t, actualData)
require.Equal(t, goodData, actualData)
info := &model.FileInfo{Path: fpath}
err = th.cleanupTestFile(info)
require.Nil(t, err)
}