Compare commits

...

2 Commits

Author SHA1 Message Date
b3cb42dbef Create the @feature_lock decorator 2018-07-23 13:04:04 +02:00
f7d807370d Create the @beta decorator 2018-07-23 13:04:04 +02:00

View File

@ -18,6 +18,11 @@
""" """
from contextlib import contextmanager from contextlib import contextmanager
from functools import wraps
from flask import flash, redirect, url_for
from flask_babelex import gettext as _
from flask_security import current_user
@contextmanager @contextmanager
def force_locale(locale): def force_locale(locale):
@ -119,3 +124,41 @@ class RoutedMixin:
return func return func
return decorator return decorator
def beta(func):
"""Decorator to hide beta features from non-beta testers
"""
@wraps(func)
def decorated(*args, **kwargs): # pylint: disable=missing-docstring
if current_user.settings['beta'] != 'True':
flash(_('Join the beta testers to enable this functionality!'))
return redirect(url_for('account.settings'))
return func(*args, **kwargs)
return decorated
def feature_lock(feature): # pylint: disable=missing-return-doc,missing-return-type-doc
"""Decorator to lock a feature
:param feature: the name of a feature
:type feature: str
"""
def decorator(func): # pylint: disable=missing-docstring
@wraps(func)
def decorated(*args, **kwargs): # pylint: disable=missing-docstring
from calsocial.models import AppState
if AppState[f'feature:{feature}'] == 'true':
return func(*args, **kwargs)
return 'Feature locked'
return decorated
return decorator