diff options
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())) + } +} |