From 72f61ab96aabf65c162c8d94b5b843b5108ee1a9 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 31 Jul 2017 08:52:45 -0700 Subject: make cli team / channel delete operations also delete webhooks and slash commands (#7028) --- app/channel.go | 8 +++++++ app/channel_test.go | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ app/team.go | 6 ++++- app/team_test.go | 41 +++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 app/channel_test.go (limited to 'app') diff --git a/app/channel.go b/app/channel.go index b077c0399..03df0e800 100644 --- a/app/channel.go +++ b/app/channel.go @@ -1184,6 +1184,14 @@ func PermanentDeleteChannel(channel *model.Channel) *model.AppError { return result.Err } + if result := <-Srv.Store.Webhook().PermanentDeleteIncomingByChannel(channel.Id); result.Err != nil { + return result.Err + } + + if result := <-Srv.Store.Webhook().PermanentDeleteOutgoingByChannel(channel.Id); result.Err != nil { + return result.Err + } + if result := <-Srv.Store.Channel().PermanentDelete(channel.Id); result.Err != nil { return result.Err } diff --git a/app/channel_test.go b/app/channel_test.go new file mode 100644 index 000000000..438eb959b --- /dev/null +++ b/app/channel_test.go @@ -0,0 +1,66 @@ +package app + +import ( + "testing" + + "github.com/mattermost/platform/model" + "github.com/mattermost/platform/utils" +) + +func TestPermanentDeleteChannel(t *testing.T) { + th := Setup().InitBasic() + + incomingWasEnabled := utils.Cfg.ServiceSettings.EnableIncomingWebhooks + outgoingWasEnabled := utils.Cfg.ServiceSettings.EnableOutgoingWebhooks + utils.Cfg.ServiceSettings.EnableIncomingWebhooks = true + utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = true + defer func() { + utils.Cfg.ServiceSettings.EnableIncomingWebhooks = incomingWasEnabled + utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = outgoingWasEnabled + }() + + channel, err := CreateChannel(&model.Channel{DisplayName: "deletion-test", Name: "deletion-test", Type: model.CHANNEL_OPEN, TeamId: th.BasicTeam.Id}, false) + if err != nil { + t.Fatal(err.Error()) + } + defer func() { + PermanentDeleteChannel(channel) + }() + + incoming, err := CreateIncomingWebhookForChannel(th.BasicUser.Id, channel, &model.IncomingWebhook{ChannelId: channel.Id}) + if err != nil { + t.Fatal(err.Error()) + } + defer DeleteIncomingWebhook(incoming.Id) + + if incoming, err = GetIncomingWebhook(incoming.Id); incoming == nil || err != nil { + t.Fatal("unable to get new incoming webhook") + } + + outgoing, err := CreateOutgoingWebhook(&model.OutgoingWebhook{ + ChannelId: channel.Id, + TeamId: channel.TeamId, + CreatorId: th.BasicUser.Id, + CallbackURLs: []string{"http://foo"}, + }) + if err != nil { + t.Fatal(err.Error()) + } + defer DeleteOutgoingWebhook(outgoing.Id) + + if outgoing, err = GetOutgoingWebhook(outgoing.Id); outgoing == nil || err != nil { + t.Fatal("unable to get new outgoing webhook") + } + + if err := PermanentDeleteChannel(channel); err != nil { + t.Fatal(err.Error()) + } + + if incoming, err = GetIncomingWebhook(incoming.Id); incoming != nil || err == nil { + t.Error("incoming webhook wasn't deleted") + } + + if outgoing, err = GetOutgoingWebhook(outgoing.Id); outgoing != nil || err == nil { + t.Error("outgoing webhook wasn't deleted") + } +} diff --git a/app/team.go b/app/team.go index bff448f7c..e4a71d7d5 100644 --- a/app/team.go +++ b/app/team.go @@ -638,7 +638,7 @@ func InviteNewUsersToTeam(emailList []string, teamId, senderId string) *model.Ap var invalidEmailList []string for _, email := range emailList { - if ! isTeamEmailAddressAllowed(email) { + if !isTeamEmailAddressAllowed(email) { invalidEmailList = append(invalidEmailList, email) } } @@ -747,6 +747,10 @@ func PermanentDeleteTeam(team *model.Team) *model.AppError { return result.Err } + if result := <-Srv.Store.Command().PermanentDeleteByTeam(team.Id); result.Err != nil { + return result.Err + } + if result := <-Srv.Store.Team().PermanentDelete(team.Id); result.Err != nil { return result.Err } diff --git a/app/team_test.go b/app/team_test.go index f2356d562..a410d6652 100644 --- a/app/team_test.go +++ b/app/team_test.go @@ -112,3 +112,44 @@ func TestAddUserToTeamByTeamId(t *testing.T) { t.Fatal("Should add user to the team") } } + +func TestPermanentDeleteTeam(t *testing.T) { + th := Setup().InitBasic() + + team, err := CreateTeam(&model.Team{ + DisplayName: "deletion-test", + Name: "deletion-test", + Email: "foo@foo.com", + Type: model.TEAM_OPEN, + }) + if err != nil { + t.Fatal(err.Error()) + } + defer func() { + PermanentDeleteTeam(team) + }() + + command, err := CreateCommand(&model.Command{ + CreatorId: th.BasicUser.Id, + TeamId: team.Id, + Trigger: "foo", + URL: "http://foo", + Method: model.COMMAND_METHOD_POST, + }) + if err != nil { + t.Fatal(err.Error()) + } + defer DeleteCommand(command.Id) + + if command, err = GetCommand(command.Id); command == nil || err != nil { + t.Fatal("unable to get new command") + } + + if err := PermanentDeleteTeam(team); err != nil { + t.Fatal(err.Error()) + } + + if command, err = GetCommand(command.Id); command != nil || err == nil { + t.Fatal("command wasn't deleted") + } +} -- cgit v1.2.3-1-g7c22