Inject current_user_is_subscriber into Jinja context

This variable is set to True iff the user has a subscriber/demo/admin role.
It's an attempt to get some of the Cloud subscription specific stuff out
of Pillar.
This commit is contained in:
2017-06-14 16:26:29 +02:00
parent e69ac4c5b9
commit fd700ca6d9

View File

@@ -2,12 +2,17 @@ import logging
import flask
from werkzeug.local import LocalProxy
from pillar.api.utils import authorization
from pillar.extension import PillarExtension
EXTENSION_NAME = 'cloud'
ROLES_TO_BE_SUBSCRIBER = {'demo', 'subscriber', 'admin'}
class CloudExtension(PillarExtension):
has_context_processor = True
def __init__(self):
self._log = logging.getLogger('%s.CloudExtension' % __name__)
@@ -65,6 +70,11 @@ class CloudExtension(PillarExtension):
import os.path
return os.path.join(os.path.dirname(__file__), 'static')
def context_processor(self):
return {
'current_user_is_subscriber': authorization.user_matches_roles(ROLES_TO_BE_SUBSCRIBER)
}
def _get_current_cloud():
"""Returns the Cloud extension of the current application."""