[Python-modules-commits] [django-guardian] 01/08: Import django-guardian_1.4.4.orig.tar.gz

Brian May bam at moszumanska.debian.org
Mon Apr 4 07:35:55 UTC 2016


This is an automated email from the git hooks/post-receive script.

bam pushed a commit to branch master
in repository django-guardian.

commit 7b851ba50ea8ae28e86553d8e1c73e8125526211
Author: Brian May <bam at debian.org>
Date:   Mon Apr 4 17:24:27 2016 +1000

    Import django-guardian_1.4.4.orig.tar.gz
---
 CHANGES                                |   9 +++
 PKG-INFO                               |   2 +-
 django_guardian.egg-info/PKG-INFO      |   2 +-
 django_guardian.egg-info/top_level.txt |   2 -
 guardian/core.py                       |  23 ++++---
 guardian/testapp/tests/test_core.py    | 117 +++++++++++++++++++++++++++++++++
 guardian/version.py                    |   2 +-
 setup.py                               |   9 ++-
 8 files changed, 151 insertions(+), 15 deletions(-)

diff --git a/CHANGES b/CHANGES
index f3783d2..cf66e38 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,10 @@
+Release 1.4.4 (Apr 04, 2016)
+============================
+
+* Don't install support example_project.
+* Direct ForeignKey perms in prefetch_perms.
+
+
 Release 1.4.3 (Apr 03, 2016)
 ============================
 
@@ -10,6 +17,7 @@ Release 1.4.3 (Apr 03, 2016)
 * Fix up processing of ANONYMOUS_USER_NAME where set to None. Fixes #409.
 * Require TEMPLATE_403 to exist if RENDER_403 set.
 
+
 Release 1.4.2 (Mar 09, 2016)
 ============================
 
@@ -32,6 +40,7 @@ Release 1.4.2 (Mar 09, 2016)
   and `with_superusers` set to `False`, only directly assigned permissions are
   now returned, and not effective (infered) permissions.
 
+
 Release 1.4.1 (Jan 10, 2016)
 ============================
 
diff --git a/PKG-INFO b/PKG-INFO
index 2682d36..410badf 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: django-guardian
-Version: 1.4.3
+Version: 1.4.4
 Summary: Implementation of per object permissions for Django.
 Home-page: http://github.com/django-guardian/django-guardian
 Author: Lukasz Balcerzak
diff --git a/django_guardian.egg-info/PKG-INFO b/django_guardian.egg-info/PKG-INFO
index 2682d36..410badf 100644
--- a/django_guardian.egg-info/PKG-INFO
+++ b/django_guardian.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: django-guardian
-Version: 1.4.3
+Version: 1.4.4
 Summary: Implementation of per object permissions for Django.
 Home-page: http://github.com/django-guardian/django-guardian
 Author: Lukasz Balcerzak
diff --git a/django_guardian.egg-info/top_level.txt b/django_guardian.egg-info/top_level.txt
index f733345..41567ab 100644
--- a/django_guardian.egg-info/top_level.txt
+++ b/django_guardian.egg-info/top_level.txt
@@ -1,3 +1 @@
-benchmarks
-example_project
 guardian
diff --git a/guardian/core.py b/guardian/core.py
index 7f6d211..9d5e3dc 100644
--- a/guardian/core.py
+++ b/guardian/core.py
@@ -151,8 +151,6 @@ class ObjectPermissionChecker(object):
         ctype = ContentType.objects.get_for_model(obj)
         key = self.get_local_cache_key(obj)
         if key not in self._obj_perms_cache:
-
-
             if self.user and self.user.is_superuser:
                 perms = list(chain(*Permission.objects
                                    .filter(content_type=ctype)
@@ -206,10 +204,7 @@ class ObjectPermissionChecker(object):
 
         group_model = get_group_obj_perms_model(model)
 
-        group_filters = {
-            'object_pk__in': pks
-        }
-
+        group_filters = {}
         if self.user:
             fieldname = 'group__%s' % (
                 User.groups.field.related_query_name(),
@@ -221,18 +216,27 @@ class ObjectPermissionChecker(object):
         if group_model.objects.is_generic():
             group_filters.update({
                 'content_type': ctype,
+                'object_pk__in': pks,
+            })
+        else:
+            group_filters.update({
+                'content_object_id__in': pks
             })
 
         if self.user:
             model = get_user_obj_perms_model(model)
             user_filters = {
                 'user': self.user,
-                'object_pk__in': pks
             }
 
             if model.objects.is_generic():
                 user_filters.update({
                     'content_type': ctype,
+                    'object_pk__in': pks
+                })
+            else:
+                user_filters.update({
+                    'content_object_id__in': pks
                 })
 
             # Query user and group permissions separately and then combine
@@ -246,7 +250,10 @@ class ObjectPermissionChecker(object):
             )
 
         for perm in perms:
-            key = (ctype.id, perm.object_pk)
+            if type(perm).objects.is_generic():
+                key = (ctype.id, perm.object_pk)
+            else:
+                key = (ctype.id, force_text(perm.content_object_id))
 
             if key in self._obj_perms_cache:
                 self._obj_perms_cache[key].append(perm.permission.codename)
diff --git a/guardian/testapp/tests/test_core.py b/guardian/testapp/tests/test_core.py
index 485124a..10fa6cb 100644
--- a/guardian/testapp/tests/test_core.py
+++ b/guardian/testapp/tests/test_core.py
@@ -20,6 +20,8 @@ from guardian.models import UserObjectPermission, GroupObjectPermission
 from guardian.shortcuts import assign_perm
 from guardian.management import create_anonymous_user
 
+from guardian.testapp.models import Project
+
 User = get_user_model()
 
 
@@ -285,3 +287,118 @@ class ObjectPermissionCheckerTest(ObjectPermissionTestCase):
 
         finally:
             settings.DEBUG = False
+
+    def test_prefetch_user_perms_direct_rel(self):
+        settings.DEBUG = True
+        try:
+            from django.db import connection
+
+            ContentType.objects.clear_cache()
+            user = User.objects.create(username='active_user', is_active=True)
+            projects = \
+                [Project.objects.create(name='Project%s' % i)
+                    for i in range(2)]
+            for project in projects:
+                assign_perm("change_project", user, project)
+            checker = ObjectPermissionChecker(user)
+
+            # Prefetch permissions
+            self.assertTrue(checker.prefetch_perms(projects))
+            query_count = len(connection.queries)
+
+            # Checking cache is filled
+            self.assertEqual(len(checker._obj_perms_cache), 2)
+
+            # Checking shouldn't spawn any queries
+            checker.has_perm("change_project", projects[0])
+            self.assertEqual(len(connection.queries), query_count)
+
+            # Checking for other permission but for Group object again
+            # shouldn't spawn any query too
+            checker.has_perm("delete_project", projects[0])
+            self.assertEqual(len(connection.queries), query_count)
+
+            # Checking for same model but other instance shouldn't spawn any
+            #  queries
+            checker.has_perm("change_project", projects[1])
+            self.assertEqual(len(connection.queries), query_count)
+
+        finally:
+            settings.DEBUG = False
+
+    def test_prefetch_superuser_perms_direct_rel(self):
+        settings.DEBUG = True
+        try:
+            from django.db import connection
+
+            ContentType.objects.clear_cache()
+            user = User.objects.create(
+                username='active_user', is_active=True, is_superuser=True)
+            projects = \
+                [Project.objects.create(name='Project%s' % i)
+                    for i in range(2)]
+            for project in projects:
+                assign_perm("change_project", user, project)
+            checker = ObjectPermissionChecker(user)
+
+            # Prefetch permissions
+            self.assertTrue(checker.prefetch_perms(projects))
+            query_count = len(connection.queries)
+
+            # Checking cache is filled
+            self.assertEqual(len(checker._obj_perms_cache), 2)
+
+            # Checking shouldn't spawn any queries
+            checker.has_perm("change_project", projects[0])
+            self.assertEqual(len(connection.queries), query_count)
+
+            # Checking for other permission but for Group object again
+            # shouldn't spawn any query too
+            checker.has_perm("delete_project", projects[0])
+            self.assertEqual(len(connection.queries), query_count)
+
+            # Checking for same model but other instance shouldn't spawn any
+            #  queries
+            checker.has_perm("change_project", projects[1])
+            self.assertEqual(len(connection.queries), query_count)
+
+        finally:
+            settings.DEBUG = False
+
+    def test_prefetch_group_perms_direct_rel(self):
+        settings.DEBUG = True
+        try:
+            from django.db import connection
+
+            ContentType.objects.clear_cache()
+            new_group = Group.objects.create(name='new-group')
+            projects = \
+                [Project.objects.create(name='Project%s' % i)
+                    for i in range(2)]
+            for project in projects:
+                assign_perm("change_project", new_group, project)
+            checker = ObjectPermissionChecker(new_group)
+
+            # Prefetch permissions
+            self.assertTrue(checker.prefetch_perms(projects))
+            query_count = len(connection.queries)
+
+            # Checking cache is filled
+            self.assertEqual(len(checker._obj_perms_cache), 2)
+
+            # Checking shouldn't spawn any queries
+            checker.has_perm("change_project", projects[0])
+            self.assertEqual(len(connection.queries), query_count)
+
+            # Checking for other permission but for Group object again
+            # shouldn't spawn any query too
+            checker.has_perm("delete_project", projects[0])
+            self.assertEqual(len(connection.queries), query_count)
+
+            # Checking for same model but other instance shouldn't spawn any
+            #  queries
+            checker.has_perm("change_project", projects[1])
+            self.assertEqual(len(connection.queries), query_count)
+
+        finally:
+            settings.DEBUG = False
diff --git a/guardian/version.py b/guardian/version.py
index 3136771..9cfe7a4 100644
--- a/guardian/version.py
+++ b/guardian/version.py
@@ -1,4 +1,4 @@
 # coding: utf-8
 # file generated by setuptools_scm
 # don't change, don't track in version control
-version = '1.4.3'
+version = '1.4.4'
diff --git a/setup.py b/setup.py
index 5e31881..bd22aee 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
 import os
 import sys
-from setuptools import setup, find_packages
+from setuptools import setup
 from extras import RunFlakesCommand
 
 
@@ -27,7 +27,12 @@ setup(
     description="Implementation of per object permissions for Django.",
     long_description=long_description,
     zip_safe=False,
-    packages=find_packages(),
+    packages=[
+        'guardian', 'guardian.conf', 'guardian.management',
+        'guardian.migrations', 'guardian.templatetags', 'guardian.testapp',
+        'guardian.management.commands', 'guardian.testapp.migrations',
+        'guardian.testapp.tests'
+    ],
     include_package_data=True,
     license='BSD',
     install_requires=[

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/django-guardian.git



More information about the Python-modules-commits mailing list