summaryrefslogtreecommitdiffstats
path: root/api4/channel.go
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-03-27 20:41:40 +0900
committerenahum <nahumhbl@gmail.com>2017-03-27 08:41:40 -0300
commit01aaccb34080ede234602d1ca9acee8373b8560f (patch)
treeaac605bdc35f8a2f1a2761c7f753d5e9f66a33ec /api4/channel.go
parent720ee81113ac7a7dd062271c3d6cdf58ce8e044a (diff)
downloadchat-01aaccb34080ede234602d1ca9acee8373b8560f.tar.gz
chat-01aaccb34080ede234602d1ca9acee8373b8560f.tar.bz2
chat-01aaccb34080ede234602d1ca9acee8373b8560f.zip
APIv4 post /channels/ids (#5845)
* APIv4 post /channels/ids * updated enpoint as /teams/{team_id}/channels/ids
Diffstat (limited to 'api4/channel.go')
-rw-r--r--api4/channel.go37
1 files changed, 35 insertions, 2 deletions
diff --git a/api4/channel.go b/api4/channel.go
index a19f7d858..278bf1d2e 100644
--- a/api4/channel.go
+++ b/api4/channel.go
@@ -19,8 +19,9 @@ func InitChannel() {
BaseRoutes.Channels.Handle("/direct", ApiSessionRequired(createDirectChannel)).Methods("POST")
BaseRoutes.Channels.Handle("/members/{user_id:[A-Za-z0-9]+}/view", ApiSessionRequired(viewChannel)).Methods("POST")
- BaseRoutes.Team.Handle("/channels", ApiSessionRequired(getPublicChannelsForTeam)).Methods("GET")
- BaseRoutes.Team.Handle("/channels/search", ApiSessionRequired(searchChannelsForTeam)).Methods("POST")
+ BaseRoutes.ChannelsForTeam.Handle("", ApiSessionRequired(getPublicChannelsForTeam)).Methods("GET")
+ BaseRoutes.ChannelsForTeam.Handle("/ids", ApiSessionRequired(getPublicChannelsByIdsForTeam)).Methods("POST")
+ BaseRoutes.ChannelsForTeam.Handle("/search", ApiSessionRequired(searchChannelsForTeam)).Methods("POST")
BaseRoutes.User.Handle("/teams/{team_id:[A-Za-z0-9]+}/channels", ApiSessionRequired(getChannelsForTeamForUser)).Methods("GET")
BaseRoutes.Channel.Handle("", ApiSessionRequired(getChannel)).Methods("GET")
@@ -322,6 +323,38 @@ func getPublicChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request
}
}
+func getPublicChannelsByIdsForTeam(c *Context, w http.ResponseWriter, r *http.Request) {
+ c.RequireTeamId()
+ if c.Err != nil {
+ return
+ }
+
+ channelIds := model.ArrayFromJson(r.Body)
+ if len(channelIds) == 0 {
+ c.SetInvalidParam("channel_ids")
+ return
+ }
+
+ for _, cid := range channelIds {
+ if len(cid) != 26 {
+ c.SetInvalidParam("channel_id")
+ return
+ }
+ }
+
+ if !app.SessionHasPermissionToTeam(c.Session, c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
+ c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
+ return
+ }
+
+ if channels, err := app.GetPublicChannelsByIdsForTeam(c.Params.TeamId, channelIds); err != nil {
+ c.Err = err
+ return
+ } else {
+ w.Write([]byte(channels.ToJson()))
+ }
+}
+
func getChannelsForTeamForUser(c *Context, w http.ResponseWriter, r *http.Request) {
c.RequireUserId().RequireTeamId()
if c.Err != nil {