diff --git a/api4/channel.go b/api4/channel.go index f228140fbf..d4c504ba09 100644 --- a/api4/channel.go +++ b/api4/channel.go @@ -338,6 +338,13 @@ func patchChannel(c *Context, w http.ResponseWriter, r *http.Request) { return } + if oldChannel.Name == model.DefaultChannelName { + if *patch.Name != "" && *patch.Name != oldChannel.Name { + c.Err = model.NewAppError("patchChannel", "api.channel.update_channel.tried.app_error", map[string]interface{}{"Channel": model.DefaultChannelName}, "", http.StatusBadRequest) + return + } + } + rchannel, appErr := c.App.PatchChannel(c.AppContext, oldChannel, patch, c.AppContext.Session().UserId) if appErr != nil { c.Err = appErr diff --git a/api4/channel_test.go b/api4/channel_test.go index 573eb0d850..5741615bf5 100644 --- a/api4/channel_test.go +++ b/api4/channel_test.go @@ -182,8 +182,14 @@ func TestUpdateChannel(t *testing.T) { require.Equal(t, private.Header, newPrivateChannel.Header, "Update failed for Header in private channel") require.Equal(t, private.Purpose, newPrivateChannel.Purpose, "Update failed for Purpose in private channel") - // Test that changing the type fails and returns error + //Test updating default channel's name and returns error + defaultChannel, _ := th.App.GetChannelByName(model.DefaultChannelName, team.Id, false) + defaultChannel.Name = "testing" + _, resp, err = client.UpdateChannel(defaultChannel) + require.Error(t, err) + CheckBadRequestStatus(t, resp) + // Test that changing the type fails and returns error private.Type = model.ChannelTypeOpen _, resp, err = client.UpdateChannel(private) require.Error(t, err) @@ -250,6 +256,7 @@ func TestPatchChannel(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() client := th.Client + team := th.BasicTeam patch := &model.ChannelPatch{ Name: new(string), @@ -277,6 +284,16 @@ func TestPatchChannel(t *testing.T) { require.Equal(t, oldName, channel.Name, "should not have updated") + //Test updating default channel's name and returns error + defaultChannel, _ := th.App.GetChannelByName(model.DefaultChannelName, team.Id, false) + defaultChannelPatch := &model.ChannelPatch{ + Name: new(string), + } + *defaultChannelPatch.Name = "testing" + _, resp, err := client.PatchChannel(defaultChannel.Id, defaultChannelPatch) + require.Error(t, err) + CheckBadRequestStatus(t, resp) + // Test GroupConstrained flag patch.GroupConstrained = model.NewBool(true) rchannel, resp, err := client.PatchChannel(th.BasicChannel.Id, patch)