Permalink
Browse files

Merge branch 'master' of github.com:hmarr/mongoengine

  • Loading branch information...
2 parents 3ce163b + 9f8d6b3 commit 1647441ce878b0369b984ad8bf7445e919537ac2 @rozza rozza committed Oct 1, 2012
Showing with 21 additions and 0 deletions.
  1. +21 −0 mongoengine/django/auth.py
View
@@ -3,6 +3,8 @@
from mongoengine import *
from django.utils.encoding import smart_str
+from django.contrib.auth.models import _user_get_all_permissions
+from django.contrib.auth.models import _user_has_perm
from django.contrib.auth.models import AnonymousUser
from django.utils.translation import ugettext_lazy as _
@@ -104,6 +106,25 @@ def check_password(self, raw_password):
"""
return check_password(raw_password, self.password)
+ def get_all_permissions(self, obj=None):
+ return _user_get_all_permissions(self, obj)
+
+ def has_perm(self, perm, obj=None):
+ """
+ Returns True if the user has the specified permission. This method
+ queries all available auth backends, but returns immediately if any
+ backend returns True. Thus, a user who has permission from a single
+ auth backend is assumed to have permission in general. If an object is
+ provided, permissions for this specific object are checked.
+ """
+
+ # Active superusers have all permissions.
+ if self.is_active and self.is_superuser:
+ return True
+
+ # Otherwise we need to check the backends.
+ return _user_has_perm(self, perm, obj)
+
@classmethod
def create_user(cls, username, password, email=None):
"""Create (and save) a new user with the given username, password and

0 comments on commit 1647441

Please sign in to comment.