MM-11118: disallow deleting direct or group channels (#9054)
Этот коммит содержится в:
коммит произвёл
Carlos Tadeu Panato Junior
родитель
7c855c30db
Коммит
6b7a35b653
@@ -638,6 +638,11 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
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) {
|
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)
|
c.SetPermissionError(model.PERMISSION_DELETE_PUBLIC_CHANNEL)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/utils"
|
"github.com/mattermost/mattermost-server/utils"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateChannel(t *testing.T) {
|
func TestCreateChannel(t *testing.T) {
|
||||||
@@ -320,6 +321,23 @@ func TestCreateDirectChannel(t *testing.T) {
|
|||||||
CheckNoError(t, resp)
|
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) {
|
func TestCreateGroupChannel(t *testing.T) {
|
||||||
th := Setup().InitBasic().InitSystemAdmin()
|
th := Setup().InitBasic().InitSystemAdmin()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
@@ -392,6 +410,26 @@ func TestCreateGroupChannel(t *testing.T) {
|
|||||||
CheckNoError(t, resp)
|
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) {
|
func TestGetChannel(t *testing.T) {
|
||||||
th := Setup().InitBasic().InitSystemAdmin()
|
th := Setup().InitBasic().InitSystemAdmin()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|||||||
@@ -159,6 +159,10 @@
|
|||||||
"id": "api.channel.delete_channel.deleted.app_error",
|
"id": "api.channel.delete_channel.deleted.app_error",
|
||||||
"translation": "The channel has been archived or deleted"
|
"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",
|
"id": "api.channel.join_channel.already_deleted.app_error",
|
||||||
"translation": "Channel is already deleted"
|
"translation": "Channel is already deleted"
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user