Commit 6b7a35b6 authored by Jesse Hallam's avatar Jesse Hallam Committed by Carlos Tadeu Panato Junior

MM-11118: disallow deleting direct or group channels (#9054)

parent 7c855c30
......@@ -638,6 +638,11 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if channel.Type == model.CHANNEL_DIRECT || channel.Type == model.CHANNEL_GROUP {
c.Err = model.NewAppError("deleteChannel", "api.channel.delete_channel.type.invalid", nil, "", http.StatusBadRequest)
return
}
if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PUBLIC_CHANNEL) {
c.SetPermissionError(model.PERMISSION_DELETE_PUBLIC_CHANNEL)
return
......
......@@ -16,6 +16,7 @@ import (
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCreateChannel(t *testing.T) {
......@@ -320,6 +321,23 @@ func TestCreateDirectChannel(t *testing.T) {
CheckNoError(t, resp)
}
func TestDeleteDirectChannel(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer th.TearDown()
Client := th.Client
user := th.BasicUser
user2 := th.BasicUser2
rgc, resp := Client.CreateDirectChannel(user.Id, user2.Id)
CheckNoError(t, resp)
CheckCreatedStatus(t, resp)
require.NotNil(t, rgc, "should have created a direct 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 direct channel.")
}
func TestCreateGroupChannel(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer th.TearDown()
......@@ -392,6 +410,26 @@ func TestCreateGroupChannel(t *testing.T) {
CheckNoError(t, resp)
}
func TestDeleteGroupChannel(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
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")
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) {
th := Setup().InitBasic().InitSystemAdmin()
defer th.TearDown()
......
......@@ -159,6 +159,10 @@
"id": "api.channel.delete_channel.deleted.app_error",
"translation": "The channel has been archived or deleted"
},
{
"id": "api.channel.delete_channel.type.invalid",
"translation": "Cannot delete direct or group message channels"
},
{
"id": "api.channel.join_channel.already_deleted.app_error",
"translation": "Channel is already deleted"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment