diff --git a/app/plugin_api.go b/app/plugin_api.go index 64c6dc44b8..d6b601332e 100644 --- a/app/plugin_api.go +++ b/app/plugin_api.go @@ -510,6 +510,19 @@ func (api *PluginAPI) OpenInteractiveDialog(dialog model.OpenDialogRequest) *mod return api.app.OpenInteractiveDialog(dialog) } +func (api *PluginAPI) RemoveTeamIcon(teamId string) *model.AppError { + _, err := api.app.GetTeam(teamId) + if err != nil { + return err + } + + err = api.app.RemoveTeamIcon(teamId) + if err != nil { + return err + } + return nil +} + // Plugin Section func (api *PluginAPI) GetPlugins() ([]*model.Manifest, *model.AppError) { diff --git a/app/plugin_api_test.go b/app/plugin_api_test.go index 8fc2e1dfd9..e17dda9763 100644 --- a/app/plugin_api_test.go +++ b/app/plugin_api_test.go @@ -87,18 +87,18 @@ func TestPluginAPISavePluginConfig(t *testing.T) { t.Fatal(err) } - if err := api.SavePluginConfig(pluginConfig); err != nil{ + if err := api.SavePluginConfig(pluginConfig); err != nil { t.Fatal(err) } type Configuration struct { MyStringSetting string - MyIntSetting int - MyBoolSetting bool + MyIntSetting int + MyBoolSetting bool } savedConfiguration := new(Configuration) - if err := api.LoadPluginConfiguration(savedConfiguration); err != nil{ + if err := api.LoadPluginConfiguration(savedConfiguration); err != nil { t.Fatal(err) } @@ -486,3 +486,26 @@ func TestPluginAPIGetChannelsForTeamForUser(t *testing.T) { assert.Empty(t, channels) }) } + +func TestPluginAPIRemoveTeamIcon(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) + err1 := png.Encode(buf, img) + require.Nil(t, err1) + dataBytes := buf.Bytes() + fileReader := bytes.NewReader(dataBytes) + + // Set the Team Icon + err := th.App.SetTeamIconFromFile(th.BasicTeam, fileReader) + require.Nil(t, err) + err = api.RemoveTeamIcon(th.BasicTeam.Id) + require.Nil(t, err) +} diff --git a/plugin/api.go b/plugin/api.go index bd305b3bd4..93f73ff08d 100644 --- a/plugin/api.go +++ b/plugin/api.go @@ -74,16 +74,21 @@ type API interface { // Minimum server version: 5.6 GetUsersInTeam(teamId string, page int, perPage int) ([]*model.User, *model.AppError) - // GetTeamIcon gets the Team Icon. + // GetTeamIcon gets the team icon. // // Minimum server version: 5.6 GetTeamIcon(teamId string) ([]byte, *model.AppError) - // SetTeamIcon sets the Team Icon. + // SetTeamIcon sets the team icon. // // Minimum server version: 5.6 SetTeamIcon(teamId string, data []byte) *model.AppError + // RemoveTeamIcon removes the team icon. + // + // Minimum server version: 5.6 + RemoveTeamIcon(teamId string) *model.AppError + // UpdateUser updates a user. UpdateUser(user *model.User) (*model.User, *model.AppError) diff --git a/plugin/client_rpc_generated.go b/plugin/client_rpc_generated.go index 53ffcc76ca..a352074845 100644 --- a/plugin/client_rpc_generated.go +++ b/plugin/client_rpc_generated.go @@ -1000,6 +1000,34 @@ func (s *apiRPCServer) SetTeamIcon(args *Z_SetTeamIconArgs, returns *Z_SetTeamIc return nil } +type Z_RemoveTeamIconArgs struct { + A string +} + +type Z_RemoveTeamIconReturns struct { + A *model.AppError +} + +func (g *apiRPCClient) RemoveTeamIcon(teamId string) *model.AppError { + _args := &Z_RemoveTeamIconArgs{teamId} + _returns := &Z_RemoveTeamIconReturns{} + if err := g.client.Call("Plugin.RemoveTeamIcon", _args, _returns); err != nil { + log.Printf("RPC call to RemoveTeamIcon API failed: %s", err.Error()) + } + return _returns.A +} + +func (s *apiRPCServer) RemoveTeamIcon(args *Z_RemoveTeamIconArgs, returns *Z_RemoveTeamIconReturns) error { + if hook, ok := s.impl.(interface { + RemoveTeamIcon(teamId string) *model.AppError + }); ok { + returns.A = hook.RemoveTeamIcon(args.A) + } else { + return encodableError(fmt.Errorf("API RemoveTeamIcon called but not implemented.")) + } + return nil +} + type Z_UpdateUserArgs struct { A *model.User } diff --git a/plugin/plugintest/api.go b/plugin/plugintest/api.go index 40dc29e87a..5abde3308d 100644 --- a/plugin/plugintest/api.go +++ b/plugin/plugintest/api.go @@ -1833,6 +1833,22 @@ func (_m *API) RemoveReaction(reaction *model.Reaction) *model.AppError { return r0 } +// RemoveTeamIcon provides a mock function with given fields: teamId +func (_m *API) RemoveTeamIcon(teamId string) *model.AppError { + ret := _m.Called(teamId) + + var r0 *model.AppError + if rf, ok := ret.Get(0).(func(string) *model.AppError); ok { + r0 = rf(teamId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.AppError) + } + } + + return r0 +} + // SaveConfig provides a mock function with given fields: config func (_m *API) SaveConfig(config *model.Config) *model.AppError { ret := _m.Called(config)