make cli team / channel delete operations also delete webhooks and slash commands (#7028)
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
0f786a42d3
Коммит
72f61ab96a
@@ -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
|
||||
}
|
||||
|
||||
66
app/channel_test.go
Обычный файл
66
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")
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user