core: add loading view for authorisation views

This commit is contained in:
Jens Langhammer
2018-12-09 21:07:18 +01:00
parent db3ae58a21
commit e7f7a3127c
6 changed files with 83 additions and 6 deletions

View File

@ -1,17 +1,28 @@
"""passbook OAuth2 Views"""
from logging import getLogger
from urllib.parse import urlencode
from django.http import Http404
from django.shortcuts import get_object_or_404
from django.shortcuts import get_object_or_404, reverse
from django.utils.translation import ugettext as _
from oauth2_provider.views.base import AuthorizationView
from passbook.core.views.access import AccessMixin
from passbook.core.views.utils import LoadingView
from passbook.oauth_provider.models import OAuth2Provider
LOGGER = getLogger(__name__)
class PassbookAuthorizationLoadingView(LoadingView):
"""Show loading view for permission checks"""
title = _('Checking permissions...')
def get_url(self):
querystring = urlencode(self.request.GET)
return reverse('passbook_oauth_provider:oauth2-ok-authorize')+'?'+querystring
class PassbookAuthorizationView(AccessMixin, AuthorizationView):
"""Custom OAuth2 Authorization View which checks rules, etc"""
@ -31,7 +42,10 @@ class PassbookAuthorizationView(AccessMixin, AuthorizationView):
if not self.user_has_access(self._application, request.user):
# TODO: Create a general error class for access denied
raise Http404
return super().dispatch(request, *args, **kwargs)
actual_response = super().dispatch(request, *args, **kwargs)
if actual_response.status_code == 400:
LOGGER.debug(request.GET.get('redirect_uri'))
return actual_response
def render_to_response(self, context, **kwargs):
# Always set is_login to true for correct css class