Skip to content

Commit

Permalink
[Core] Add a configuration file.
Browse files Browse the repository at this point in the history
Give the possiblity to configure if the user must be staff.

Fixes: #17
  • Loading branch information
hobbestigrou committed Mar 23, 2018
1 parent ba3a892 commit da61d38
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions django_cprofile_middleware/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
"""A module to manage the configuration."""
from django.conf import settings

CPROFILE_MIDDLEWARE_REQUIRE_STAFF = getattr(
settings, 'CPROFILE_MIDDLEWARE_REQUIRE_STAFF', True)
11 changes: 9 additions & 2 deletions django_cprofile_middleware/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from django.conf import settings
from django.http import HttpResponse

from django_cprofile_middleware.conf import CPROFILE_MIDDLEWARE_REQUIRE_STAFF

if django.VERSION >= (1, 10):
from django.utils.deprecation import MiddlewareMixin
else:
Expand Down Expand Up @@ -41,8 +43,13 @@ class ProfilerMiddleware(MiddlewareMixin):
http://www.slideshare.net/zeeg/django-con-high-performance-django-presentation.
"""
def can(self, request):
return settings.DEBUG and 'prof' in request.GET and \
request.user is not None and request.user.is_staff
if request.user is None:
return False

prof = request.GET.get('prof', None)

return settings.DEBUG and prof \
and request.user.is_staff or not CPROFILE_MIDDLEWARE_REQUIRE_STAFF

def process_view(self, request, callback, callback_args, callback_kwargs):
if self.can(request):
Expand Down

0 comments on commit da61d38

Please sign in to comment.