diff options
author | Corey Hulen <corey@hulen.com> | 2015-11-27 19:58:05 -0800 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2015-11-27 19:58:05 -0800 |
commit | d4eb8743e3bd36b6cd2e7939c9a698d893b215d7 (patch) | |
tree | 442382ad3dd80a6a11fdbe38703ad794cc17287e /store/sql_preference_store.go | |
parent | 42a001c4e26acaebb7bade2a9b45428578b04164 (diff) | |
parent | c50144de0475da2c5865cb4246f63d285aa452c4 (diff) | |
download | chat-d4eb8743e3bd36b6cd2e7939c9a698d893b215d7.tar.gz chat-d4eb8743e3bd36b6cd2e7939c9a698d893b215d7.tar.bz2 chat-d4eb8743e3bd36b6cd2e7939c9a698d893b215d7.zip |
Merge pull request #1416 from florianorben/PLT-1125
PLT-1125: Add "Preview pre-release features" option
Diffstat (limited to 'store/sql_preference_store.go')
-rw-r--r-- | store/sql_preference_store.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/store/sql_preference_store.go b/store/sql_preference_store.go index 8454abcbd..f73dad3ac 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": model.PREFERENCE_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) IsFeatureEnabled(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": model.PREFERENCE_CATEGORY_ADVANCED_SETTINGS, "Name": FEATURE_TOGGLE_PREFIX + feature}); err != nil { + result.Err = model.NewAppError("SqlPreferenceStore.IsFeatureEnabled", "We encountered an error while finding a pre release feature preference", err.Error()) + } else { + result.Data = value == "true" + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} |