2019-10-30 13:06:55 +00:00
|
|
|
from django.contrib.auth.mixins import UserPassesTestMixin
|
2019-10-25 11:33:37 +00:00
|
|
|
from django.views.generic.base import ContextMixin
|
|
|
|
|
2019-10-30 13:36:03 +00:00
|
|
|
from . import api, get_version
|
2019-10-30 13:06:55 +00:00
|
|
|
from .auth import SESSION_KEY_TOKEN
|
2019-10-25 11:33:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CustomContextMixin(ContextMixin):
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
2019-10-30 13:36:03 +00:00
|
|
|
# generate services menu items
|
|
|
|
services_menu = [
|
|
|
|
{'pattern_name': 'musician:dashboard', 'title': 'Domains & websites'},
|
|
|
|
{'pattern_name': 'musician:mails', 'title': 'Mails'},
|
|
|
|
{'pattern_name': 'musician:mailing-lists', 'title': 'Mailing lists'},
|
|
|
|
{'pattern_name': 'musician:databases', 'title': 'Databases'},
|
|
|
|
{'pattern_name': 'musician:saas', 'title': 'SaaS'},
|
|
|
|
]
|
2019-10-25 11:33:37 +00:00
|
|
|
context.update({
|
2019-10-30 13:36:03 +00:00
|
|
|
'services_menu': services_menu,
|
2019-10-25 11:33:37 +00:00
|
|
|
'version': get_version(),
|
|
|
|
})
|
|
|
|
|
|
|
|
return context
|
2019-10-30 13:06:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UserTokenRequiredMixin(UserPassesTestMixin):
|
|
|
|
def test_func(self):
|
|
|
|
"""Check that the user has an authorized token."""
|
|
|
|
token = self.request.session.get(SESSION_KEY_TOKEN, None)
|
|
|
|
if token is None:
|
|
|
|
return False
|
|
|
|
|
|
|
|
# initialize orchestra api orm
|
|
|
|
self.orchestra = api.Orchestra(auth_token=token)
|
|
|
|
|
|
|
|
# verify if the token is valid
|
|
|
|
if self.orchestra.verify_credentials() is None:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|