allow to toggle features in backend
Этот коммит содержится в:
@@ -1,6 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"label": "#1389",
|
|
||||||
"description": "Show markdown preview option in message input box"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
package store
|
package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
l4g "code.google.com/p/log4go"
|
||||||
"github.com/go-gorp/gorp"
|
"github.com/go-gorp/gorp"
|
||||||
"github.com/mattermost/platform/model"
|
"github.com/mattermost/platform/model"
|
||||||
"github.com/mattermost/platform/utils"
|
"github.com/mattermost/platform/utils"
|
||||||
@@ -13,6 +14,10 @@ type SqlPreferenceStore struct {
|
|||||||
*SqlStore
|
*SqlStore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
FEATURE_TOGGLE_PREFIX = "feature_enabled_"
|
||||||
|
)
|
||||||
|
|
||||||
func NewSqlPreferenceStore(sqlStore *SqlStore) PreferenceStore {
|
func NewSqlPreferenceStore(sqlStore *SqlStore) PreferenceStore {
|
||||||
s := &SqlPreferenceStore{sqlStore}
|
s := &SqlPreferenceStore{sqlStore}
|
||||||
|
|
||||||
@@ -36,6 +41,23 @@ func (s SqlPreferenceStore) CreateIndexesIfNotExists() {
|
|||||||
s.CreateIndexIfNotExists("idx_preferences_name", "Preferences", "Name")
|
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 {
|
func (s SqlPreferenceStore) Save(preferences *model.Preferences) StoreChannel {
|
||||||
storeChannel := make(StoreChannel)
|
storeChannel := make(StoreChannel)
|
||||||
|
|
||||||
@@ -257,3 +279,28 @@ func (s SqlPreferenceStore) PermanentDeleteByUser(userId string) StoreChannel {
|
|||||||
|
|
||||||
return 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
|
||||||
|
}
|
||||||
|
|||||||
@@ -148,6 +148,8 @@ func NewSqlStore() Store {
|
|||||||
sqlStore.webhook.(*SqlWebhookStore).CreateIndexesIfNotExists()
|
sqlStore.webhook.(*SqlWebhookStore).CreateIndexesIfNotExists()
|
||||||
sqlStore.preference.(*SqlPreferenceStore).CreateIndexesIfNotExists()
|
sqlStore.preference.(*SqlPreferenceStore).CreateIndexesIfNotExists()
|
||||||
|
|
||||||
|
sqlStore.preference.(*SqlPreferenceStore).DeleteUnusedFeatures()
|
||||||
|
|
||||||
if model.IsPreviousVersion(schemaVersion) || isSchemaVersion07 || isSchemaVersion10 {
|
if model.IsPreviousVersion(schemaVersion) || isSchemaVersion07 || isSchemaVersion10 {
|
||||||
sqlStore.system.Update(&model.System{Name: "Version", Value: model.CurrentVersion})
|
sqlStore.system.Update(&model.System{Name: "Version", Value: model.CurrentVersion})
|
||||||
l4g.Warn("The database schema has been upgraded to version " + model.CurrentVersion)
|
l4g.Warn("The database schema has been upgraded to version " + model.CurrentVersion)
|
||||||
|
|||||||
@@ -186,4 +186,5 @@ type PreferenceStore interface {
|
|||||||
GetCategory(userId string, category string) StoreChannel
|
GetCategory(userId string, category string) StoreChannel
|
||||||
GetAll(userId string) StoreChannel
|
GetAll(userId string) StoreChannel
|
||||||
PermanentDeleteByUser(userId string) StoreChannel
|
PermanentDeleteByUser(userId string) StoreChannel
|
||||||
|
FeatureToggle(feature, userId string) StoreChannel
|
||||||
}
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../config/pre_release_features.json
|
|
||||||
6
web/static/config/pre_release_features.json
Обычный файл
6
web/static/config/pre_release_features.json
Обычный файл
@@ -0,0 +1,6 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"label": "#1389",
|
||||||
|
"description": "Show markdown preview option in message input box"
|
||||||
|
}
|
||||||
|
]
|
||||||
Ссылка в новой задаче
Block a user