mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-24597 Migrate API handler deleteChannel to be compatible with local mode (#14532)
Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> Co-authored-by: Miguel de la Cruz <miguel@mcrx.me> Co-authored-by: mattermod <mattermod@users.noreply.github.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
func (api *API) InitChannelLocal() {
|
||||
api.BaseRoutes.Channels.Handle("", api.ApiLocal(getAllChannels)).Methods("GET")
|
||||
api.BaseRoutes.Channels.Handle("", api.ApiLocal(localCreateChannel)).Methods("POST")
|
||||
api.BaseRoutes.Channel.Handle("", api.ApiLocal(deleteChannel)).Methods("DELETE")
|
||||
api.BaseRoutes.ChannelMember.Handle("", api.ApiLocal(getChannelMember)).Methods("GET")
|
||||
api.BaseRoutes.ChannelMembers.Handle("", api.ApiLocal(getChannelMembers)).Methods("GET")
|
||||
}
|
||||
|
||||
@@ -604,21 +604,22 @@ func TestCreateGroupChannelAsGuest(t *testing.T) {
|
||||
func TestDeleteGroupChannel(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
user := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
user3 := th.CreateUser()
|
||||
|
||||
userIds := []string{user.Id, user2.Id, user3.Id}
|
||||
|
||||
rgc, resp := Client.CreateGroupChannel(userIds)
|
||||
CheckNoError(t, resp)
|
||||
CheckCreatedStatus(t, resp)
|
||||
require.NotNil(t, rgc, "should have created a group channel")
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
rgc, resp := th.Client.CreateGroupChannel(userIds)
|
||||
CheckNoError(t, resp)
|
||||
CheckCreatedStatus(t, resp)
|
||||
require.NotNil(t, rgc, "should have created a group channel")
|
||||
deleted, resp := client.DeleteChannel(rgc.Id)
|
||||
CheckErrorMessage(t, resp, "api.channel.delete_channel.type.invalid")
|
||||
require.False(t, deleted, "should not have been able to delete group channel.")
|
||||
})
|
||||
|
||||
deleted, resp := Client.DeleteChannel(rgc.Id)
|
||||
CheckErrorMessage(t, resp, "api.channel.delete_channel.type.invalid")
|
||||
require.False(t, deleted, "should not have been able to delete group channel.")
|
||||
}
|
||||
|
||||
func TestGetChannel(t *testing.T) {
|
||||
@@ -1241,84 +1242,90 @@ func TestSearchGroupChannels(t *testing.T) {
|
||||
func TestDeleteChannel(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
c := th.Client
|
||||
team := th.BasicTeam
|
||||
user := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
|
||||
// successful delete of public channel
|
||||
publicChannel1 := th.CreatePublicChannel()
|
||||
pass, resp := Client.DeleteChannel(publicChannel1.Id)
|
||||
CheckNoError(t, resp)
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
publicChannel1 := th.CreatePublicChannel()
|
||||
pass, resp := client.DeleteChannel(publicChannel1.Id)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
require.True(t, pass, "should have passed")
|
||||
require.True(t, pass, "should have passed")
|
||||
|
||||
ch, err := th.App.GetChannel(publicChannel1.Id)
|
||||
require.True(t, err != nil || ch.DeleteAt != 0, "should have failed to get deleted channel, or returned one with a populated DeleteAt.")
|
||||
ch, err := th.App.GetChannel(publicChannel1.Id)
|
||||
require.True(t, err != nil || ch.DeleteAt != 0, "should have failed to get deleted channel, or returned one with a populated DeleteAt.")
|
||||
|
||||
post1 := &model.Post{ChannelId: publicChannel1.Id, Message: "a" + GenerateTestId() + "a"}
|
||||
_, resp = Client.CreatePost(post1)
|
||||
require.NotNil(t, resp, "expected response to not be nil")
|
||||
post1 := &model.Post{ChannelId: publicChannel1.Id, Message: "a" + GenerateTestId() + "a"}
|
||||
_, resp = client.CreatePost(post1)
|
||||
require.NotNil(t, resp, "expected response to not be nil")
|
||||
|
||||
// successful delete of private channel
|
||||
privateChannel2 := th.CreatePrivateChannel()
|
||||
_, resp = Client.DeleteChannel(privateChannel2.Id)
|
||||
CheckNoError(t, resp)
|
||||
// successful delete of private channel
|
||||
privateChannel2 := th.CreatePrivateChannel()
|
||||
_, resp = client.DeleteChannel(privateChannel2.Id)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
// successful delete of channel with multiple members
|
||||
publicChannel3 := th.CreatePublicChannel()
|
||||
th.App.AddUserToChannel(user, publicChannel3)
|
||||
th.App.AddUserToChannel(user2, publicChannel3)
|
||||
_, resp = Client.DeleteChannel(publicChannel3.Id)
|
||||
CheckNoError(t, resp)
|
||||
// successful delete of channel with multiple members
|
||||
publicChannel3 := th.CreatePublicChannel()
|
||||
th.App.AddUserToChannel(user, publicChannel3)
|
||||
th.App.AddUserToChannel(user2, publicChannel3)
|
||||
_, resp = client.DeleteChannel(publicChannel3.Id)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
// default channel cannot be deleted.
|
||||
defaultChannel, _ := th.App.GetChannelByName(model.DEFAULT_CHANNEL, team.Id, false)
|
||||
pass, resp = Client.DeleteChannel(defaultChannel.Id)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
require.False(t, pass, "should have failed")
|
||||
// default channel cannot be deleted.
|
||||
defaultChannel, _ := th.App.GetChannelByName(model.DEFAULT_CHANNEL, team.Id, false)
|
||||
pass, resp = client.DeleteChannel(defaultChannel.Id)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
require.False(t, pass, "should have failed")
|
||||
|
||||
// check system admin can delete a channel without any appropriate team or channel membership.
|
||||
sdTeam := th.CreateTeamWithClient(Client)
|
||||
sdPublicChannel := &model.Channel{
|
||||
DisplayName: "dn_" + model.NewId(),
|
||||
Name: GenerateTestChannelName(),
|
||||
Type: model.CHANNEL_OPEN,
|
||||
TeamId: sdTeam.Id,
|
||||
}
|
||||
sdPublicChannel, resp = Client.CreateChannel(sdPublicChannel)
|
||||
CheckNoError(t, resp)
|
||||
_, resp = th.SystemAdminClient.DeleteChannel(sdPublicChannel.Id)
|
||||
CheckNoError(t, resp)
|
||||
// check system admin can delete a channel without any appropriate team or channel membership.
|
||||
sdTeam := th.CreateTeamWithClient(c)
|
||||
sdPublicChannel := &model.Channel{
|
||||
DisplayName: "dn_" + model.NewId(),
|
||||
Name: GenerateTestChannelName(),
|
||||
Type: model.CHANNEL_OPEN,
|
||||
TeamId: sdTeam.Id,
|
||||
}
|
||||
sdPublicChannel, resp = c.CreateChannel(sdPublicChannel)
|
||||
CheckNoError(t, resp)
|
||||
_, resp = client.DeleteChannel(sdPublicChannel.Id)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
sdPrivateChannel := &model.Channel{
|
||||
DisplayName: "dn_" + model.NewId(),
|
||||
Name: GenerateTestChannelName(),
|
||||
Type: model.CHANNEL_PRIVATE,
|
||||
TeamId: sdTeam.Id,
|
||||
}
|
||||
sdPrivateChannel, resp = Client.CreateChannel(sdPrivateChannel)
|
||||
CheckNoError(t, resp)
|
||||
_, resp = th.SystemAdminClient.DeleteChannel(sdPrivateChannel.Id)
|
||||
CheckNoError(t, resp)
|
||||
sdPrivateChannel := &model.Channel{
|
||||
DisplayName: "dn_" + model.NewId(),
|
||||
Name: GenerateTestChannelName(),
|
||||
Type: model.CHANNEL_PRIVATE,
|
||||
TeamId: sdTeam.Id,
|
||||
}
|
||||
sdPrivateChannel, resp = c.CreateChannel(sdPrivateChannel)
|
||||
CheckNoError(t, resp)
|
||||
_, resp = client.DeleteChannel(sdPrivateChannel.Id)
|
||||
CheckNoError(t, resp)
|
||||
})
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
|
||||
th.LoginBasic()
|
||||
publicChannel5 := th.CreatePublicChannel()
|
||||
Client.Logout()
|
||||
th.LoginBasic()
|
||||
publicChannel5 := th.CreatePublicChannel()
|
||||
c.Logout()
|
||||
|
||||
Client.Login(user.Id, user.Password)
|
||||
_, resp = Client.DeleteChannel(publicChannel5.Id)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
c.Login(user.Id, user.Password)
|
||||
_, resp := c.DeleteChannel(publicChannel5.Id)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
_, resp = Client.DeleteChannel("junk")
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
_, resp = c.DeleteChannel("junk")
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
Client.Logout()
|
||||
_, resp = Client.DeleteChannel(GenerateTestId())
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
c.Logout()
|
||||
_, resp = c.DeleteChannel(GenerateTestId())
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
_, resp = client.DeleteChannel(publicChannel5.Id)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
})
|
||||
|
||||
_, resp = th.SystemAdminClient.DeleteChannel(publicChannel5.Id)
|
||||
CheckNoError(t, resp)
|
||||
}
|
||||
|
||||
func TestDeleteChannel2(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user