summaryrefslogtreecommitdiffstats
path: root/api/command.go
diff options
context:
space:
mode:
authorDavid Lu <david.lu@hotmail.com>2016-05-27 08:35:55 -0700
committerCorey Hulen <corey@hulen.com>2016-05-27 08:35:55 -0700
commit0d0734ac9845ef32c55ebf4c3185ba85065c5940 (patch)
treeaaaf2522d8cacbf06fce4aee0d89aac1f1d9ec19 /api/command.go
parent1e7805b79025823fba4479ffaa354e9c756d6622 (diff)
downloadchat-0d0734ac9845ef32c55ebf4c3185ba85065c5940.tar.gz
chat-0d0734ac9845ef32c55ebf4c3185ba85065c5940.tar.bz2
chat-0d0734ac9845ef32c55ebf4c3185ba85065c5940.zip
Added duplicated trigger validation (#3124)
Diffstat (limited to 'api/command.go')
-rw-r--r--api/command.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/api/command.go b/api/command.go
index 72249a48c..e1c576bba 100644
--- a/api/command.go
+++ b/api/command.go
@@ -288,6 +288,26 @@ func createCommand(c *Context, w http.ResponseWriter, r *http.Request) {
cmd.CreatorId = c.Session.UserId
cmd.TeamId = c.TeamId
+ if result := <-Srv.Store.Command().GetByTeam(c.TeamId); result.Err != nil {
+ c.Err = result.Err
+ return
+ } else {
+ teamCmds := result.Data.([]*model.Command)
+ for _, existingCommand := range teamCmds {
+ if cmd.Trigger == existingCommand.Trigger {
+ c.Err = model.NewLocAppError("createCommand", "api.command.duplicate_trigger.app_error", nil, "")
+ return
+ }
+ }
+ for _, builtInProvider := range commandProviders {
+ builtInCommand := *builtInProvider.GetCommand(c)
+ if cmd.Trigger == builtInCommand.Trigger {
+ c.Err = model.NewLocAppError("createCommand", "api.command.duplicate_trigger.app_error", nil, "")
+ return
+ }
+ }
+ }
+
if result := <-Srv.Store.Command().Save(cmd); result.Err != nil {
c.Err = result.Err
return