From a71a9fc3bff1b6a6c9d5e0a65f53686922572834 Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Tue, 14 Mar 2017 21:08:58 +0900 Subject: APIv4 DELETE channels/{channel_id} (#5723) --- api4/channel.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'api4/channel.go') 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 { -- cgit v1.2.3-1-g7c22