MM-17912: Allow searching for files through plugin API (#13647)
* constants and options for getting files * Method to get files with options * Add i18n strings for en * Add API methods for getting files with options * gofmt -s file * explicitly set create at in tests * use greater than nanosecond time difference for tests * use gte instead of gt for getting files by created time * use created at time as default sort order for getting file infos * use explicit inline strings instead of format strings * join tables only when required * use if as secondary sort, and update tests * update field docs to reflect previous changes * make page and perPage get options as required * add json struct tags to GetFileOptions * bump minimum server versioni * remove sorting by username and channelname * use bool for sort order type * use FileInfo prefix instead of just File * clearer comments * use zero-based page numbering * test filtering by user and channel * remove unnecessary whitespace * use int instead of uint for page and perPage arguments Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ed52acd89c
Коммит
3fc5287f6b
@@ -350,6 +350,94 @@ func TestPluginAPIGetFile(t *testing.T) {
|
||||
require.Nil(t, data)
|
||||
}
|
||||
|
||||
func TestPluginAPIGetFileInfos(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
api := th.SetupPluginAPI()
|
||||
|
||||
fileInfo1, err := th.App.DoUploadFile(
|
||||
time.Date(2020, 1, 1, 1, 1, 1, 1, time.UTC),
|
||||
th.BasicTeam.Id,
|
||||
th.BasicChannel.Id,
|
||||
th.BasicUser.Id,
|
||||
"testFile1",
|
||||
[]byte("testfile1 Content"),
|
||||
)
|
||||
require.Nil(t, err)
|
||||
defer func() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(fileInfo1.Id)
|
||||
th.App.RemoveFile(fileInfo1.Path)
|
||||
}()
|
||||
|
||||
fileInfo2, err := th.App.DoUploadFile(
|
||||
time.Date(2020, 1, 2, 1, 1, 1, 1, time.UTC),
|
||||
th.BasicTeam.Id,
|
||||
th.BasicChannel.Id,
|
||||
th.BasicUser2.Id,
|
||||
"testFile2",
|
||||
[]byte("testfile2 Content"),
|
||||
)
|
||||
require.Nil(t, err)
|
||||
defer func() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(fileInfo2.Id)
|
||||
th.App.RemoveFile(fileInfo2.Path)
|
||||
}()
|
||||
|
||||
fileInfo3, err := th.App.DoUploadFile(
|
||||
time.Date(2020, 1, 3, 1, 1, 1, 1, time.UTC),
|
||||
th.BasicTeam.Id,
|
||||
th.BasicChannel.Id,
|
||||
th.BasicUser.Id,
|
||||
"testFile3",
|
||||
[]byte("testfile3 Content"),
|
||||
)
|
||||
require.Nil(t, err)
|
||||
defer func() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(fileInfo3.Id)
|
||||
th.App.RemoveFile(fileInfo3.Path)
|
||||
}()
|
||||
|
||||
_, err = api.CreatePost(&model.Post{
|
||||
Message: "testFile1",
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
FileIds: model.StringArray{fileInfo1.Id},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = api.CreatePost(&model.Post{
|
||||
Message: "testFile2",
|
||||
UserId: th.BasicUser2.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
FileIds: model.StringArray{fileInfo2.Id},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
t.Run("get file infos with no options 2nd page of 1 per page", func(t *testing.T) {
|
||||
fileInfos, err := api.GetFileInfos(1, 1, nil)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, fileInfos, 1)
|
||||
})
|
||||
t.Run("get file infos filtered by user", func(t *testing.T) {
|
||||
fileInfos, err := api.GetFileInfos(0, 5, &model.GetFileInfosOptions{
|
||||
UserIds: []string{th.BasicUser.Id},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
require.Len(t, fileInfos, 2)
|
||||
})
|
||||
t.Run("get file infos filtered by channel ordered by created at descending", func(t *testing.T) {
|
||||
fileInfos, err := api.GetFileInfos(0, 5, &model.GetFileInfosOptions{
|
||||
ChannelIds: []string{th.BasicChannel.Id},
|
||||
SortBy: model.FILEINFO_SORT_BY_CREATED,
|
||||
SortDescending: true,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
require.Len(t, fileInfos, 2)
|
||||
require.Equal(t, fileInfos[0].Id, fileInfo2.Id)
|
||||
require.Equal(t, fileInfos[1].Id, fileInfo1.Id)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPluginAPISavePluginConfig(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
Ссылка в новой задаче
Block a user