diff options
author | Saturnino Abril <saturnino.abril@gmail.com> | 2017-03-14 21:08:58 +0900 |
---|---|---|
committer | George Goldberg <george@gberg.me> | 2017-03-14 12:08:58 +0000 |
commit | a71a9fc3bff1b6a6c9d5e0a65f53686922572834 (patch) | |
tree | c132dcdb82cef953634e091d91fddab1c3572efe /api4/channel.go | |
parent | aafc63933a7e213261e28ac7f528cea50b70e1af (diff) | |
download | chat-a71a9fc3bff1b6a6c9d5e0a65f53686922572834.tar.gz chat-a71a9fc3bff1b6a6c9d5e0a65f53686922572834.tar.bz2 chat-a71a9fc3bff1b6a6c9d5e0a65f53686922572834.zip |
APIv4 DELETE channels/{channel_id} (#5723)
Diffstat (limited to 'api4/channel.go')
-rw-r--r-- | api4/channel.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/api4/channel.go b/api4/channel.go index 80ae9fa30..acf14846a 100644 --- a/api4/channel.go +++ b/api4/channel.go @@ -22,6 +22,7 @@ func InitChannel() { BaseRoutes.Channel.Handle("", ApiSessionRequired(getChannel)).Methods("GET") BaseRoutes.Channel.Handle("", ApiSessionRequired(updateChannel)).Methods("PUT") + BaseRoutes.Channel.Handle("", ApiSessionRequired(deleteChannel)).Methods("DELETE") BaseRoutes.ChannelByName.Handle("", ApiSessionRequired(getChannelByName)).Methods("GET") BaseRoutes.ChannelByNameForTeamName.Handle("", ApiSessionRequired(getChannelByNameForTeamName)).Methods("GET") @@ -226,6 +227,40 @@ func getPublicChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request } } +func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) { + c.RequireChannelId() + if c.Err != nil { + return + } + + var channel *model.Channel + var err *model.AppError + if channel, err = app.GetChannel(c.Params.ChannelId); err != nil { + c.Err = err + return + } + + if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PUBLIC_CHANNEL) { + c.SetPermissionError(model.PERMISSION_DELETE_PUBLIC_CHANNEL) + return + } + + if channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PRIVATE_CHANNEL) { + c.SetPermissionError(model.PERMISSION_DELETE_PRIVATE_CHANNEL) + return + } + + err = app.DeleteChannel(channel, c.Session.UserId) + if err != nil { + c.Err = err + return + } + + c.LogAudit("name=" + channel.Name) + + ReturnStatusOK(w) +} + func getChannelByName(c *Context, w http.ResponseWriter, r *http.Request) { c.RequireTeamId().RequireChannelName() if c.Err != nil { |