Commits

Anonymous committed 36b918e

[per-object-permissions] Fixes problem with one-to-one relationships as the original code assumed every model had an id attribute, now uses "_get_pk_val()" to determine the model id.

  • Participants
  • Parent commits 48643b4
  • Branches per-object-permissions

Comments (0)

Files changed (3)

django/contrib/admin/row_level_perm_manipulator.py

 
         model_ct = rlp.model_ct
         model = model_ct.get_object_for_this_type (pk=rlp.model_id)
+        model_id = rlp.model_id
         
         perm = Permission.objects.get(pk=new_data['perm'])
         
         
         field_name_list = ('owner_ct', 'owner_id', 'model_ct', 'model_id', 'permission')
         field_data = owner_ct.id
-        all_data = {'owner_id':owner.id, 'model_ct_id':model_ct.id, 'model_id':model.id, 'permission_id':perm.id}
+        all_data = {'owner_id':owner.id, 'model_ct_id':model_ct.id, 'model_id':model_id, 'permission_id':perm.id}
         manipulators.manipulator_validator_unique_together(field_name_list, self.opts, self, field_data, all_data)
         
         rlp.owner = owner

django/contrib/admin/views/row_level_permissions.py

             raise PermissionDenied
 
         if not request.user.has_perm(rlp._meta.app_label + '.' + rlp._meta.get_delete_permission()):
-            print "BAM"
             raise PermissionDenied   
         if not request.user.has_perm(obj._meta.app_label + '.' + obj._meta.get_change_permission(), object=obj):
-            print "BOOM"
             raise PermissionDenied           
 
         rlp.delete()
         raise PermissionDenied  
 
     obj = rlp.model
-    if model_instance.id is not obj.id:
+    model_id = model_instance._get_pk_val()
+    object_id = obj._get_pk_val()
+    if model_id is not object_id:
         raise PermissionDenied
     
     if not request.user.has_perm(rlp._meta.app_label + '.' + rlp._meta.get_change_permission(), object=obj):

django/contrib/auth/models.py

             permission = Permission.objects.get(codename__exact=permission, content_type=model_ct.id)
         if model_ct != permission.content_type:
             raise TypeError, "Invalid value: Permission content type(%s) and object content type(%s) do not match" % (permission.content_type, type_ct)
-        
-        rowLvlPerm = self.model(model_id=model_instance.id, model_ct=model_ct,
+        model_id = model_instance._get_pk_val()
+        rowLvlPerm = self.model(model_id=model_id, model_ct=model_ct,
                                                  owner_id=owner.id, owner_ct=ContentType.objects.get_for_model(owner),
                                                  permission=permission, negative=negative)
         rowLvlPerm.save()
             except Permission.DoesNotExist:
                 return False
         try:
-            row_level_perm=self.row_level_permissions_owned.get(model_id=object.id, 
+            model_id = object._get_pk_val()
+            row_level_perm=self.row_level_permissions_owned.get(model_id=model_id, 
                                                                     model_ct=object_ct.id, 
                                                                     permission=permission.id)
         except RowLevelPermission.DoesNotExist:
         #AND rlp."model_id"=%s
         #AND rlp."model_ct_id"=%s
         #AND rlp."permission_id"=%s;
+        model_id = object._get_pk_val()
         cursor = connection.cursor()        
         sql = """
             SELECT rlp.%s
             backend.quote_name('negative'))
         cursor.execute(sql, [self.id, 
                              ContentType.objects.get_for_model(Group).id, 
-                             object.id,
+                             model_id,
                              ContentType.objects.get_for_model(object).id,
                              permission.id,])
         row = cursor.fetchone()