adding check for name change and new tests (#18531)

Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MacBook-Pro.local>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Ben Cooke
2021-10-29 13:46:50 -04:00
коммит произвёл GitHub
родитель bf589c2995
Коммит 3181a3765d
2 изменённых файлов: 25 добавлений и 1 удалений

Просмотреть файл

@@ -338,6 +338,13 @@ func patchChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return 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) rchannel, appErr := c.App.PatchChannel(c.AppContext, oldChannel, patch, c.AppContext.Session().UserId)
if appErr != nil { if appErr != nil {
c.Err = appErr c.Err = appErr

Просмотреть файл

@@ -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.Header, newPrivateChannel.Header, "Update failed for Header in private channel")
require.Equal(t, private.Purpose, newPrivateChannel.Purpose, "Update failed for Purpose 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 private.Type = model.ChannelTypeOpen
_, resp, err = client.UpdateChannel(private) _, resp, err = client.UpdateChannel(private)
require.Error(t, err) require.Error(t, err)
@@ -250,6 +256,7 @@ func TestPatchChannel(t *testing.T) {
th := Setup(t).InitBasic() th := Setup(t).InitBasic()
defer th.TearDown() defer th.TearDown()
client := th.Client client := th.Client
team := th.BasicTeam
patch := &model.ChannelPatch{ patch := &model.ChannelPatch{
Name: new(string), Name: new(string),
@@ -277,6 +284,16 @@ func TestPatchChannel(t *testing.T) {
require.Equal(t, oldName, channel.Name, "should not have updated") 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 // Test GroupConstrained flag
patch.GroupConstrained = model.NewBool(true) patch.GroupConstrained = model.NewBool(true)
rchannel, resp, err := client.PatchChannel(th.BasicChannel.Id, patch) rchannel, resp, err := client.PatchChannel(th.BasicChannel.Id, patch)