Commit 594544f7 authored by Harrison Healey's avatar Harrison Healey
Browse files

MM-27258 Cannot update categories with deleted channels (#15109)

parent 0fa35c23
......@@ -2046,8 +2046,10 @@ func updateCategoriesForTeamForUser(c *Context, w http.ResponseWriter, r *http.R
w.Write(model.SidebarCategoriesWithChannelsToJson(categories))
}
// validateUserChannels confirms that the given user is a member of the given channel IDs. Returns an error if the user
// is not a member of any channel or nil if the user is a member of each channel.
func validateUserChannels(operationName string, c *Context, teamId, userId string, channelIDs []string) *model.AppError {
channels, err := c.App.GetChannelsForUser(teamId, userId, false)
channels, err := c.App.GetChannelsForUser(teamId, userId, true)
if err != nil {
return model.NewAppError("Api4."+operationName, "api.invalid_channel", nil, err.Error(), http.StatusBadRequest)
}
......
......@@ -3984,10 +3984,6 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
Channels: []string{channelsCategory.Channels[1], channelsCategory.Channels[0], channelsCategory.Channels[4], channelsCategory.Channels[3], channelsCategory.Channels[2]},
}
t.Log("UserId=" + th.BasicUser.Id)
t.Log("TeamId=" + th.BasicTeam.Id)
t.Log("category=" + channelsCategory.Id)
received, resp := th.Client.UpdateSidebarCategoryForTeamForUser(th.BasicUser.Id, th.BasicTeam.Id, channelsCategory.Id, updatedCategory)
assert.Nil(t, resp.Error)
assert.Equal(t, channelsCategory.Id, received.Id)
......@@ -4064,4 +4060,33 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
assert.Equal(t, customCategory.Id, received.Id)
assert.Equal(t, updatedCategory.DisplayName, received.DisplayName)
})
t.Run("should update the channel order of the category even if it contains archived channels", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
categories, resp := th.Client.GetSidebarCategoriesForTeamForUser(th.BasicUser.Id, th.BasicTeam.Id, "")
require.Nil(t, resp.Error)
require.Len(t, categories.Categories, 3)
require.Len(t, categories.Order, 3)
channelsCategory := categories.Categories[1]
require.Equal(t, model.SidebarCategoryChannels, channelsCategory.Type)
require.Len(t, channelsCategory.Channels, 5) // Town Square, Off Topic, and the 3 channels created by InitBasic
// Delete one of the channels
_, resp = th.Client.DeleteChannel(th.BasicChannel.Id)
require.Nil(t, resp.Error)
// Should still be able to reorder the channels
updatedCategory := &model.SidebarCategoryWithChannels{
SidebarCategory: channelsCategory.SidebarCategory,
Channels: []string{channelsCategory.Channels[1], channelsCategory.Channels[0], channelsCategory.Channels[4], channelsCategory.Channels[3], channelsCategory.Channels[2]},
}
received, resp := th.Client.UpdateSidebarCategoryForTeamForUser(th.BasicUser.Id, th.BasicTeam.Id, channelsCategory.Id, updatedCategory)
require.Nil(t, resp.Error)
assert.Equal(t, channelsCategory.Id, received.Id)
assert.Equal(t, updatedCategory.Channels, received.Channels)
})
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment