Created
April 1, 2015 10:17
-
-
Save Diviei/7b2161871953f0c12615 to your computer and use it in GitHub Desktop.
Hide admin panel for unprivileged users
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from django.http import HttpResponseNotFound | |
class AdminSiteSecurizeMiddleware(object): | |
"""Hide admin panel for unprivileged users""" | |
def process_response(self, request, response): | |
""" | |
Return a 404 Not Found page if there is no authenticated user | |
or if user has no enough privileges | |
""" | |
if '/admin/' in request.META.get("PATH_INFO"): | |
if not request.user.is_authenticated() or not request.user.is_staff: | |
return HttpResponseNotFound() | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would like to find a better way to identify and admin panel request instead of checking "PATH_INFO" value.