From 8c8d9dbf8fa3b4ebf640bf5e1a71f9c04b57e111 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Tue, 9 May 2017 16:01:06 -0400 Subject: Forward port 3.8.1 changes that missed master (#6362) --- api4/channel.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'api4/channel.go') diff --git a/api4/channel.go b/api4/channel.go index 493b012a0..6daf43c74 100644 --- a/api4/channel.go +++ b/api4/channel.go @@ -259,7 +259,7 @@ func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) { return } - if groupChannel, err := app.CreateGroupChannel(userIds); err != nil { + if groupChannel, err := app.CreateGroupChannel(userIds, c.Session.UserId); err != nil { c.Err = err return } else { @@ -376,7 +376,7 @@ func getPublicChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request return } - if channels, err := app.GetPublicChannelsForTeam(c.Params.TeamId, c.Params.Page, c.Params.PerPage); err != nil { + if channels, err := app.GetPublicChannelsForTeam(c.Params.TeamId, c.Params.Page*c.Params.PerPage, c.Params.PerPage); err != nil { c.Err = err return } else { -- cgit v1.2.3-1-g7c22 From a21a06afd9907e9911dcb166d902cba9f405c7cb Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Thu, 11 May 2017 16:32:14 -0400 Subject: PLT-6556 Fixed last member of a channel not being able to delete channel with api v4 (#6397) --- api4/channel.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'api4/channel.go') 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) -- cgit v1.2.3-1-g7c22