PLT-6556 Fixed last member of a channel not being able to delete channel with api v4 (#6397)

Этот коммит содержится в:
Harrison Healey
2017-05-11 16:32:14 -04:00
коммит произвёл Joram Wilander
родитель 9ad61491d6
Коммит a21a06afd9
2 изменённых файлов: 24 добавлений и 5 удалений

Просмотреть файл

@@ -482,6 +482,14 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
var memberCount int64
if memberCount, err = app.GetChannelMemberCount(c.Params.ChannelId); err != nil {
c.Err = err
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) { if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PUBLIC_CHANNEL) {
c.SetPermissionError(model.PERMISSION_DELETE_PUBLIC_CHANNEL) c.SetPermissionError(model.PERMISSION_DELETE_PUBLIC_CHANNEL)
return return
@@ -491,6 +499,7 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
c.SetPermissionError(model.PERMISSION_DELETE_PRIVATE_CHANNEL) c.SetPermissionError(model.PERMISSION_DELETE_PRIVATE_CHANNEL)
return return
} }
}
err = app.DeleteChannel(channel, c.Session.UserId) err = app.DeleteChannel(channel, c.Session.UserId)
if err != nil { if err != nil {

Просмотреть файл

@@ -1006,6 +1006,16 @@ func TestDeleteChannel(t *testing.T) {
_, resp = th.SystemAdminClient.DeleteChannel(privateChannel7.Id) _, resp = th.SystemAdminClient.DeleteChannel(privateChannel7.Id)
CheckNoError(t, resp) CheckNoError(t, resp)
// last member of a channel should be able to delete it regardless of required permissions
publicChannel6 = th.CreateChannelWithClient(th.Client, model.CHANNEL_OPEN)
privateChannel7 = th.CreateChannelWithClient(th.Client, model.CHANNEL_PRIVATE)
_, resp = Client.DeleteChannel(publicChannel6.Id)
CheckNoError(t, resp)
_, resp = Client.DeleteChannel(privateChannel7.Id)
CheckNoError(t, resp)
} }
func TestGetChannelByName(t *testing.T) { func TestGetChannelByName(t *testing.T) {