Add support for hiding settings based on whether features are enabled in the license.

This commit is contained in:
Chris Church
2016-11-21 14:15:41 -05:00
parent 06510ce4b9
commit 5b1df83fcc
6 changed files with 63 additions and 7 deletions

View File

@@ -14,7 +14,8 @@ from rest_framework.exceptions import APIException
from awx.main.task_engine import TaskEnhancer
from awx.main.utils import memoize
__all__ = ['LicenseForbids', 'get_license', 'feature_enabled', 'feature_exists']
__all__ = ['LicenseForbids', 'get_license', 'get_licensed_features',
'feature_enabled', 'feature_exists']
class LicenseForbids(APIException):
@@ -42,6 +43,15 @@ def get_license(show_key=False):
return license_data
def get_licensed_features():
"""Return a set of all features enabled by the active license."""
features = set()
for feature, enabled in _get_validated_license_data().get('features', {}).items():
if enabled:
features.add(feature)
return features
def feature_enabled(name):
"""Return True if the requested feature is enabled, False otherwise."""
return _get_validated_license_data().get('features', {}).get(name, False)