add passbook.pretend to use passbook in applications which don't support generic OAuth
This commit is contained in:
		@ -1,7 +1,8 @@
 | 
			
		||||
"""passbook access helper classes"""
 | 
			
		||||
from logging import getLogger
 | 
			
		||||
 | 
			
		||||
from django.http import Http404
 | 
			
		||||
from django.contrib import messages
 | 
			
		||||
from django.utils.translation import gettext as _
 | 
			
		||||
 | 
			
		||||
from passbook.core.models import Application
 | 
			
		||||
 | 
			
		||||
@ -11,14 +12,18 @@ class AccessMixin:
 | 
			
		||||
    """Mixin class for usage in Authorization views.
 | 
			
		||||
    Provider functions to check application access, etc"""
 | 
			
		||||
 | 
			
		||||
    # request is set by view but since this Mixin has no base class
 | 
			
		||||
    request = None
 | 
			
		||||
 | 
			
		||||
    def provider_to_application(self, provider):
 | 
			
		||||
        """Lookup application assigned to provider, throw error if no application assigned"""
 | 
			
		||||
        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
 | 
			
		||||
            messages.error(self.request, _('Provider "%(name)s" has no application assigned' % {
 | 
			
		||||
                'name': provider
 | 
			
		||||
                }))
 | 
			
		||||
            raise exc
 | 
			
		||||
 | 
			
		||||
    def user_has_access(self, application, user):
 | 
			
		||||
        """Check if user has access to application."""
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user