Compare commits
	
		
			2 Commits
		
	
	
		
			test-cover
			...
			feature-lo
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| b3cb42dbef | |||
| f7d807370d | 
| @@ -18,6 +18,11 @@ | ||||
| """ | ||||
|  | ||||
| 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 | ||||
| def force_locale(locale): | ||||
| @@ -119,3 +124,41 @@ class RoutedMixin: | ||||
|             return func | ||||
|  | ||||
|         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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user