diff options
author | Saturnino Abril <saturnino.abril@gmail.com> | 2017-03-13 21:26:51 +0900 |
---|---|---|
committer | George Goldberg <george@gberg.me> | 2017-03-13 12:26:51 +0000 |
commit | 8731465957ba41c1f828285e19ee3bb234e2ef58 (patch) | |
tree | 4051efe2fb0ec981e7004c32cf79d3592471fdfb /api4/channel.go | |
parent | 3559fb7959cf008b038239f2e7c43e604c44cd31 (diff) | |
download | chat-8731465957ba41c1f828285e19ee3bb234e2ef58.tar.gz chat-8731465957ba41c1f828285e19ee3bb234e2ef58.tar.bz2 chat-8731465957ba41c1f828285e19ee3bb234e2ef58.zip |
Endpoint for APIv4: GET /team/{team_id}/channels (#5681)
Diffstat (limited to 'api4/channel.go')
-rw-r--r-- | api4/channel.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/api4/channel.go b/api4/channel.go index 8be522484..d86e54039 100644 --- a/api4/channel.go +++ b/api4/channel.go @@ -18,6 +18,8 @@ func InitChannel() { BaseRoutes.Channels.Handle("", ApiSessionRequired(createChannel)).Methods("POST") BaseRoutes.Channels.Handle("/direct", ApiSessionRequired(createDirectChannel)).Methods("POST") + BaseRoutes.Team.Handle("/channels", ApiSessionRequired(getPublicChannelsForTeam)).Methods("GET") + BaseRoutes.Channel.Handle("", ApiSessionRequired(getChannel)).Methods("GET") BaseRoutes.ChannelByName.Handle("", ApiSessionRequired(getChannelByName)).Methods("GET") BaseRoutes.ChannelByNameForTeamName.Handle("", ApiSessionRequired(getChannelByNameForTeamName)).Methods("GET") @@ -115,6 +117,26 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) { } } +func getPublicChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) { + c.RequireTeamId() + if c.Err != nil { + return + } + + if !app.SessionHasPermissionToTeam(c.Session, c.Params.TeamId, model.PERMISSION_LIST_TEAM_CHANNELS) { + c.SetPermissionError(model.PERMISSION_LIST_TEAM_CHANNELS) + return + } + + if channels, err := app.GetPublicChannelsForTeam(c.Params.TeamId, c.Params.Page, c.Params.PerPage); err != nil { + c.Err = err + return + } else { + w.Write([]byte(channels.ToJson())) + return + } +} + func getChannelByName(c *Context, w http.ResponseWriter, r *http.Request) { c.RequireTeamId().RequireChannelName() if c.Err != nil { |