add SetTeamIcon plugin api (#9840)
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
7a8d7e53cc
Коммит
bffac3f09f
@@ -466,6 +466,20 @@ func (api *PluginAPI) GetTeamIcon(teamId string) ([]byte, *model.AppError) {
|
|||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *PluginAPI) SetTeamIcon(teamId string, data []byte) *model.AppError {
|
||||||
|
team, err := api.app.GetTeam(teamId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fileReader := bytes.NewReader(data)
|
||||||
|
err = api.app.SetTeamIconFromFile(team, fileReader)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Plugin Section
|
// Plugin Section
|
||||||
|
|
||||||
func (api *PluginAPI) GetPlugins() ([]*model.Manifest, *model.AppError) {
|
func (api *PluginAPI) GetPlugins() ([]*model.Manifest, *model.AppError) {
|
||||||
|
|||||||
@@ -332,12 +332,42 @@ func TestPluginAPIGetTeamIcon(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
// Get the team icon to check
|
// Get the team icon to check
|
||||||
imageProfile, err := api.GetTeamIcon(th.BasicTeam.Id)
|
teamIcon, err := api.GetTeamIcon(th.BasicTeam.Id)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.NotEmpty(t, imageProfile)
|
require.NotEmpty(t, teamIcon)
|
||||||
|
|
||||||
colorful := color.NRGBA{255, 0, 0, 255}
|
colorful := color.NRGBA{255, 0, 0, 255}
|
||||||
byteReader := bytes.NewReader(imageProfile)
|
byteReader := bytes.NewReader(teamIcon)
|
||||||
|
img2, _, err2 := image.Decode(byteReader)
|
||||||
|
require.Nil(t, err2)
|
||||||
|
require.Equal(t, img2.At(2, 3), colorful)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPluginAPISetTeamIcon(t *testing.T) {
|
||||||
|
th := Setup().InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
|
api := th.SetupPluginAPI()
|
||||||
|
|
||||||
|
// Create an 128 x 128 image
|
||||||
|
img := image.NewRGBA(image.Rect(0, 0, 128, 128))
|
||||||
|
// Draw a red dot at (2, 3)
|
||||||
|
img.Set(2, 3, color.RGBA{255, 0, 0, 255})
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
err := png.Encode(buf, img)
|
||||||
|
require.Nil(t, err)
|
||||||
|
dataBytes := buf.Bytes()
|
||||||
|
|
||||||
|
// Set the user profile image
|
||||||
|
err = api.SetTeamIcon(th.BasicTeam.Id, dataBytes)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
// Get the user profile image to check
|
||||||
|
teamIcon, err := api.GetTeamIcon(th.BasicTeam.Id)
|
||||||
|
require.Nil(t, err)
|
||||||
|
require.NotEmpty(t, teamIcon)
|
||||||
|
|
||||||
|
colorful := color.NRGBA{255, 0, 0, 255}
|
||||||
|
byteReader := bytes.NewReader(teamIcon)
|
||||||
img2, _, err2 := image.Decode(byteReader)
|
img2, _, err2 := image.Decode(byteReader)
|
||||||
require.Nil(t, err2)
|
require.Nil(t, err2)
|
||||||
require.Equal(t, img2.At(2, 3), colorful)
|
require.Equal(t, img2.At(2, 3), colorful)
|
||||||
|
|||||||
@@ -69,6 +69,11 @@ type API interface {
|
|||||||
// Minimum server version: 5.6
|
// Minimum server version: 5.6
|
||||||
GetTeamIcon(teamId string) ([]byte, *model.AppError)
|
GetTeamIcon(teamId string) ([]byte, *model.AppError)
|
||||||
|
|
||||||
|
// SetTeamIcon sets the Team Icon.
|
||||||
|
//
|
||||||
|
// Minimum server version: 5.6
|
||||||
|
SetTeamIcon(teamId string, data []byte) *model.AppError
|
||||||
|
|
||||||
// UpdateUser updates a user.
|
// UpdateUser updates a user.
|
||||||
UpdateUser(user *model.User) (*model.User, *model.AppError)
|
UpdateUser(user *model.User) (*model.User, *model.AppError)
|
||||||
|
|
||||||
|
|||||||
@@ -916,6 +916,35 @@ func (s *apiRPCServer) GetTeamIcon(args *Z_GetTeamIconArgs, returns *Z_GetTeamIc
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Z_SetTeamIconArgs struct {
|
||||||
|
A string
|
||||||
|
B []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
type Z_SetTeamIconReturns struct {
|
||||||
|
A *model.AppError
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *apiRPCClient) SetTeamIcon(teamId string, data []byte) *model.AppError {
|
||||||
|
_args := &Z_SetTeamIconArgs{teamId, data}
|
||||||
|
_returns := &Z_SetTeamIconReturns{}
|
||||||
|
if err := g.client.Call("Plugin.SetTeamIcon", _args, _returns); err != nil {
|
||||||
|
log.Printf("RPC call to SetTeamIcon API failed: %s", err.Error())
|
||||||
|
}
|
||||||
|
return _returns.A
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *apiRPCServer) SetTeamIcon(args *Z_SetTeamIconArgs, returns *Z_SetTeamIconReturns) error {
|
||||||
|
if hook, ok := s.impl.(interface {
|
||||||
|
SetTeamIcon(teamId string, data []byte) *model.AppError
|
||||||
|
}); ok {
|
||||||
|
returns.A = hook.SetTeamIcon(args.A, args.B)
|
||||||
|
} else {
|
||||||
|
return encodableError(fmt.Errorf("API SetTeamIcon called but not implemented."))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type Z_UpdateUserArgs struct {
|
type Z_UpdateUserArgs struct {
|
||||||
A *model.User
|
A *model.User
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1876,6 +1876,22 @@ func (_m *API) SetProfileImage(userId string, data []byte) *model.AppError {
|
|||||||
return r0
|
return r0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetTeamIcon provides a mock function with given fields: teamId, data
|
||||||
|
func (_m *API) SetTeamIcon(teamId string, data []byte) *model.AppError {
|
||||||
|
ret := _m.Called(teamId, data)
|
||||||
|
|
||||||
|
var r0 *model.AppError
|
||||||
|
if rf, ok := ret.Get(0).(func(string, []byte) *model.AppError); ok {
|
||||||
|
r0 = rf(teamId, data)
|
||||||
|
} else {
|
||||||
|
if ret.Get(0) != nil {
|
||||||
|
r0 = ret.Get(0).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0
|
||||||
|
}
|
||||||
|
|
||||||
// UnregisterCommand provides a mock function with given fields: teamId, trigger
|
// UnregisterCommand provides a mock function with given fields: teamId, trigger
|
||||||
func (_m *API) UnregisterCommand(teamId string, trigger string) error {
|
func (_m *API) UnregisterCommand(teamId string, trigger string) error {
|
||||||
ret := _m.Called(teamId, trigger)
|
ret := _m.Called(teamId, trigger)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user