[MM-48523] Expose resumable uploads API to plugins (#21700)

* Expose resumable uploads API to plugins

* Update translations
Этот коммит содержится в:
Claudio Costa
2022-11-22 15:26:22 -06:00
коммит произвёл GitHub
родитель a1e16f7b02
Коммит 0509e78744
13 изменённых файлов: 362 добавлений и 19 удалений

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

@@ -65,6 +65,13 @@ func createUpload(c *Context, w http.ResponseWriter, r *http.Request) {
if c.AppContext.Session().UserId != "" {
us.UserId = c.AppContext.Session().UserId
}
if us.FileSize > *c.App.Config().FileSettings.MaxFileSize {
c.Err = model.NewAppError("createUpload", "api.upload.create.upload_too_large.app_error",
map[string]any{"channelId": us.ChannelId}, "", http.StatusRequestEntityTooLarge)
return
}
rus, err := c.App.CreateUploadSession(c.AppContext, &us)
if err != nil {
c.Err = err

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

@@ -45,6 +45,17 @@ func TestCreateUpload(t *testing.T) {
require.Equal(t, http.StatusForbidden, resp.StatusCode)
})
t.Run("FileSize over limit", func(t *testing.T) {
maxFileSize := *th.App.Config().FileSettings.MaxFileSize
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.MaxFileSize = us.FileSize - 1 })
defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.MaxFileSize = maxFileSize })
us.ChannelId = th.BasicChannel.Id
u, resp, err := th.Client.CreateUpload(us)
require.Nil(t, u)
CheckErrorID(t, err, "api.upload.create.upload_too_large.app_error")
require.Equal(t, http.StatusRequestEntityTooLarge, resp.StatusCode)
})
t.Run("not allowed in cloud", func(t *testing.T) {
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
defer th.App.Srv().RemoveLicense()