summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorFlorian Orben <florian.orben@gmail.com>2015-11-13 22:56:41 +0100
committerFlorian Orben <florian.orben@gmail.com>2015-11-27 23:17:45 +0100
commit79e9244dc9977c6ec6adc78631c0485efa9f60af (patch)
treeecb7d6e68603771ca53f79bd312b4f6a72af31d0 /store
parentabec097da19a56a73270a3e9b30198c07b1210ea (diff)
downloadchat-79e9244dc9977c6ec6adc78631c0485efa9f60af.tar.gz
chat-79e9244dc9977c6ec6adc78631c0485efa9f60af.tar.bz2
chat-79e9244dc9977c6ec6adc78631c0485efa9f60af.zip
allow to toggle features in backend
Diffstat (limited to 'store')
-rw-r--r--store/sql_preference_store.go47
-rw-r--r--store/sql_store.go2
-rw-r--r--store/store.go3
3 files changed, 51 insertions, 1 deletions
diff --git a/store/sql_preference_store.go b/store/sql_preference_store.go
index 8454abcbd..63561a509 100644
--- a/store/sql_preference_store.go
+++ b/store/sql_preference_store.go
@@ -4,6 +4,7 @@
package store
import (
+ l4g "code.google.com/p/log4go"
"github.com/go-gorp/gorp"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
@@ -13,6 +14,10 @@ type SqlPreferenceStore struct {
*SqlStore
}
+const (
+ FEATURE_TOGGLE_PREFIX = "feature_enabled_"
+)
+
func NewSqlPreferenceStore(sqlStore *SqlStore) PreferenceStore {
s := &SqlPreferenceStore{sqlStore}
@@ -36,6 +41,23 @@ func (s SqlPreferenceStore) CreateIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_preferences_name", "Preferences", "Name")
}
+func (s SqlPreferenceStore) DeleteUnusedFeatures() {
+ l4g.Debug("Deleting any unused pre-release features")
+
+ sql := `DELETE
+ FROM Preferences
+ WHERE
+ Category = :Category
+ AND Value = :Value
+ AND Name LIKE '` + FEATURE_TOGGLE_PREFIX + `%'`
+
+ queryParams := map[string]string{
+ "Category": "advanced_settings",
+ "Value": "false",
+ }
+ s.GetMaster().Exec(sql, queryParams)
+}
+
func (s SqlPreferenceStore) Save(preferences *model.Preferences) StoreChannel {
storeChannel := make(StoreChannel)
@@ -257,3 +279,28 @@ func (s SqlPreferenceStore) PermanentDeleteByUser(userId string) StoreChannel {
return storeChannel
}
+
+func (s SqlPreferenceStore) FeatureToggle(feature, userId string) StoreChannel {
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+ if value, err := s.GetReplica().SelectStr(`SELECT
+ value
+ FROM
+ Preferences
+ WHERE
+ UserId = :UserId
+ AND Category = :Category
+ AND Name = :Name`, map[string]interface{}{"UserId": userId, "Category": "advanced_settings", "Name": FEATURE_TOGGLE_PREFIX + feature}); err != nil {
+ result.Err = model.NewAppError("SqlPreferenceStore.featureToggle", "We encountered an error while finding a pre release feature preference", err.Error())
+ } else {
+ result.Data = value == "true"
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
diff --git a/store/sql_store.go b/store/sql_store.go
index f348db10b..d17a3e8c3 100644
--- a/store/sql_store.go
+++ b/store/sql_store.go
@@ -148,6 +148,8 @@ func NewSqlStore() Store {
sqlStore.webhook.(*SqlWebhookStore).CreateIndexesIfNotExists()
sqlStore.preference.(*SqlPreferenceStore).CreateIndexesIfNotExists()
+ sqlStore.preference.(*SqlPreferenceStore).DeleteUnusedFeatures()
+
if model.IsPreviousVersion(schemaVersion) || isSchemaVersion07 || isSchemaVersion10 {
sqlStore.system.Update(&model.System{Name: "Version", Value: model.CurrentVersion})
l4g.Warn("The database schema has been upgraded to version " + model.CurrentVersion)
diff --git a/store/store.go b/store/store.go
index 338ae186f..36d991a15 100644
--- a/store/store.go
+++ b/store/store.go
@@ -186,4 +186,5 @@ type PreferenceStore interface {
GetCategory(userId string, category string) StoreChannel
GetAll(userId string) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel
-}
+ FeatureToggle(feature, userId string) StoreChannel
+} \ No newline at end of file