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>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
dea705969c
Коммит
553af3a694
@@ -13,6 +13,7 @@ import (
|
|||||||
func (api *API) InitChannelLocal() {
|
func (api *API) InitChannelLocal() {
|
||||||
api.BaseRoutes.Channels.Handle("", api.ApiLocal(getAllChannels)).Methods("GET")
|
api.BaseRoutes.Channels.Handle("", api.ApiLocal(getAllChannels)).Methods("GET")
|
||||||
api.BaseRoutes.Channels.Handle("", api.ApiLocal(localCreateChannel)).Methods("POST")
|
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.ChannelMember.Handle("", api.ApiLocal(getChannelMember)).Methods("GET")
|
||||||
api.BaseRoutes.ChannelMembers.Handle("", api.ApiLocal(getChannelMembers)).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) {
|
func TestDeleteGroupChannel(t *testing.T) {
|
||||||
th := Setup(t).InitBasic()
|
th := Setup(t).InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
Client := th.Client
|
|
||||||
user := th.BasicUser
|
user := th.BasicUser
|
||||||
user2 := th.BasicUser2
|
user2 := th.BasicUser2
|
||||||
user3 := th.CreateUser()
|
user3 := th.CreateUser()
|
||||||
|
|
||||||
userIds := []string{user.Id, user2.Id, user3.Id}
|
userIds := []string{user.Id, user2.Id, user3.Id}
|
||||||
|
|
||||||
rgc, resp := Client.CreateGroupChannel(userIds)
|
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||||
CheckNoError(t, resp)
|
rgc, resp := th.Client.CreateGroupChannel(userIds)
|
||||||
CheckCreatedStatus(t, resp)
|
CheckNoError(t, resp)
|
||||||
require.NotNil(t, rgc, "should have created a group channel")
|
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) {
|
func TestGetChannel(t *testing.T) {
|
||||||
@@ -1241,84 +1242,90 @@ func TestSearchGroupChannels(t *testing.T) {
|
|||||||
func TestDeleteChannel(t *testing.T) {
|
func TestDeleteChannel(t *testing.T) {
|
||||||
th := Setup(t).InitBasic()
|
th := Setup(t).InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
Client := th.Client
|
c := th.Client
|
||||||
team := th.BasicTeam
|
team := th.BasicTeam
|
||||||
user := th.BasicUser
|
user := th.BasicUser
|
||||||
user2 := th.BasicUser2
|
user2 := th.BasicUser2
|
||||||
|
|
||||||
// successful delete of public channel
|
// successful delete of public channel
|
||||||
publicChannel1 := th.CreatePublicChannel()
|
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||||
pass, resp := Client.DeleteChannel(publicChannel1.Id)
|
publicChannel1 := th.CreatePublicChannel()
|
||||||
CheckNoError(t, resp)
|
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)
|
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.")
|
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"}
|
post1 := &model.Post{ChannelId: publicChannel1.Id, Message: "a" + GenerateTestId() + "a"}
|
||||||
_, resp = Client.CreatePost(post1)
|
_, resp = client.CreatePost(post1)
|
||||||
require.NotNil(t, resp, "expected response to not be nil")
|
require.NotNil(t, resp, "expected response to not be nil")
|
||||||
|
|
||||||
// successful delete of private channel
|
// successful delete of private channel
|
||||||
privateChannel2 := th.CreatePrivateChannel()
|
privateChannel2 := th.CreatePrivateChannel()
|
||||||
_, resp = Client.DeleteChannel(privateChannel2.Id)
|
_, resp = client.DeleteChannel(privateChannel2.Id)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
// successful delete of channel with multiple members
|
// successful delete of channel with multiple members
|
||||||
publicChannel3 := th.CreatePublicChannel()
|
publicChannel3 := th.CreatePublicChannel()
|
||||||
th.App.AddUserToChannel(user, publicChannel3)
|
th.App.AddUserToChannel(user, publicChannel3)
|
||||||
th.App.AddUserToChannel(user2, publicChannel3)
|
th.App.AddUserToChannel(user2, publicChannel3)
|
||||||
_, resp = Client.DeleteChannel(publicChannel3.Id)
|
_, resp = client.DeleteChannel(publicChannel3.Id)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
// default channel cannot be deleted.
|
// default channel cannot be deleted.
|
||||||
defaultChannel, _ := th.App.GetChannelByName(model.DEFAULT_CHANNEL, team.Id, false)
|
defaultChannel, _ := th.App.GetChannelByName(model.DEFAULT_CHANNEL, team.Id, false)
|
||||||
pass, resp = Client.DeleteChannel(defaultChannel.Id)
|
pass, resp = client.DeleteChannel(defaultChannel.Id)
|
||||||
CheckBadRequestStatus(t, resp)
|
CheckBadRequestStatus(t, resp)
|
||||||
require.False(t, pass, "should have failed")
|
require.False(t, pass, "should have failed")
|
||||||
|
|
||||||
// check system admin can delete a channel without any appropriate team or channel membership.
|
// check system admin can delete a channel without any appropriate team or channel membership.
|
||||||
sdTeam := th.CreateTeamWithClient(Client)
|
sdTeam := th.CreateTeamWithClient(c)
|
||||||
sdPublicChannel := &model.Channel{
|
sdPublicChannel := &model.Channel{
|
||||||
DisplayName: "dn_" + model.NewId(),
|
DisplayName: "dn_" + model.NewId(),
|
||||||
Name: GenerateTestChannelName(),
|
Name: GenerateTestChannelName(),
|
||||||
Type: model.CHANNEL_OPEN,
|
Type: model.CHANNEL_OPEN,
|
||||||
TeamId: sdTeam.Id,
|
TeamId: sdTeam.Id,
|
||||||
}
|
}
|
||||||
sdPublicChannel, resp = Client.CreateChannel(sdPublicChannel)
|
sdPublicChannel, resp = c.CreateChannel(sdPublicChannel)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
_, resp = th.SystemAdminClient.DeleteChannel(sdPublicChannel.Id)
|
_, resp = client.DeleteChannel(sdPublicChannel.Id)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
sdPrivateChannel := &model.Channel{
|
sdPrivateChannel := &model.Channel{
|
||||||
DisplayName: "dn_" + model.NewId(),
|
DisplayName: "dn_" + model.NewId(),
|
||||||
Name: GenerateTestChannelName(),
|
Name: GenerateTestChannelName(),
|
||||||
Type: model.CHANNEL_PRIVATE,
|
Type: model.CHANNEL_PRIVATE,
|
||||||
TeamId: sdTeam.Id,
|
TeamId: sdTeam.Id,
|
||||||
}
|
}
|
||||||
sdPrivateChannel, resp = Client.CreateChannel(sdPrivateChannel)
|
sdPrivateChannel, resp = c.CreateChannel(sdPrivateChannel)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
_, resp = th.SystemAdminClient.DeleteChannel(sdPrivateChannel.Id)
|
_, resp = client.DeleteChannel(sdPrivateChannel.Id)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
})
|
||||||
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
|
|
||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
publicChannel5 := th.CreatePublicChannel()
|
publicChannel5 := th.CreatePublicChannel()
|
||||||
Client.Logout()
|
c.Logout()
|
||||||
|
|
||||||
Client.Login(user.Id, user.Password)
|
c.Login(user.Id, user.Password)
|
||||||
_, resp = Client.DeleteChannel(publicChannel5.Id)
|
_, resp := c.DeleteChannel(publicChannel5.Id)
|
||||||
CheckUnauthorizedStatus(t, resp)
|
CheckUnauthorizedStatus(t, resp)
|
||||||
|
|
||||||
_, resp = Client.DeleteChannel("junk")
|
_, resp = c.DeleteChannel("junk")
|
||||||
CheckUnauthorizedStatus(t, resp)
|
CheckUnauthorizedStatus(t, resp)
|
||||||
|
|
||||||
Client.Logout()
|
c.Logout()
|
||||||
_, resp = Client.DeleteChannel(GenerateTestId())
|
_, resp = c.DeleteChannel(GenerateTestId())
|
||||||
CheckUnauthorizedStatus(t, resp)
|
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) {
|
func TestDeleteChannel2(t *testing.T) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user