Disallow changing type when updating a channel (#13387)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e2e2ad48ce
Коммит
c06b2d28c3
@@ -143,8 +143,13 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if len(channel.Type) > 0 && channel.Type != oldChannel.Type {
|
||||
c.Err = model.NewAppError("updateChannel", "api.channel.update_channel.typechange.app_error", nil, "", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if oldChannel.Name == model.DEFAULT_CHANNEL {
|
||||
if (len(channel.Name) > 0 && channel.Name != oldChannel.Name) || (len(channel.Type) > 0 && channel.Type != oldChannel.Type) {
|
||||
if len(channel.Name) > 0 && channel.Name != oldChannel.Name {
|
||||
c.Err = model.NewAppError("updateChannel", "api.channel.update_channel.tried.app_error", map[string]interface{}{"Channel": model.DEFAULT_CHANNEL}, "", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -163,10 +168,6 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
oldChannel.Name = channel.Name
|
||||
}
|
||||
|
||||
if len(channel.Type) > 0 {
|
||||
oldChannel.Type = channel.Type
|
||||
}
|
||||
|
||||
if channel.GroupConstrained != nil {
|
||||
oldChannel.GroupConstrained = channel.GroupConstrained
|
||||
}
|
||||
|
||||
@@ -169,6 +169,18 @@ 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
|
||||
|
||||
private.Type = model.CHANNEL_OPEN
|
||||
newPrivateChannel, resp = Client.UpdateChannel(private)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
// Test that keeping the same type succeeds
|
||||
|
||||
private.Type = model.CHANNEL_PRIVATE
|
||||
newPrivateChannel, resp = Client.UpdateChannel(private)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
//Non existing channel
|
||||
channel1 := &model.Channel{DisplayName: "Test API Name for apiv4", Name: GenerateTestChannelName(), Type: model.CHANNEL_OPEN, TeamId: team.Id}
|
||||
_, resp = Client.UpdateChannel(channel1)
|
||||
|
||||
Ссылка в новой задаче
Block a user