core: cleanup

This commit is contained in:
Jens Langhammer
2018-12-09 21:07:38 +01:00
parent e7f7a3127c
commit 0754b07765
6 changed files with 28 additions and 14 deletions

View File

@ -1,6 +1,10 @@
"""passbook access helper classes"""
from logging import getLogger
from django.http import Http404
from passbook.core.models import Application
LOGGER = getLogger(__name__)
class AccessMixin:
@ -9,7 +13,12 @@ class AccessMixin:
def provider_to_application(self, provider):
"""Lookup application assigned to provider, throw error if no application assigned"""
return provider.application
try:
return provider.application
except Application.DoesNotExist as exc:
# TODO: Log that no provider has no application assigned
LOGGER.warning('Provider "%s" has no application assigned...', provider)
raise Http404 from exc
def user_has_access(self, application, user):
"""Check if user has access to application."""