Commits

Kai Diefenbach committed bb502a6 Merge

Merged 1.0 branch

Comments (0)

Files changed (11)

 c3761c18d35922bfa6b311c53332125326801163 1.0b3
 84a2f4b8a52466f6190eeb26dcb9fabca79e2dcc 1.0b4
 27337d044a8d76deb753f40ea94631567fb807c2 1.0
+8e19e9ceac1981c5c1e8ce8535794afd22710a74 1.0.1
+4e38edea63b1b7be92c684ce8749ac03e6230acf 1.0.2
+4e38edea63b1b7be92c684ce8749ac03e6230acf 1.0.2
+0000000000000000000000000000000000000000 1.0.2
+0000000000000000000000000000000000000000 1.0.2
+150b7c0e5592bf79767b3376caab695f1f4def73 1.0.2
+7754113e63c5389239bbd0e478b453d78046aa64 1.0.3
+7754113e63c5389239bbd0e478b453d78046aa64 1.0.3
+0000000000000000000000000000000000000000 1.0.3
+0000000000000000000000000000000000000000 1.0.3
+43de2a0faa9b287977db5b07b76e9064e169ea63 1.0.3
 What is it?
 ===========
 
-django-permissions provides per-object permissions for Django
-
-Documentation
-=============
-
-For more documentation please visit: http://packages.python.org/django-permissions/
+django-permissions provides per-object permissions for Django on roles: http://en.wikipedia.org/wiki/Role-based_access_control
 
 Code
 ====
 Changes
 =======
 
+1.0.3 (2011-04-30)
+------------------
+
+Bugfix release
+
+* Bugfix: Removed mutuable parameters; issue #11
+
+Changes
+=======
+
+1.0.2 (2011-04-09)
+------------------
+
+Bugfix release
+
+* Bugfix: prevent to add same Users several times to a Role; issue #6 of django-workflows
+* Updated Development Status to "5 - Production/Stable"
+
+1.0.1 (2011-04-08)
+------------------
+
+Bugfix release
+
+* Bugfix: DatabaseErrors with Postgres; issue #5.
+* Bugfix: changed order of passed parameters to has_permission; issue #6
+* Bugfix: removed not needed import of "sets"; issue #8
+
 1.0 (2010-08-24)
 ----------------
 
 # documentation root, use os.path.abspath to make it absolute, like shown here.
 #sys.path.append(os.path.abspath('.'))
 
-sys.path.append(os.path.abspath("../../../lfc_project"))
-sys.path.append(os.path.abspath("../../../parts/lfc"))
-sys.path.append(os.path.abspath("../../../parts/django"))
-sys.path.append(os.path.abspath("../../../parts/tagging"))
-sys.path.append(os.path.abspath("../../../parts/portlets"))
+sys.path.append(os.path.abspath("../../../project"))
 sys.path.append(os.path.abspath("../../../parts/permissions"))
 
 # -- General configuration -----------------------------------------------------
 django-permissions
 ==================
 
-Contents:
+django-permissions is a generic framework for per-object permissions for Django based on roles: http://en.wikipedia.org/wiki/Role-based_access_control
+
+Contents
+========
 
 .. toctree::
    :maxdepth: 1

docs/overview.rst

 ========
 
 * django-permissions is a generic framework for per-object permissions for
-  Django.
+  Django based on roles: http://en.wikipedia.org/wiki/Role-based_access_control
 
 Permissions
 ===========
 Local Roles
 ===========
 
-* Local roles are roles which are assigned to users and groups for a specific 
+* Local roles are roles which are assigned to users and groups for specific 
   content objects.
 
 Users

docs/usage/simple.rst

 .. code-block:: python
 
     >>> from permissions.utils import has_permission
-    >>> result = has_permission(content, user, "view")
+    >>> has_permission(content, user, "view")
     True
 
 This will check whether the current user has the permission "View" for the

permissions/__init__.py

         """
         return permissions.utils.remove_permission(self, role, permission)
 
-    def has_permission(self, user, permission, roles=[]):
+    def has_permission(self, user, permission, roles=None):
         """Returns True if the passed user has passed permission for this
         instance. Otherwise False.
 
             If passed, these roles will be assigned to the user temporarily
             before the permissions are checked.
         """
+        if roles is None:
+            roles = []
         return permissions.utils.has_permission(self, user, permission, roles)
 
-    def check_permission(self, user, permission, roles=[]):
+    def check_permission(self, user, permission, roles=None):
         """Raise Unauthorized if the the passed user hasn't passed permission 
         for this instance.
 
             If passed, these roles will be assigned to the user temporarily
             before the permissions are checked.
         """
+        if roles is None:
+            roles = []
+
         if not self.has_permission(user, permission, roles):
             raise Unauthorized("User %s doesn't have permission %s for object %s" % (user, permission, self.slug))
 
         return permissions.utils.get_local_roles(self, principal)
 
     def remove_role(self, principal, role):
-        """Adds a local role for the principal to the object.
+        """Removes a local role for the principal to the object.
 
         **Parameters:**
 

permissions/models.py

 from django.contrib.contenttypes.models import ContentType
 from django.utils.translation import ugettext_lazy as _
 
+# permissions imports
+import permissions.utils
+
 class Permission(models.Model):
     """A permission which can be granted to users/groups and objects.
 
     def add_principal(self, principal, content=None):
         """Addes the given principal (user or group) ot the Role.
         """
-        if isinstance(principal, User):
-            PrincipalRoleRelation.objects.create(user=principal, role=self)
-        else:
-            PrincipalRoleRelation.objects.create(group=principal, role=self)
+        return permissions.utils.add_role(principal, self)
 
     def get_groups(self, content=None):
         """Returns all groups which has this role assigned. If content is given

permissions/tests.py

         self.assertEqual(result[0].username, "john")
         self.assertEqual(result[1].username, "jane")
         self.assertEqual(len(result), 2)
+        
+    def test_get_users_3(self):
+        """
+        """
+        self.role_1.add_principal(self.user)
+        result = self.role_1.get_users()
+        self.assertEqual(result, [self.user])
+        
+        # Add same user again
+        self.role_1.add_principal(self.user)
+        result = self.role_1.get_users()
+        self.assertEqual(result, [self.user])
 
 class PermissionTestCase(TestCase):
     """

permissions/utils.py

 
     **Parameters:**
 
-        obj
-            The content object for which an inheritance block should be added.
+    obj
+        The content object for which an inheritance block should be added.
 
-        permission
-            The permission for which an inheritance block should be removed.
-            Either a permission object or the codename of a permission.
+    permission
+        The permission for which an inheritance block should be removed.
+        Either a permission object or the codename of a permission.
     """
     if not isinstance(permission, Permission):
         try:
 
     **Parameters:**
 
-        obj
-            The content object for which the permission should be checked.
+    obj
+        The content object for which the permission should be checked.
 
-        codename
-            The permission which should be checked. Must be the codename of
-            the permission.
+    codename
+        The permission which should be checked. Must be the codename of the 
+        permission.
     """
     ct = ContentType.objects.get_for_model(obj)
     try:
 
 # Registering ################################################################
 
-def register_permission(name, codename, ctypes=[]):
+def register_permission(name, codename, ctypes=None):
     """Registers a permission to the framework. Returns the permission if the
     registration was successfully, otherwise False.
 
     **Parameters:**
 
-        name
-            The unique name of the permission. This is displayed to the
-            customer.
-        codename
-            The unique codename of the permission. This is used internally to
-            identify the permission.
-        content_types
-            The content type for which the permission is active. This can be
-            used to display only reasonable permissions for an object. This
-            must be a Django ContentType
+    name
+        The unique name of the permission. This is displayed to the customer.
+
+    codename
+        The unique codename of the permission. This is used internally to
+        identify the permission.
+
+    content_types
+        The content type for which the permission is active. This can be
+        used to display only reasonable permissions for an object. This
+        must be a Django ContentType
     """
+    if ctypes = None:
+        ctypes = []
+
     # Permission with same codename and/or name must not exist.
     if Permission.objects.filter(Q(name=name) | Q(codename=codename)):
         return False
 
     **Parameters:**
 
-        codename
-            The unique codename of the permission.
+    codename
+        The unique codename of the permission.
     """
     try:
         permission = Permission.objects.get(codename=codename)
 from setuptools import setup, find_packages
 import os
 
-version = '1.0'
+version = '1.0.3'
 
 here = os.path.abspath(os.path.dirname(__file__))
 README = open(os.path.join(here, 'README.txt')).read()
       description='Generic per-object permissions for Django',
       long_description=README,
       classifiers=[
-          'Development Status :: 4 - Beta',
+          'Development Status :: 5 - Production/Stable',
           'Environment :: Web Environment',
           'Framework :: Django',
           'License :: OSI Approved :: BSD License',