diff --git a/api4/upload.go b/api4/upload.go index bac31f2790..f6b665bb69 100644 --- a/api4/upload.go +++ b/api4/upload.go @@ -48,6 +48,11 @@ func createUpload(c *Context, w http.ResponseWriter, r *http.Request) { c.SetPermissionError(model.PermissionManageSystem) return } + if c.App.Srv().License() != nil && *c.App.Srv().License().Features.Cloud { + c.Err = model.NewAppError("createUpload", "api.file.cloud_upload.app_error", nil, "", http.StatusBadRequest) + return + } + } else { if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), us.ChannelId, model.PermissionUploadFile) { c.SetPermissionError(model.PermissionUploadFile) @@ -122,6 +127,10 @@ func uploadData(c *Context, w http.ResponseWriter, r *http.Request) { c.SetPermissionError(model.PermissionManageSystem) return } + if c.App.Srv().License() != nil && *c.App.Srv().License().Features.Cloud { + c.Err = model.NewAppError("UploadData", "api.file.cloud_upload.app_error", nil, "", http.StatusBadRequest) + return + } } else { if us.UserId != c.AppContext.Session().UserId || !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), us.ChannelId, model.PermissionUploadFile) { c.SetPermissionError(model.PermissionUploadFile) diff --git a/api4/upload_test.go b/api4/upload_test.go index 19a786daf7..6bcfa2630e 100644 --- a/api4/upload_test.go +++ b/api4/upload_test.go @@ -45,6 +45,21 @@ func TestCreateUpload(t *testing.T) { require.Equal(t, http.StatusForbidden, resp.StatusCode) }) + t.Run("not allowed in cloud", func(t *testing.T) { + th.App.Srv().SetLicense(model.NewTestLicense("cloud")) + defer th.App.Srv().RemoveLicense() + + u, resp, err := th.SystemAdminClient.CreateUpload(&model.UploadSession{ + ChannelId: th.BasicChannel.Id, + Filename: "upload", + FileSize: 8 * 1024 * 1024, + Type: model.UploadTypeImport, + }) + require.Nil(t, u) + CheckErrorID(t, err, "api.file.cloud_upload.app_error") + require.Equal(t, http.StatusBadRequest, resp.StatusCode) + }) + t.Run("valid", func(t *testing.T) { us.ChannelId = th.BasicChannel.Id u, resp, err := th.Client.CreateUpload(us) @@ -223,6 +238,28 @@ func TestUploadData(t *testing.T) { CheckErrorID(t, err, "api.context.permissions.app_error") }) + t.Run("not allowed in cloud", func(t *testing.T) { + th.App.Srv().SetLicense(model.NewTestLicense("cloud")) + defer th.App.Srv().RemoveLicense() + + us2 := &model.UploadSession{ + Id: model.NewId(), + Type: model.UploadTypeImport, + CreateAt: model.GetMillis(), + UserId: th.BasicUser2.Id, + ChannelId: th.BasicChannel.Id, + Filename: "upload", + FileSize: 8 * 1024 * 1024, + } + _, appErr := th.App.CreateUploadSession(us2) + require.Nil(t, appErr) + + info, resp, err := th.SystemAdminClient.UploadData(us2.Id, bytes.NewReader(data)) + require.Nil(t, info) + CheckErrorID(t, err, "api.file.cloud_upload.app_error") + require.Equal(t, http.StatusBadRequest, resp.StatusCode) + }) + t.Run("bad content-length", func(t *testing.T) { u, resp, err := th.Client.CreateUpload(us) require.NoError(t, err) diff --git a/i18n/en.json b/i18n/en.json index d6a0c783c5..0e1c390d97 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -1741,6 +1741,10 @@ "id": "api.file.attachments.disabled.app_error", "translation": "File attachments have been disabled on this server." }, + { + "id": "api.file.cloud_upload.app_error", + "translation": "Uploading via mmctl to a Cloud instance is not supported. Please check the documentation here: https://docs.mattermost.com/manage/cloud-data-export.html." + }, { "id": "api.file.file_exists.app_error", "translation": "Unable to check if the file exists."