github.com/haalcala/mattermost-server-change-repo@v0.0.0-20210713015153-16753fbeee5f/api4/command_local.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package api4 5 6 import ( 7 "net/http" 8 9 "github.com/mattermost/mattermost-server/v5/audit" 10 "github.com/mattermost/mattermost-server/v5/model" 11 ) 12 13 func (api *API) InitCommandLocal() { 14 api.BaseRoutes.Commands.Handle("", api.ApiLocal(localCreateCommand)).Methods("POST") 15 api.BaseRoutes.Commands.Handle("", api.ApiLocal(listCommands)).Methods("GET") 16 17 api.BaseRoutes.Command.Handle("", api.ApiLocal(getCommand)).Methods("GET") 18 api.BaseRoutes.Command.Handle("", api.ApiLocal(updateCommand)).Methods("PUT") 19 api.BaseRoutes.Command.Handle("/move", api.ApiLocal(moveCommand)).Methods("PUT") 20 api.BaseRoutes.Command.Handle("", api.ApiLocal(deleteCommand)).Methods("DELETE") 21 } 22 23 func localCreateCommand(c *Context, w http.ResponseWriter, r *http.Request) { 24 cmd := model.CommandFromJson(r.Body) 25 if cmd == nil { 26 c.SetInvalidParam("command") 27 return 28 } 29 30 auditRec := c.MakeAuditRecord("localCreateCommand", audit.Fail) 31 defer c.LogAuditRec(auditRec) 32 c.LogAudit("attempt") 33 34 rcmd, err := c.App.CreateCommand(cmd) 35 if err != nil { 36 c.Err = err 37 return 38 } 39 40 auditRec.Success() 41 c.LogAudit("success") 42 auditRec.AddMeta("command", rcmd) 43 44 w.WriteHeader(http.StatusCreated) 45 w.Write([]byte(rcmd.ToJson())) 46 }