diff options
-rw-r--r-- | store/sql_channel_store.go | 16 | ||||
-rw-r--r-- | store/sql_channel_store_test.go | 2 |
2 files changed, 10 insertions, 8 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go index b68774189..c9e0d113f 100644 --- a/store/sql_channel_store.go +++ b/store/sql_channel_store.go @@ -145,18 +145,20 @@ func (s SqlChannelStore) saveChannelT(transaction *gorp.Transaction, channel *mo return result } - if count, err := transaction.SelectInt("SELECT COUNT(0) FROM Channels WHERE TeamId = :TeamId AND DeleteAt = 0 AND (Type = 'O' OR Type = 'P')", map[string]interface{}{"TeamId": channel.TeamId}); err != nil { - result.Err = model.NewAppError("SqlChannelStore.Save", "Failed to get current channel count", "teamId="+channel.TeamId+", "+err.Error()) - return result - } else if count > 150 { - result.Err = model.NewAppError("SqlChannelStore.Save", "You've reached the limit of the number of allowed channels.", "teamId="+channel.TeamId) - return result + if channel.Type != model.CHANNEL_DIRECT { + if count, err := transaction.SelectInt("SELECT COUNT(0) FROM Channels WHERE TeamId = :TeamId AND DeleteAt = 0 AND (Type = 'O' OR Type = 'P')", map[string]interface{}{"TeamId": channel.TeamId}); err != nil { + result.Err = model.NewAppError("SqlChannelStore.Save", "Failed to get current channel count", "teamId="+channel.TeamId+", "+err.Error()) + return result + } else if count > 1000 { + result.Err = model.NewAppError("SqlChannelStore.Save", "You've reached the limit of the number of allowed channels.", "teamId="+channel.TeamId) + return result + } } if err := transaction.Insert(channel); err != nil { if IsUniqueConstraintError(err.Error(), "Name", "channels_name_teamid_key") { dupChannel := model.Channel{} - s.GetReplica().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Name = :Name AND DeleteAt > 0", map[string]interface{}{"TeamId": channel.TeamId, "Name": channel.Name}) + s.GetMaster().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Name = :Name AND DeleteAt > 0", map[string]interface{}{"TeamId": channel.TeamId, "Name": channel.Name}) if dupChannel.DeleteAt > 0 { result.Err = model.NewAppError("SqlChannelStore.Update", "A channel with that URL was previously created", "id="+channel.Id+", "+err.Error()) } else { diff --git a/store/sql_channel_store_test.go b/store/sql_channel_store_test.go index 695991bf7..8b22fbb7a 100644 --- a/store/sql_channel_store_test.go +++ b/store/sql_channel_store_test.go @@ -41,7 +41,7 @@ func TestChannelStoreSave(t *testing.T) { } o1.Type = model.CHANNEL_OPEN - for i := 0; i < 150; i++ { + for i := 0; i < 1000; i++ { o1.Id = "" o1.Name = "a" + model.NewId() + "b" if err := (<-store.Channel().Save(&o1)).Err; err != nil { |