summaryrefslogtreecommitdiffstats
path: root/store/sqlstore/channel_store.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-10-20 17:33:20 -0700
committerJoram Wilander <jwawilander@gmail.com>2017-10-20 20:33:20 -0400
commitd39a722a819b154d260b90905065a000749778b6 (patch)
tree94d9a1de7bea296e135624c60bdd2147be344aab /store/sqlstore/channel_store.go
parent812f5664016deb596281d8119321833beafd4599 (diff)
downloadchat-d39a722a819b154d260b90905065a000749778b6.tar.gz
chat-d39a722a819b154d260b90905065a000749778b6.tar.bz2
chat-d39a722a819b154d260b90905065a000749778b6.zip
refactor max channels per team enforcement (#7690)
Diffstat (limited to 'store/sqlstore/channel_store.go')
-rw-r--r--store/sqlstore/channel_store.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go
index 124fc729d..da3fecc62 100644
--- a/store/sqlstore/channel_store.go
+++ b/store/sqlstore/channel_store.go
@@ -96,7 +96,7 @@ func (s SqlChannelStore) CreateIndexesIfNotExists() {
s.CreateFullTextIndexIfNotExists("idx_channels_txt", "Channels", "Name, DisplayName")
}
-func (s SqlChannelStore) Save(channel *model.Channel) store.StoreChannel {
+func (s SqlChannelStore) Save(channel *model.Channel, maxChannelsPerTeam int64) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
if channel.Type == model.CHANNEL_DIRECT {
result.Err = model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save.direct_channel.app_error", nil, "", http.StatusBadRequest)
@@ -104,7 +104,7 @@ func (s SqlChannelStore) Save(channel *model.Channel) store.StoreChannel {
if transaction, err := s.GetMaster().Begin(); err != nil {
result.Err = model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
} else {
- *result = s.saveChannelT(transaction, channel)
+ *result = s.saveChannelT(transaction, channel, maxChannelsPerTeam)
if result.Err != nil {
transaction.Rollback()
} else {
@@ -149,7 +149,7 @@ func (s SqlChannelStore) SaveDirectChannel(directchannel *model.Channel, member1
result.Err = model.NewAppError("SqlChannelStore.SaveDirectChannel", "store.sql_channel.save_direct_channel.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
} else {
directchannel.TeamId = ""
- channelResult := s.saveChannelT(transaction, directchannel)
+ channelResult := s.saveChannelT(transaction, directchannel, 0)
if channelResult.Err != nil {
transaction.Rollback()
@@ -187,7 +187,7 @@ func (s SqlChannelStore) SaveDirectChannel(directchannel *model.Channel, member1
})
}
-func (s SqlChannelStore) saveChannelT(transaction *gorp.Transaction, channel *model.Channel) store.StoreResult {
+func (s SqlChannelStore) saveChannelT(transaction *gorp.Transaction, channel *model.Channel, maxChannelsPerTeam int64) store.StoreResult {
result := store.StoreResult{}
if len(channel.Id) > 0 {
@@ -200,11 +200,11 @@ func (s SqlChannelStore) saveChannelT(transaction *gorp.Transaction, channel *mo
return result
}
- if channel.Type != model.CHANNEL_DIRECT && channel.Type != model.CHANNEL_GROUP {
+ if channel.Type != model.CHANNEL_DIRECT && channel.Type != model.CHANNEL_GROUP && maxChannelsPerTeam >= 0 {
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", "store.sql_channel.save_channel.current_count.app_error", nil, "teamId="+channel.TeamId+", "+err.Error(), http.StatusInternalServerError)
return result
- } else if count > *utils.Cfg.TeamSettings.MaxChannelsPerTeam {
+ } else if count >= maxChannelsPerTeam {
result.Err = model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.limit.app_error", nil, "teamId="+channel.TeamId, http.StatusBadRequest)
return result
}