summaryrefslogtreecommitdiffstats
path: root/api4/channel.go
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2017-05-11 16:32:14 -0400
committerJoram Wilander <jwawilander@gmail.com>2017-05-11 16:32:14 -0400
commita21a06afd9907e9911dcb166d902cba9f405c7cb (patch)
treed2c5ebd2b752b8172988433e4b075badd84946af /api4/channel.go
parent9ad61491d693c608dd3bf4a45df9bdaf33b79016 (diff)
downloadchat-a21a06afd9907e9911dcb166d902cba9f405c7cb.tar.gz
chat-a21a06afd9907e9911dcb166d902cba9f405c7cb.tar.bz2
chat-a21a06afd9907e9911dcb166d902cba9f405c7cb.zip
PLT-6556 Fixed last member of a channel not being able to delete channel with api v4 (#6397)
Diffstat (limited to 'api4/channel.go')
-rw-r--r--api4/channel.go19
1 files changed, 14 insertions, 5 deletions
diff --git a/api4/channel.go b/api4/channel.go
index 6daf43c74..522d6cfb9 100644
--- a/api4/channel.go
+++ b/api4/channel.go
@@ -482,14 +482,23 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
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)
+ var memberCount int64
+ if memberCount, err = app.GetChannelMemberCount(c.Params.ChannelId); err != nil {
+ c.Err = err
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
+ // Allow delete if user is the only member left in channel
+ if memberCount > 1 {
+ 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)