summaryrefslogtreecommitdiffstats
path: root/api4/channel.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2018-02-06 17:25:53 +0000
committerGeorge Goldberg <george@gberg.me>2018-02-06 17:25:53 +0000
commit7941c30117efe1b957ac0458c2f0479e3824196d (patch)
treedf791632a9dc790a6f73dec53aae3ba919ebda63 /api4/channel.go
parente1cd64613591cf5a990442a69ebf188258bd0cb5 (diff)
parent034dbc07e3068c482e654b6a1a8fcbe4b01c44f3 (diff)
downloadchat-7941c30117efe1b957ac0458c2f0479e3824196d.tar.gz
chat-7941c30117efe1b957ac0458c2f0479e3824196d.tar.bz2
chat-7941c30117efe1b957ac0458c2f0479e3824196d.zip
Merge branch 'master' into advanced-permissions-phase-1
Diffstat (limited to 'api4/channel.go')
-rw-r--r--api4/channel.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/api4/channel.go b/api4/channel.go
index d46c3d559..1670770c6 100644
--- a/api4/channel.go
+++ b/api4/channel.go
@@ -21,6 +21,7 @@ func (api *API) InitChannel() {
api.BaseRoutes.ChannelsForTeam.Handle("/deleted", api.ApiSessionRequired(getDeletedChannelsForTeam)).Methods("GET")
api.BaseRoutes.ChannelsForTeam.Handle("/ids", api.ApiSessionRequired(getPublicChannelsByIdsForTeam)).Methods("POST")
api.BaseRoutes.ChannelsForTeam.Handle("/search", api.ApiSessionRequired(searchChannelsForTeam)).Methods("POST")
+ api.BaseRoutes.ChannelsForTeam.Handle("/autocomplete", api.ApiSessionRequired(autocompleteChannelsForTeam)).Methods("GET")
api.BaseRoutes.User.Handle("/teams/{team_id:[A-Za-z0-9]+}/channels", api.ApiSessionRequired(getChannelsForTeamForUser)).Methods("GET")
api.BaseRoutes.Channel.Handle("", api.ApiSessionRequired(getChannel)).Methods("GET")
@@ -490,6 +491,27 @@ func getChannelsForTeamForUser(c *Context, w http.ResponseWriter, r *http.Reques
}
}
+func autocompleteChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) {
+ c.RequireTeamId()
+ if c.Err != nil {
+ return
+ }
+
+ if !c.App.SessionHasPermissionToTeam(c.Session, c.Params.TeamId, model.PERMISSION_LIST_TEAM_CHANNELS) {
+ c.SetPermissionError(model.PERMISSION_LIST_TEAM_CHANNELS)
+ return
+ }
+
+ name := r.URL.Query().Get("name")
+
+ if channels, err := c.App.AutocompleteChannels(c.Params.TeamId, name); err != nil {
+ c.Err = err
+ return
+ } else {
+ w.Write([]byte(channels.ToJson()))
+ }
+}
+
func searchChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) {
c.RequireTeamId()
if c.Err != nil {