GH-9633 Added plugin API method to return user's profile image (#9653)
Этот коммит содержится в:
коммит произвёл
Carlos Tadeu Panato Junior
родитель
c1e5fff565
Коммит
160d278592
@@ -323,6 +323,16 @@ func (api *PluginAPI) UpdatePost(post *model.Post) (*model.Post, *model.AppError
|
||||
return api.app.UpdatePost(post, false)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetProfileImage(userId string) ([]byte, *model.AppError) {
|
||||
user, err := api.app.GetUser(userId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data, _, err := api.app.GetProfileImage(user)
|
||||
return data, err
|
||||
}
|
||||
|
||||
func (api *PluginAPI) CopyFileInfos(userId string, fileIds []string) ([]string, *model.AppError) {
|
||||
return api.app.CopyFileInfos(userId, fileIds)
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ func TestPluginAPILoadPluginConfiguration(t *testing.T) {
|
||||
}
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
plugin.MattermostPlugin
|
||||
|
||||
configuration configuration
|
||||
}
|
||||
@@ -199,3 +199,19 @@ func TestPluginAPILoadPluginConfigurationDefaults(t *testing.T) {
|
||||
_, ret := hooks.MessageWillBePosted(nil, nil)
|
||||
assert.Equal(t, "override35true", ret)
|
||||
}
|
||||
|
||||
func TestPluginAPIGetProfileImage(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
api := th.SetupPluginAPI()
|
||||
|
||||
// check existing user first
|
||||
data, err := api.GetProfileImage(th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
require.NotEmpty(t, data)
|
||||
|
||||
// then unknown user
|
||||
data, err = api.GetProfileImage(model.NewId())
|
||||
require.NotNil(t, err)
|
||||
require.Nil(t, data)
|
||||
}
|
||||
|
||||
@@ -185,6 +185,9 @@ type API interface {
|
||||
// UpdatePost updates a post.
|
||||
UpdatePost(post *model.Post) (*model.Post, *model.AppError)
|
||||
|
||||
// GetProfileImage gets user's profile image
|
||||
GetProfileImage(userId string) ([]byte, *model.AppError)
|
||||
|
||||
// CopyFileInfos duplicates the FileInfo objects referenced by the given file ids,
|
||||
// recording the given user id as the new creator and returning the new set of file ids.
|
||||
//
|
||||
|
||||
@@ -2098,6 +2098,35 @@ func (s *apiRPCServer) UpdatePost(args *Z_UpdatePostArgs, returns *Z_UpdatePostR
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_GetProfileImageArgs struct {
|
||||
A string
|
||||
}
|
||||
|
||||
type Z_GetProfileImageReturns struct {
|
||||
A []byte
|
||||
B *model.AppError
|
||||
}
|
||||
|
||||
func (g *apiRPCClient) GetProfileImage(userId string) ([]byte, *model.AppError) {
|
||||
_args := &Z_GetProfileImageArgs{userId}
|
||||
_returns := &Z_GetProfileImageReturns{}
|
||||
if err := g.client.Call("Plugin.GetProfileImage", _args, _returns); err != nil {
|
||||
log.Printf("RPC call to GetProfileImage API failed: %s", err.Error())
|
||||
}
|
||||
return _returns.A, _returns.B
|
||||
}
|
||||
|
||||
func (s *apiRPCServer) GetProfileImage(args *Z_GetProfileImageArgs, returns *Z_GetProfileImageReturns) error {
|
||||
if hook, ok := s.impl.(interface {
|
||||
GetProfileImage(userId string) ([]byte, *model.AppError)
|
||||
}); ok {
|
||||
returns.A, returns.B = hook.GetProfileImage(args.A)
|
||||
} else {
|
||||
return encodableError(fmt.Errorf("API GetProfileImage called but not implemented."))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_CopyFileInfosArgs struct {
|
||||
A string
|
||||
B []string
|
||||
|
||||
@@ -674,6 +674,31 @@ func (_m *API) GetPostsSince(channelId string, time int64) (*model.PostList, *mo
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetProfileImage provides a mock function with given fields: userId
|
||||
func (_m *API) GetProfileImage(userId string) ([]byte, *model.AppError) {
|
||||
ret := _m.Called(userId)
|
||||
|
||||
var r0 []byte
|
||||
if rf, ok := ret.Get(0).(func(string) []byte); ok {
|
||||
r0 = rf(userId)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]byte)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||
r1 = rf(userId)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetPublicChannelsForTeam provides a mock function with given fields: teamId, offset, limit
|
||||
func (_m *API) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
|
||||
ret := _m.Called(teamId, offset, limit)
|
||||
|
||||
Ссылка в новой задаче
Block a user