summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJesús Espino <jespinog@gmail.com>2018-10-02 19:33:52 +0200
committerGitHub <noreply@github.com>2018-10-02 19:33:52 +0200
commit2945e8a2b0ce9306bb049e65eb2410038e0fa18c (patch)
treecee7c4edc0a947496caec9bf9e6b84b09231d926 /app
parentc82a84ed765bd9c4d601b93201d93af92f6ee742 (diff)
downloadchat-2945e8a2b0ce9306bb049e65eb2410038e0fa18c.tar.gz
chat-2945e8a2b0ce9306bb049e65eb2410038e0fa18c.tar.bz2
chat-2945e8a2b0ce9306bb049e65eb2410038e0fa18c.zip
MM-10699: Disallow renaming direct and group message channels (#9518)
* MM-10699: Disallow renaming direct and group message channels * Replacing errors.New with errors.Wrapf
Diffstat (limited to 'app')
-rw-r--r--app/channel.go8
-rw-r--r--app/channel_test.go47
2 files changed, 48 insertions, 7 deletions
diff --git a/app/channel.go b/app/channel.go
index 30fc2c1b6..54b589175 100644
--- a/app/channel.go
+++ b/app/channel.go
@@ -163,6 +163,14 @@ func (a *App) CreateChannelWithUser(channel *model.Channel, userId string) (*mod
// RenameChannel is used to rename the channel Name and the DisplayName fields
func (a *App) RenameChannel(channel *model.Channel, newChannelName string, newDisplayName string) (*model.Channel, *model.AppError) {
+ if channel.Type == model.CHANNEL_DIRECT {
+ return nil, model.NewAppError("RenameChannel", "api.channel.rename_channel.cant_rename_direct_messages.app_error", nil, "", http.StatusBadRequest)
+ }
+
+ if channel.Type == model.CHANNEL_GROUP {
+ return nil, model.NewAppError("RenameChannel", "api.channel.rename_channel.cant_rename_group_messages.app_error", nil, "", http.StatusBadRequest)
+ }
+
channel.Name = newChannelName
if newDisplayName != "" {
channel.DisplayName = newDisplayName
diff --git a/app/channel_test.go b/app/channel_test.go
index 4dc8dce37..0501b9406 100644
--- a/app/channel_test.go
+++ b/app/channel_test.go
@@ -640,12 +640,45 @@ func TestRenameChannel(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
- channel := th.createChannel(th.BasicTeam, model.CHANNEL_OPEN)
-
- channel, err := th.App.RenameChannel(channel, "newchannelname", "New Display Name")
- if err != nil {
- t.Fatal("Failed to update channel name. Error: " + err.Error())
+ testCases := []struct {
+ Name string
+ Channel *model.Channel
+ ExpectError bool
+ ExpectedName string
+ ExpectedDisplayName string
+ }{
+ {
+ "Rename open channel",
+ th.createChannel(th.BasicTeam, model.CHANNEL_OPEN),
+ false,
+ "newchannelname",
+ "New Display Name",
+ },
+ {
+ "Fail on rename direct message channel",
+ th.CreateDmChannel(th.BasicUser2),
+ true,
+ "",
+ "",
+ },
+ {
+ "Fail on rename direct message channel",
+ th.CreateGroupChannel(th.BasicUser2, th.CreateUser()),
+ true,
+ "",
+ "",
+ },
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.Name, func(t *testing.T) {
+ channel, err := th.App.RenameChannel(tc.Channel, "newchannelname", "New Display Name")
+ if tc.ExpectError {
+ assert.NotNil(t, err)
+ } else {
+ assert.Equal(t, tc.ExpectedName, channel.Name)
+ assert.Equal(t, tc.ExpectedDisplayName, channel.DisplayName)
+ }
+ })
}
- assert.Equal(t, "newchannelname", channel.Name)
- assert.Equal(t, "New Display Name", channel.DisplayName)
}