1. Florian Hahn
  2. django-object-permission-backend-nonrel

Commits

Florian Hahn  committed 645ef28

replace ListField with SetField, remove group_id_list_cache, thanks Waldemar

  • Participants
  • Parent commits cd996e2
  • Branches default

Comments (0)

Files changed (3)

File object_permission_backend_nonrel/backends.py

View file
         return self._create_permission_strings(current_permission_objs)
 
     def _get_group_permission(self, user_id, object_id, ct):
-        if not hasattr(self, '_group_id_list_cache'):
-            setattr(self, '_group_id_list_cache', get_group_id_list(user_id))
-        current_permission_objs = GroupObjectPermission.objects.filter(group_id__in=self._group_id_list_cache, content_type=ct, object_id=object_id)
+        group_id_list =  get_group_id_list(user_id)
+        current_permission_objs = GroupObjectPermission.objects.filter(group_id__in=group_id_list, content_type=ct, object_id=object_id)
         return self._create_permission_strings(current_permission_objs)

File object_permission_backend_nonrel/models.py

View file
 from django.contrib.auth.models import User, Group
 from django.contrib.contenttypes.models import ContentType
 
-from djangotoolbox.fields import ListField
+from djangotoolbox.fields import SetField
 
 
 class PermissionType(models.Model):
 
 
 class BaseObjectPermission(models.Model):
-    permissions = ListField(models.CharField(max_length=64))
+    permissions = SetField(models.CharField(max_length=64))
 
     content_type = models.CharField(max_length=256)
     object_id = models.PositiveIntegerField()

File object_permission_backend_nonrel/utils.py

View file
                 permission_list.remove(permission_list.index(perm))
             except ValueError:
                 pass
-            
+        
         for perm in permission_list:
             try:
-                new_permission_list.append(registerd_permission_list.pop(registerd_permission_list.index(perm)))
+                new_permission_list.add(registerd_permission_list.pop(registerd_permission_list.index(perm)))
             except ValueError:
                 return False
-            
+
         perm_obj.set_permission_list(new_permission_list)
         perm_obj.save()
         return True
                                                                     content_type=ct,
                                                                     object_id=obj.id)
     permission_list = perm_obj.get_permission_list()
-    permission_list.append(perm)
+    permission_list.add(perm)
     perm_obj.set_permission_list(permission_list)
     perm_obj.save()