Commits

Florian Hahn committed 7c251b1

make utils.py generic

Comments (0)

Files changed (1)

object_permission_backend_nonrel/utils.py

 
 
 def get_group_id_list(user_id):
-    from permission_backend_nonrel.models import UserPermissionList
-
-    try:
-        return UserPermissionList.objects.get(user__id=user_id).group_fk_list
-    except UserPermissionList.DoesNotExist:
-        return []
+    return []
 
 def get_content_type_string(obj):
     return (obj._meta.app_label + '.' + obj.__class__.__name__).lower()
     returns True if permission_list is saved
     """
     
-    if isinstance(user, User) and isinstance(model, models.Model):    
+       if isinstance(user, User) and isinstance(model, models.Model):    
         ct = get_content_type_string(model)
         try:
             perm_obj = ObjectPermission.objects.get(user=user,
         except ObjectPermission.DoesNotExist:
             perm_obj = ObjectPermission(user=user, 
                                         content_type=ct, object_id=model.id)
-        current_permission_list = perm_obj.permission_list
+        current_permission_list = perm_obj.get_permission_list()
         registered_permissions = PermissionType.objects.filter(content_type=
                                                                ct)
 
-        registerd_permission_list = list()
+        registerd_permission_list = []
+        new_permission_list = current_permission_list
         for perm in registered_permissions:
             registerd_permission_list.append(perm.permission_name)
         
         # remove already existing entries from permission_list
         for perm in current_permission_list:
             try:
-                dup = permission_list.index(perm)
-                permission_list.remove(dup)
+                permission_list.remove(permission_list.index(perm))
             except ValueError:
                 pass
             
         for perm in permission_list:
             try:
-                perm_obj.permission_list.append(registerd_permission_list.pop(registerd_permission_list.index(perm)))
+                new_permission_list.append(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
 
     else:
         return False
 
-
 def add_permission_to_group(perm, group, obj):
     ct = get_content_type_string(obj)
     perm_obj, created = GroupObjectPermission.objects.get_or_create(group=group,
                                                                     content_type=ct,
                                                                     object_id=obj.id)
-    perm_obj.permission_list.append(perm)
+    permission_list = perm_obj.get_permission_list()
+    permission_list.append(perm)
+    perm_obj.set_permission_list(permission_list)
     perm_obj.save()
     
 
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.