mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
Merge pull request #6781 from lyft/xtinec--merge-feature-flags
Merge default feature flags and user defined feature flags
This commit is contained in:
@@ -410,6 +410,10 @@ export enum FeatureFlag {
|
||||
}
|
||||
```
|
||||
|
||||
`superset/config.py` contains `DEFAULT_FEATURE_FLAGS` which will be overwritten by
|
||||
those specified under FEATURE_FLAGS in `superset_config.py`. For example, `DEFAULT_FEATURE_FLAGS = { 'FOO': True, 'BAR': False }` in `superset/config.py` and `FEATURE_FLAGS = { 'BAR': True, 'BAZ': True }` in `superset_config.py` will result
|
||||
in combined feature flags of `{ 'FOO': True, 'BAR': True, 'BAZ': True }`.
|
||||
|
||||
## Linting
|
||||
|
||||
Lint the project with:
|
||||
|
||||
@@ -208,6 +208,18 @@ security_manager = appbuilder.sm
|
||||
|
||||
results_backend = app.config.get('RESULTS_BACKEND')
|
||||
|
||||
# Merge user defined feature flags with default feature flags
|
||||
feature_flags = app.config.get('DEFAULT_FEATURE_FLAGS')
|
||||
feature_flags.update(app.config.get('FEATURE_FLAGS') or {})
|
||||
|
||||
|
||||
def is_feature_enabled(feature):
|
||||
"""
|
||||
Utility function for checking whether a feature is turned on
|
||||
"""
|
||||
return feature_flags.get(feature)
|
||||
|
||||
|
||||
# Registering sources
|
||||
module_datasource_map = app.config.get('DEFAULT_MODULE_DS_MAP')
|
||||
module_datasource_map.update(app.config.get('ADDITIONAL_MODULE_DS_MAP'))
|
||||
|
||||
@@ -187,9 +187,12 @@ LANGUAGES = {
|
||||
# ---------------------------------------------------
|
||||
# Feature flags
|
||||
# ---------------------------------------------------
|
||||
# Feature flags that are on by default go here. Their
|
||||
# values can be overridden by those in super_config.py
|
||||
FEATURE_FLAGS = {}
|
||||
# Feature flags that are set by default go here. Their values can be
|
||||
# overwritten by those specified under FEATURE_FLAGS in super_config.py
|
||||
# For example, DEFAULT_FEATURE_FLAGS = { 'FOO': True, 'BAR': False } here
|
||||
# and FEATURE_FLAGS = { 'BAR': True, 'BAZ': True } in superset_config.py
|
||||
# will result in combined feature flags of { 'FOO': True, 'BAR': True, 'BAZ': True }
|
||||
DEFAULT_FEATURE_FLAGS = {}
|
||||
|
||||
# ---------------------------------------------------
|
||||
# Image and file configuration
|
||||
|
||||
@@ -31,7 +31,7 @@ from flask_babel import lazy_gettext as _
|
||||
import simplejson as json
|
||||
import yaml
|
||||
|
||||
from superset import conf, db, security_manager
|
||||
from superset import conf, db, feature_flags, security_manager
|
||||
from superset.exceptions import SupersetException, SupersetSecurityException
|
||||
from superset.translations.utils import get_language_pack
|
||||
from superset.utils import core as utils
|
||||
@@ -157,7 +157,7 @@ class BaseSupersetView(BaseView):
|
||||
'conf': {k: conf.get(k) for k in FRONTEND_CONF_KEYS},
|
||||
'locale': locale,
|
||||
'language_pack': get_language_pack(locale),
|
||||
'feature_flags': conf.get('FEATURE_FLAGS'),
|
||||
'feature_flags': feature_flags,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ import json
|
||||
import unittest
|
||||
|
||||
from flask_appbuilder.security.sqla import models as ab_models
|
||||
from mock import Mock
|
||||
from mock import Mock, patch
|
||||
import pandas as pd
|
||||
|
||||
from superset import app, db, security_manager
|
||||
from superset import app, db, is_feature_enabled, security_manager
|
||||
from superset.connectors.druid.models import DruidCluster, DruidDatasource
|
||||
from superset.connectors.sqla.models import SqlaTable
|
||||
from superset.models import core as models
|
||||
@@ -185,3 +185,11 @@ class SupersetTestCase(unittest.TestCase):
|
||||
if raise_on_error and 'error' in resp:
|
||||
raise Exception('run_sql failed')
|
||||
return resp
|
||||
|
||||
@patch.dict('superset.feature_flags', {'FOO': True}, clear=True)
|
||||
def test_existing_feature_flags(self):
|
||||
self.assertTrue(is_feature_enabled('FOO'))
|
||||
|
||||
@patch.dict('superset.feature_flags', {}, clear=True)
|
||||
def test_nonexistent_feature_flags(self):
|
||||
self.assertFalse(is_feature_enabled('FOO'))
|
||||
|
||||
Reference in New Issue
Block a user