MM-25563: Add endpoint to fetch only archived channels (#15031)

Automatic Merge
Этот коммит содержится в:
Agniva De Sarker
2020-07-27 17:01:39 +05:30
коммит произвёл GitHub
родитель 29c8b58fc7
Коммит 77f7a97bee
18 изменённых файлов: 166 добавлений и 49 удалений

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

@@ -854,7 +854,17 @@ func getChannelsForTeamForUser(c *Context, w http.ResponseWriter, r *http.Reques
return
}
channels, err := c.App.GetChannelsForUser(c.Params.TeamId, c.Params.UserId, c.Params.IncludeDeleted)
query := r.URL.Query()
lastDeleteAt, nErr := strconv.Atoi(query.Get("last_delete_at"))
if nErr != nil {
lastDeleteAt = 0
}
if lastDeleteAt < 0 {
c.SetInvalidUrlParam("last_delete_at")
return
}
channels, err := c.App.GetChannelsForUser(c.Params.TeamId, c.Params.UserId, c.Params.IncludeDeleted, lastDeleteAt)
if err != nil {
c.Err = err
return
@@ -2047,7 +2057,7 @@ func updateCategoriesForTeamForUser(c *Context, w http.ResponseWriter, r *http.R
}
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, false, 0)
if err != nil {
return model.NewAppError("Api4."+operationName, "api.invalid_channel", nil, err.Error(), http.StatusBadRequest)
}

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

@@ -949,6 +949,18 @@ func TestGetChannelsForTeamForUser(t *testing.T) {
channels, resp = Client.GetChannelsForTeamForUser(th.BasicTeam.Id, th.BasicUser.Id, false, "")
CheckNoError(t, resp)
assert.Equal(t, 5, len(channels))
// Should return all channels including basicDeleted.
channels, resp = Client.GetChannelsForTeamForUser(th.BasicTeam.Id, th.BasicUser.Id, true, "")
CheckNoError(t, resp)
assert.Equal(t, 7, len(channels))
// Should stil return all channels including basicDeleted.
now := time.Now().Add(-time.Minute).Unix() * 1000
Client.GetChannelsForTeamAndUserWithLastDeleteAt(th.BasicTeam.Id, th.BasicUser.Id,
true, int(now), "")
CheckNoError(t, resp)
assert.Equal(t, 7, len(channels))
})
}