summaryrefslogtreecommitdiffstats
path: root/api/channel.go
diff options
context:
space:
mode:
authorenahum <nahumhbl@gmail.com>2016-05-10 09:24:52 -0300
committerChristopher Speller <crspeller@gmail.com>2016-05-10 08:24:52 -0400
commit45b22f312d3f57c63f86ffdbbb50c29108099993 (patch)
tree0921119d05ff8ae01a660269d3d1da639062c074 /api/channel.go
parent4f39b8b2e4e919c036d37718346a420f5a36f885 (diff)
downloadchat-45b22f312d3f57c63f86ffdbbb50c29108099993.tar.gz
chat-45b22f312d3f57c63f86ffdbbb50c29108099993.tar.bz2
chat-45b22f312d3f57c63f86ffdbbb50c29108099993.zip
PLT-2674 Private Group should not have Leave option when only one member remains (#2888)
Diffstat (limited to 'api/channel.go')
-rw-r--r--api/channel.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/api/channel.go b/api/channel.go
index b63e44017..b7a608717 100644
--- a/api/channel.go
+++ b/api/channel.go
@@ -576,6 +576,7 @@ func leave(c *Context, w http.ResponseWriter, r *http.Request) {
sc := Srv.Store.Channel().Get(id)
uc := Srv.Store.User().Get(c.Session.UserId)
+ ccm := Srv.Store.Channel().GetMemberCount(id)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -583,9 +584,13 @@ func leave(c *Context, w http.ResponseWriter, r *http.Request) {
} else if uresult := <-uc; uresult.Err != nil {
c.Err = cresult.Err
return
+ } else if ccmresult := <-ccm; ccmresult.Err != nil {
+ c.Err = ccmresult.Err
+ return
} else {
channel := cresult.Data.(*model.Channel)
user := uresult.Data.(*model.User)
+ membersCount := ccmresult.Data.(int64)
if !c.HasPermissionsToTeam(channel.TeamId, "leave") {
return
@@ -597,6 +602,12 @@ func leave(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
+ if channel.Type == model.CHANNEL_PRIVATE && membersCount == 1 {
+ c.Err = model.NewLocAppError("leave", "api.channel.leave.last_member.app_error", nil, "userId="+user.Id)
+ c.Err.StatusCode = http.StatusBadRequest
+ return
+ }
+
if channel.Name == model.DEFAULT_CHANNEL {
c.Err = model.NewLocAppError("leave", "api.channel.leave.default.app_error", map[string]interface{}{"Channel": model.DEFAULT_CHANNEL}, "")
c.Err.StatusCode = http.StatusBadRequest