From 2d7cd02abcd62ffd60fe3c6e16e5189169de349e Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Tue, 26 Jun 2018 16:46:58 -0400 Subject: MM-10833: send down computed channel props (#8953) * MM-10833: send down computed channel props This allows channel headers to reference channel mentions for a client that doesn't already know about the channels in question. We intentionally don't send down the props for the autocomplete and search endpoints since they aren't used in that context, and would add unnecessary overhead. * update channel props on patch * revert to treating channel purpose as plaintext --- api4/channel.go | 107 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 83 insertions(+), 24 deletions(-) (limited to 'api4') diff --git a/api4/channel.go b/api4/channel.go index b2c920ddb..cb9112677 100644 --- a/api4/channel.go +++ b/api4/channel.go @@ -209,13 +209,20 @@ func patchChannel(c *Context, w http.ResponseWriter, r *http.Request) { return } - if rchannel, err := c.App.PatchChannel(oldChannel, patch, c.Session.UserId); err != nil { + rchannel, err := c.App.PatchChannel(oldChannel, patch, c.Session.UserId) + if err != nil { + c.Err = err + return + } + + err = c.App.FillInChannelProps(rchannel) + if err != nil { c.Err = err return - } else { - c.LogAudit("") - w.Write([]byte(rchannel.ToJson())) } + + c.LogAudit("") + w.Write([]byte(rchannel.ToJson())) } func restoreChannel(c *Context, w http.ResponseWriter, r *http.Request) { @@ -361,6 +368,12 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) { } } + err = c.App.FillInChannelProps(channel) + if err != nil { + c.Err = err + return + } + w.Write([]byte(channel.ToJson())) } @@ -444,13 +457,19 @@ func getPublicChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request return } - if channels, err := c.App.GetPublicChannelsForTeam(c.Params.TeamId, c.Params.Page*c.Params.PerPage, c.Params.PerPage); err != nil { + channels, err := c.App.GetPublicChannelsForTeam(c.Params.TeamId, c.Params.Page*c.Params.PerPage, c.Params.PerPage) + if err != nil { c.Err = err return - } else { - w.Write([]byte(channels.ToJson())) + } + + err = c.App.FillInChannelsProps(channels) + if err != nil { + c.Err = err return } + + w.Write([]byte(channels.ToJson())) } func getDeletedChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) { @@ -464,13 +483,19 @@ func getDeletedChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Reques return } - if channels, err := c.App.GetDeletedChannels(c.Params.TeamId, c.Params.Page*c.Params.PerPage, c.Params.PerPage); err != nil { + channels, err := c.App.GetDeletedChannels(c.Params.TeamId, c.Params.Page*c.Params.PerPage, c.Params.PerPage) + if err != nil { c.Err = err return - } else { - w.Write([]byte(channels.ToJson())) + } + + err = c.App.FillInChannelsProps(channels) + if err != nil { + c.Err = err return } + + w.Write([]byte(channels.ToJson())) } func getPublicChannelsByIdsForTeam(c *Context, w http.ResponseWriter, r *http.Request) { @@ -497,12 +522,19 @@ func getPublicChannelsByIdsForTeam(c *Context, w http.ResponseWriter, r *http.Re return } - if channels, err := c.App.GetPublicChannelsByIdsForTeam(c.Params.TeamId, channelIds); err != nil { + channels, err := c.App.GetPublicChannelsByIdsForTeam(c.Params.TeamId, channelIds) + if err != nil { + c.Err = err + return + } + + err = c.App.FillInChannelsProps(channels) + if err != nil { c.Err = err return - } else { - w.Write([]byte(channels.ToJson())) } + + w.Write([]byte(channels.ToJson())) } func getChannelsForTeamForUser(c *Context, w http.ResponseWriter, r *http.Request) { @@ -521,15 +553,24 @@ func getChannelsForTeamForUser(c *Context, w http.ResponseWriter, r *http.Reques return } - if channels, err := c.App.GetChannelsForUser(c.Params.TeamId, c.Params.UserId); err != nil { + channels, err := c.App.GetChannelsForUser(c.Params.TeamId, c.Params.UserId) + if err != nil { c.Err = err return - } else if c.HandleEtag(channels.Etag(), "Get Channels", w, r) { + } + + if c.HandleEtag(channels.Etag(), "Get Channels", w, r) { return - } else { - w.Header().Set(model.HEADER_ETAG_SERVER, channels.Etag()) - w.Write([]byte(channels.ToJson())) } + + err = c.App.FillInChannelsProps(channels) + if err != nil { + c.Err = err + return + } + + w.Header().Set(model.HEADER_ETAG_SERVER, channels.Etag()) + w.Write([]byte(channels.ToJson())) } func autocompleteChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) { @@ -545,12 +586,15 @@ func autocompleteChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Requ name := r.URL.Query().Get("name") - if channels, err := c.App.AutocompleteChannels(c.Params.TeamId, name); err != nil { + channels, err := c.App.AutocompleteChannels(c.Params.TeamId, name) + if err != nil { c.Err = err return - } else { - w.Write([]byte(channels.ToJson())) } + + // Don't fill in channels props, since unused by client and potentially expensive. + + w.Write([]byte(channels.ToJson())) } func searchChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) { @@ -570,12 +614,15 @@ func searchChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) { return } - if channels, err := c.App.SearchChannels(c.Params.TeamId, props.Term); err != nil { + channels, err := c.App.SearchChannels(c.Params.TeamId, props.Term) + if err != nil { c.Err = err return - } else { - w.Write([]byte(channels.ToJson())) } + + // Don't fill in channels props, since unused by client and potentially expensive. + + w.Write([]byte(channels.ToJson())) } func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) { @@ -638,6 +685,12 @@ func getChannelByName(c *Context, w http.ResponseWriter, r *http.Request) { } } + err = c.App.FillInChannelProps(channel) + if err != nil { + c.Err = err + return + } + w.Write([]byte(channel.ToJson())) } @@ -660,6 +713,12 @@ func getChannelByNameForTeamName(c *Context, w http.ResponseWriter, r *http.Requ return } + err = c.App.FillInChannelProps(channel) + if err != nil { + c.Err = err + return + } + w.Write([]byte(channel.ToJson())) } -- cgit v1.2.3-1-g7c22 From f17c15c9d83e42e46adb8e8c1fb9706b22fe6f50 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Wed, 27 Jun 2018 01:23:13 +0100 Subject: Simplify oauth (#8972) * Remove unused OauthProvider::GetIdentifier Signed-off-by: Emil Velikov * Reuse gitlab's getAuthData() instead of open-coding it Signed-off-by: Emil Velikov * Remove OauthProvider::GetAuthDataFromJson interface The data is already available via GetUserFromJson().AuthData Signed-off-by: Emil Velikov --- api4/oauth_test.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'api4') diff --git a/api4/oauth_test.go b/api4/oauth_test.go index 8cf20ca5e..6bbd99ccc 100644 --- a/api4/oauth_test.go +++ b/api4/oauth_test.go @@ -1127,15 +1127,8 @@ func closeBody(r *http.Response) { type MattermostTestProvider struct { } -func (m *MattermostTestProvider) GetIdentifier() string { - return model.SERVICE_GITLAB -} - func (m *MattermostTestProvider) GetUserFromJson(data io.Reader) *model.User { - return model.UserFromJson(data) -} - -func (m *MattermostTestProvider) GetAuthDataFromJson(data io.Reader) string { - authData := model.UserFromJson(data) - return authData.Email + user := model.UserFromJson(data) + user.AuthData = &user.Email + return user } -- cgit v1.2.3-1-g7c22