PLT-6556 Fixed last member of a channel not being able to delete channel with api v4 (#6397)
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
9ad61491d6
Коммит
a21a06afd9
@@ -482,14 +482,23 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PUBLIC_CHANNEL) {
|
var memberCount int64
|
||||||
c.SetPermissionError(model.PERMISSION_DELETE_PUBLIC_CHANNEL)
|
if memberCount, err = app.GetChannelMemberCount(c.Params.ChannelId); err != nil {
|
||||||
|
c.Err = err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PRIVATE_CHANNEL) {
|
// Allow delete if user is the only member left in channel
|
||||||
c.SetPermissionError(model.PERMISSION_DELETE_PRIVATE_CHANNEL)
|
if memberCount > 1 {
|
||||||
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)
|
err = app.DeleteChannel(channel, c.Session.UserId)
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user