From 95a7dc5e927eb94c9321fb01ec75e1c3078ad54e Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Wed, 26 Sep 2012 17:44:01 -0400 Subject: [PATCH 1/4] refs #9: added a line in the docs showing how to disable the use of the smart cache --- docs/configuration.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/configuration.txt b/docs/configuration.txt index bcf734a..c0aa19f 100644 --- a/docs/configuration.txt +++ b/docs/configuration.txt @@ -32,6 +32,11 @@ context processors:: 'django.core.context_processors.request', ) +django-authority defaults to using a smart cache when checking permissions. +This can be disabled by adding the following line to ``settings.py``:: + + AUTHORITY_USE_SMART_CACHE = False + urls.py ======= From e45d774a763ae0303444b40e0d8344d978020f67 Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Wed, 26 Sep 2012 17:44:22 -0400 Subject: [PATCH 2/4] refs #9: added a section to show how cache invalidation works --- docs/tips_tricks.txt | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/docs/tips_tricks.txt b/docs/tips_tricks.txt index 6f77da7..ff5ae71 100644 --- a/docs/tips_tricks.txt +++ b/docs/tips_tricks.txt @@ -31,3 +31,38 @@ Within a permission class, you can refer to Django's basic permissions:: # ... authority.register(Flatpage, FlagpagePermisson) + +If the ``Permission`` table changes during the lifespan of a django-authority +permission instance and the smart cache is being used, you will need to call +invalidate_permissions_cache in order to see that changes:: + + class UserPermission(permission.BasePermission): + label = 'user_permission' + checks = ('do_foo',) + authority.register(User, UserPermission) + + user_permission = UserPermission(user) + + # can_foo is False here since the permission has not yet been added. + can_foo = user_permission.has_user_perms('foo', user) + + Permission.objects.create( + content_type=Permission.objects.get_content_type(User), + object_id=user.pk, + codename='foo', + user=user, + approved=True, + ) + + # can_foo is still False because the permission cache has not been + invalidated yet. + can_foo = user_permission.has_user_perms('foo', user) + + user_permission.invalidate_permissions_cache() + + # can_foo is now True + can_foo = user_permission.has_user_perms('foo', user) + +This is particularly useful if you are using the permission instances during a +request, where it is unlikely that the state of the ``Permission`` table will +change. From 6c1692ae6362f3ed7bdf5cdbc9122f1654fd2ed9 Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Wed, 26 Sep 2012 17:49:19 -0400 Subject: [PATCH 3/4] refs #9: bumped the version in the docs --- docs/conf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 1137de2..84cd272 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -46,10 +46,10 @@ copyright = u'2009, the django-authority team' # built documents. # # The short X.Y version. -version = '0.4' +version = '0.5' # The full version, including alpha/beta/rc tags. -release = '0.4dev' +release = '0.5dev' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. From 483cb629c72bad11ae99793c18e5d2c684c504ba Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Thu, 27 Sep 2012 17:17:59 -0400 Subject: [PATCH 4/4] refs #9: added a line in the basic overview about the smart cache --- docs/index.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/index.txt b/docs/index.txt index 6f9fda9..baa244c 100644 --- a/docs/index.txt +++ b/docs/index.txt @@ -23,6 +23,11 @@ This application provides three abilities: voodoo-code to Django's ``contrib.auth`` system, it keeps your existing permission system intact! +django-authority uses a cache that is stored on the user object to help improve +performance. However, if the ``Permission`` table changes the cache will need +to be invalidated. More information about this can be found in the tips and +tricks section. + .. warning:: We have just started with the documentation and it's far from being perfect. If you find glitches, errors or just have feedback, please contact the team: :ref:`support`.