This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
2018-11-25 19:39:09 +00:00
|
|
|
"""passbook access helper classes"""
|
|
|
|
from logging import getLogger
|
|
|
|
|
2018-12-09 20:07:38 +00:00
|
|
|
from django.http import Http404
|
|
|
|
|
|
|
|
from passbook.core.models import Application
|
|
|
|
|
2018-11-25 19:39:09 +00:00
|
|
|
LOGGER = getLogger(__name__)
|
|
|
|
|
|
|
|
class AccessMixin:
|
|
|
|
"""Mixin class for usage in Authorization views.
|
|
|
|
Provider functions to check application access, etc"""
|
|
|
|
|
|
|
|
def provider_to_application(self, provider):
|
|
|
|
"""Lookup application assigned to provider, throw error if no application assigned"""
|
2018-12-09 20:07:38 +00:00
|
|
|
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
|
2018-11-25 19:39:09 +00:00
|
|
|
|
|
|
|
def user_has_access(self, application, user):
|
|
|
|
"""Check if user has access to application."""
|
|
|
|
LOGGER.debug("Checking permissions of %s on application %s...", user, application)
|
|
|
|
return application.user_is_authorized(user)
|