Repository: dotkom/onlineweb4

Issue:
External Auth dashboard view permission denied bug
```
Internal Server Error: /dashboard/auth/sso/
Traceback (most recent call last):
  File "/srv/www/onlineweb4/env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 204, in get_response
    response = middleware_method(request, response)
  File "/srv/www/onlineweb4/env/local/lib/python2.7/site-packages/django/contrib/sessions/middleware.py", line 30, in process_response
    patch_vary_headers(response, ('Cookie',))
  File "/srv/www/onlineweb4/env/local/lib/python2.7/site-packages/django/utils/cache.py", line 148, in patch_vary_headers
    if response.has_header('Vary'):
AttributeError: type object 'PermissionDenied' has no attribute 'has_header'
```



Discussion:

Resolving patch:
diff --git a/apps/sso/dashboard/views.py b/apps/sso/dashboard/views.py
--- a/apps/sso/dashboard/views.py
+++ b/apps/sso/dashboard/views.py
@@ -16,8 +16,6 @@
 from apps.sso.models import Client
 from apps.sso.dashboard.forms import NewClientForm
 
-log = logging.getLogger('SSO')
-
 
 @login_required()
 def index(request):
@@ -29,7 +27,7 @@ def index(request):
 
     # Force only the almighty dotKom to access this view
     if not request.user.is_superuser:
-        return PermissionDenied
+        raise PermissionDenied
 
     context = get_base_context(request)
 
@@ -50,9 +48,11 @@ def new_app(request):
     :return: An HttpResponse
     """
 
+    _log = logging.getLogger('%s.%s' % (__name__, new_app.__name__))
+
     # Force only the almighty dotKom to access this view
     if not request.user.is_superuser:
-        return PermissionDenied
+        raise PermissionDenied
 
     context = get_base_context(request)
 
@@ -76,6 +76,8 @@ def new_app(request):
             client.skip_authorization = False
 
             client.save()
+
+            _log.info(u'%s created external auth client %s (%d)' % (request.user, client.name, client.id))
             messages.success(request, u'App-klienten ble opprettet')
             return redirect(reverse('sso:app_details', kwargs={'app_pk': client.id}))
 
@@ -95,9 +97,11 @@ def app_details(request, app_pk):
     :return: An HttpResponse
     """
 
+    _log = logging.getLogger('%s.%s' % (__name__, app_details.__name__))
+
     # Force only the almighty dotKom to access this view
     if not request.user.is_superuser:
-        return PermissionDenied
+        raise PermissionDenied
 
     context = get_base_context(request)
 
@@ -108,7 +112,10 @@ def app_details(request, app_pk):
     if request.method == 'POST':
         if 'action' in request.POST:
             if request.POST['action'] == 'delete':
+                app_id = context['app'].id
+                app_name = context['app'].name
                 context['app'].delete()
+                _log.info(u'%s deleted external auth client %s (%d)' % (request.user, app_name, app_id))
                 messages.success(request, u'App-klienten ble slettet')
                 return redirect(reverse('sso:index'))
 
diff --git a/apps/sso/views.py b/apps/sso/views.py
--- a/apps/sso/views.py
+++ b/apps/sso/views.py
@@ -3,7 +3,7 @@
 import logging
 
 from django.contrib.auth.decorators import login_required
-from django.http import HttpResponse, JsonResponse
+from django.http import HttpResponse
 from django.shortcuts import render
 from django.views.decorators.debug import sensitive_post_parameters
 from django.views.generic import View, FormView
@@ -16,19 +16,16 @@
 
 from oauth2_provider.settings import oauth2_settings
 from oauth2_provider.backends import OAuth2Backend
-from oauth2_provider.decorators import protected_resource
 from oauth2_provider.oauth2_validators import OAuth2Validator
 from oauth2_provider.exceptions import OAuthToolkitError
 from oauth2_provider.forms import AllowForm
 from oauth2_provider.http import HttpResponseUriRedirect
 from oauth2_provider.models import get_application_model
 from oauth2_provider.views.mixins import OAuthLibMixin
-from oauth2_provider.models import AccessToken
 
-from apps.authentication.models import FIELD_OF_STUDY_CHOICES
 from apps.sso.models import Client
 
-log = logging.getLogger('SSO')
+_log = logging.getLogger('SSO')
 
 
 @login_required
@@ -122,7 +119,7 @@ def form_valid(self, form):
             uri, headers, body, status = self.create_authorization_response(
                 request=self.request, scopes=scopes, credentials=credentials, allow=allow)
             self.success_url = uri
-            log.debug("Success url for the request: {0}".format(self.success_url))
+            _log.debug("Success url for the request: {0}".format(self.success_url))
             return HttpResponseUriRedirect(self.success_url)
 
         except OAuthToolkitError as error:


Test patch: