diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-02-02 09:04:36 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-02 09:04:36 -0500 |
commit | 609d4f43d9eef504d852fbf02af5473b0d1424c8 (patch) | |
tree | 63fe24f08d5364501d3afed7c44b6739719d86e3 /api4/channel.go | |
parent | 2ac4f36587b8b217dcfd53e67c650c8ad27c75df (diff) | |
download | chat-609d4f43d9eef504d852fbf02af5473b0d1424c8.tar.gz chat-609d4f43d9eef504d852fbf02af5473b0d1424c8.tar.bz2 chat-609d4f43d9eef504d852fbf02af5473b0d1424c8.zip |
Implement POST /channels endpoint for APIv4 (#5241)
Diffstat (limited to 'api4/channel.go')
-rw-r--r-- | api4/channel.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/api4/channel.go b/api4/channel.go new file mode 100644 index 000000000..2ce9e23e5 --- /dev/null +++ b/api4/channel.go @@ -0,0 +1,45 @@ +// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package api4 + +import ( + "net/http" + + l4g "github.com/alecthomas/log4go" + "github.com/mattermost/platform/app" + "github.com/mattermost/platform/model" + "github.com/mattermost/platform/utils" +) + +func InitChannel() { + l4g.Debug(utils.T("api.channel.init.debug")) + + BaseRoutes.Channels.Handle("", ApiSessionRequired(createChannel)).Methods("POST") +} + +func createChannel(c *Context, w http.ResponseWriter, r *http.Request) { + channel := model.ChannelFromJson(r.Body) + if channel == nil { + c.SetInvalidParam("channel") + return + } + + if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToTeam(c.Session, channel.TeamId, model.PERMISSION_CREATE_PUBLIC_CHANNEL) { + c.SetPermissionError(model.PERMISSION_CREATE_PUBLIC_CHANNEL) + return + } + + if channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToTeam(c.Session, channel.TeamId, model.PERMISSION_CREATE_PRIVATE_CHANNEL) { + c.SetPermissionError(model.PERMISSION_CREATE_PRIVATE_CHANNEL) + return + } + + if sc, err := app.CreateChannelWithUser(channel, c.Session.UserId); err != nil { + c.Err = err + return + } else { + c.LogAudit("name=" + channel.Name) + w.Write([]byte(sc.ToJson())) + } +} |