* Initial implementation of a CopyFileInfos function that creates new FileInfo objects copied from provided FileIds with the provided user as the creator and not linked to a post yet. This can subsequently be used to copy existing attachments from another post to attach to a new post without having to re-upload the actual files

* added a unit test for the CopyFileInfos function

* resolving pull request suggestions
Этот коммит содержится в:
dmitrysamuylovpharo
2018-08-02 10:37:31 -04:00
коммит произвёл Harrison Healey
родитель b728b16f90
Коммит 7a731d2bd1
6 изменённых файлов: 127 добавлений и 0 удалений

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

@@ -155,6 +155,13 @@ type API interface {
// UpdatePost updates a post.
UpdatePost(post *model.Post) (*model.Post, *model.AppError)
// CopyFileInfos creates a copy of FileInfo objects provided in the list of FileIds
// these new FileInfo objects will not be linked to any post and will
// be ready to provide to a new CreatePost call
// this should be used when you want to create a copy of a post including
// file attachments without duplicating the file uploads
CopyFileInfos(userId string, fileIds []string) ([]string, *model.AppError)
// KVSet will store a key-value pair, unique per plugin.
KVSet(key string, value []byte) *model.AppError

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

@@ -1820,6 +1820,36 @@ func (s *apiRPCServer) UpdatePost(args *Z_UpdatePostArgs, returns *Z_UpdatePostR
return nil
}
type Z_CopyFileInfosArgs struct {
A string
B []string
}
type Z_CopyFileInfosReturns struct {
A []string
B *model.AppError
}
func (g *apiRPCClient) CopyFileInfos(userId string, fileIds []string) ([]string, *model.AppError) {
_args := &Z_CopyFileInfosArgs{userId, fileIds}
_returns := &Z_CopyFileInfosReturns{}
if err := g.client.Call("Plugin.CopyFileInfos", _args, _returns); err != nil {
log.Printf("RPC call to CopyFileInfos API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) CopyFileInfos(args *Z_CopyFileInfosArgs, returns *Z_CopyFileInfosReturns) error {
if hook, ok := s.impl.(interface {
CopyFileInfos(userId string, fileIds []string) ([]string, *model.AppError)
}); ok {
returns.A, returns.B = hook.CopyFileInfos(args.A, args.B)
} else {
return fmt.Errorf("API CopyFileInfos called but not implemented.")
}
return nil
}
type Z_KVSetArgs struct {
A string
B []byte

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

@@ -37,6 +37,31 @@ func (_m *API) AddChannelMember(channelId string, userId string) (*model.Channel
return r0, r1
}
// CopyFileInfos provides a mock function with given fields: userId, fileIds
func (_m *API) CopyFileInfos(userId string, fileIds []string) ([]string, *model.AppError) {
ret := _m.Called(userId, fileIds)
var r0 []string
if rf, ok := ret.Get(0).(func(string, []string) []string); ok {
r0 = rf(userId, fileIds)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]string)
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, []string) *model.AppError); ok {
r1 = rf(userId, fileIds)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// CreateChannel provides a mock function with given fields: channel
func (_m *API) CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError) {
ret := _m.Called(channel)