MM-13492 Allow empty channel in /channels/view (#10062)

* Allow empty channel in /channels/view

* Simplify if statement.
Этот коммит содержится в:
Christopher Speller
2019-01-07 14:07:41 -08:00
коммит произвёл GitHub
родитель dc175cc704
Коммит ca4dcf4404
2 изменённых файлов: 18 добавлений и 1 удалений

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

@@ -917,11 +917,22 @@ func viewChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
view := model.ChannelViewFromJson(r.Body)
if view == nil || !model.IsValidId(view.ChannelId) || (view.PrevChannelId != "" && !model.IsValidId(view.PrevChannelId)) {
if view == nil {
c.SetInvalidParam("channel_view")
return
}
// Validate view struct
// Check IDs are valid or blank. Blank IDs are used to denote focus loss or inital channel view.
if view.ChannelId != "" && !model.IsValidId(view.ChannelId) {
c.SetInvalidParam("channel_view.channel_id")
return
}
if view.PrevChannelId != "" && !model.IsValidId(view.PrevChannelId) {
c.SetInvalidParam("channel_view.prev_channel_id")
return
}
times, err := c.App.ViewChannel(view, c.Params.UserId, !c.App.Session.IsMobileApp())
if err != nil {
c.Err = err

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

@@ -1418,6 +1418,12 @@ func TestViewChannel(t *testing.T) {
_, resp = Client.ViewChannel(th.BasicUser.Id, view)
CheckBadRequestStatus(t, resp)
// All blank is OK we use it for clicking off of the browser.
view.PrevChannelId = ""
view.ChannelId = ""
_, resp = Client.ViewChannel(th.BasicUser.Id, view)
CheckNoError(t, resp)
view.PrevChannelId = ""
view.ChannelId = "junk"
_, resp = Client.ViewChannel(th.BasicUser.Id, view)