Commits

Kai Diefenbach committed 95f0219

Removed django 1.2 dependencies

Comments (0)

Files changed (1)

permissions/utils.py

         The object for which the permission should be checked.
     groups
         If given these groups will be assigned to the user temporarily before 
-        the permissions are checked.
+        the permissions are checked. If you don't know why this is need you
+        can safely ignore it.
     """
+
     if obj is None:
         return False
 
     if user.is_superuser:
         return True
 
-    if not user.is_authenticated():
-        user = User.objects.get(username="anonymous")
-
     user_groups = list(Group.objects.filter(user=user))
     user_groups.extend(groups)
 
         p = ObjectPermission.objects.filter(
             content_type=ct, content_id=obj.id, user=user, permission__codename = codename)
 
-        if p.exists():
+        # if p.exists():
+        #     return True
+
+        if p.count() > 0:
             return True
 
         p = ObjectPermission.objects.filter(
             content_type=ct, content_id=obj.id, group__in=user_groups, permission__codename = codename)
 
-        if p.exists():
+        # if p.exists():
+        #     return True
+
+        if p.count() > 0:
             return True
-
-        if is_inherited(codename, obj):
+        
+        if is_inherited(codename, obj) == False:
             return False
 
         try:
     else:
         return False
 
+def get_group(name):
+    """Returns the group with given or None if it doesn't exit.
+    """
+    try:
+        return Group.objects.get(name=name)
+    except Group.DoesNotExist:
+        return None
+    
 # Registering ################################################################
 
 def register_permission(name, codename):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.