MM-41655: Prevent mmctl import into cloud instances (#20191)

mmctl import is not supported and therefore we stop it.

https://mattermost.atlassian.net/browse/MM-41655

```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2022-05-12 12:37:59 +05:30
коммит произвёл GitHub
родитель 1092c60bc6
Коммит 52661807f7
3 изменённых файлов: 50 добавлений и 0 удалений

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

@@ -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)

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

@@ -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)

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

@@ -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."