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>
Этот коммит содержится в:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Ссылка в новой задаче
Block a user