diff options
author | Carlos Tadeu Panato Junior <ctadeu@gmail.com> | 2017-04-04 06:20:04 +0200 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2017-04-03 21:20:04 -0700 |
commit | 0a81dd9fff606d041ee08c62c655bf6966c7a66a (patch) | |
tree | 1521cebb48f15df64688d30a60023e10fa0077a3 /api4/command.go | |
parent | 348374fba5db8415d37d5cd8b897048b1300f415 (diff) | |
download | chat-0a81dd9fff606d041ee08c62c655bf6966c7a66a.tar.gz chat-0a81dd9fff606d041ee08c62c655bf6966c7a66a.tar.bz2 chat-0a81dd9fff606d041ee08c62c655bf6966c7a66a.zip |
implement GET /teams/{team_id}/commands/autocomplete (#5951)
Diffstat (limited to 'api4/command.go')
-rw-r--r-- | api4/command.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/api4/command.go b/api4/command.go index 41a85eac3..d6102bd70 100644 --- a/api4/command.go +++ b/api4/command.go @@ -18,6 +18,8 @@ func InitCommand() { BaseRoutes.Commands.Handle("", ApiSessionRequired(createCommand)).Methods("POST") BaseRoutes.Commands.Handle("", ApiSessionRequired(listCommands)).Methods("GET") + + BaseRoutes.Team.Handle("/commands/autocomplete", ApiSessionRequired(listAutocompleteCommands)).Methods("GET") } func createCommand(c *Context, w http.ResponseWriter, r *http.Request) { @@ -91,3 +93,23 @@ func listCommands(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(model.CommandListToJson(commands))) } + +func listAutocompleteCommands(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_VIEW_TEAM) { + c.SetPermissionError(model.PERMISSION_VIEW_TEAM) + return + } + + commands, err := app.ListAutocompleteCommands(c.Params.TeamId, c.T) + if err != nil { + c.Err = err + return + } + + w.Write([]byte(model.CommandListToJson(commands))) +} |