summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/channel.go19
-rw-r--r--api/channel_test.go5
2 files changed, 7 insertions, 17 deletions
diff --git a/api/channel.go b/api/channel.go
index 2a56e7c93..50dc840ff 100644
--- a/api/channel.go
+++ b/api/channel.go
@@ -448,23 +448,14 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- var memberCount int64
- if memberCount, err = app.GetChannelMemberCount(id); err != nil {
- c.Err = err
+ 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
}
- // 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
- }
+ 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)
diff --git a/api/channel_test.go b/api/channel_test.go
index 6ed4d55fa..bdb62677f 100644
--- a/api/channel_test.go
+++ b/api/channel_test.go
@@ -1476,9 +1476,8 @@ func TestDeleteChannel(t *testing.T) {
t.Fatal("should have errored not system admin")
}
- // Only one left in channel, should be able to delete
- if _, err := Client.DeleteChannel(channel4.Id); err != nil {
- t.Fatal(err)
+ if _, err := Client.DeleteChannel(channel4.Id); err == nil {
+ t.Fatal("Should not be able to delete channel, even though only one user is left")
}
th.LoginSystemAdmin()