Commits

Kai Diefenbach  committed 583088e

Improved docstrings. Some adaptations for local roles

  • Participants
  • Parent commits f1785e6

Comments (0)

Files changed (3)

File workflows/models.py

 from django.db import models
 
 # django imports
-from django.contrib.auth.models import Group
 from django.contrib.contenttypes import generic
 from django.contrib.contenttypes.models import ContentType
 from django.utils.translation import ugettext_lazy as _
 
 # permissions imports
 from permissions.models import Permission
+from permissions.models import Role
 
 # workflows imports
 import workflows.utils
     workflow
         The workflow which is responsible for the permissions. Needs to be a
         Workflow instance.
+
     permission
         The permission for which the workflow is responsible. Needs to be a
         Permission instance.
     state
         The state for which the inheritance is blocked. Needs to be a State
         instance.
+
     permission
         The permission for which the instance is blocked. Needs to be a
         Permission instance.
         return "%s %s" % (self.state.name, self.permission.name)
 
 class StatePermissionRelation(models.Model):
-    """Stores granted permission for state and group.
+    """Stores granted permission for state and role.
 
     **Attributes:**
 
     state
-        The state for which the group has the permission. Needs to be a State
+        The state for which the role has the permission. Needs to be a State
         instance.
+
     permission
         The permission for which the workflow is responsible. Needs to be a
         Permission instance.
-    group
-        The group for which the state has the permission. Needs to be a Django
-        Group instance.
+
+    role
+        The role for which the state has the permission. Needs to be a lfc
+        Role instance.
     """
     state = models.ForeignKey(State, verbose_name=_(u"State"))
     permission = models.ForeignKey(Permission, verbose_name=_(u"Permission"))
-    group = models.ForeignKey(Group, verbose_name=_(u"Group"))
+    role = models.ForeignKey(Role, verbose_name=_(u"Role"))
 
     def __unicode__(self):
-        return "%s %s %s" % (self.state.name, self.group.name, self.permission.name)
+        return "%s %s %s" % (self.state.name, self.role.name, self.permission.name)

File workflows/tests.py

         """
         create_workflow(self)
 
-        # Register groups
-        self.anonymous = permissions.utils.register_group("Anonymous")
-        self.owner = permissions.utils.register_group("Owner")
+        # Register roles
+        self.anonymous = permissions.utils.register_role("Anonymous")
+        self.owner = permissions.utils.register_role("Owner")
 
         self.user = User.objects.create(username="john")
-        self.user.groups.add(self.owner)
-        self.user.save()
+        permissions.utils.add_role(self.user, self.owner)
 
         # Example content type
         self.page_1 = FlatPage.objects.create(url="/page-1/", title="Page 1")
         wpr = WorkflowPermissionRelation.objects.create(workflow=self.w, permission=self.edit)
 
         # Add permissions for single states
-        spr = StatePermissionRelation.objects.create(state=self.public, permission=self.view, group=self.owner)
-        spr = StatePermissionRelation.objects.create(state=self.private, permission=self.view, group=self.owner)
-        spr = StatePermissionRelation.objects.create(state=self.private, permission=self.edit, group=self.owner)
+        spr = StatePermissionRelation.objects.create(state=self.public, permission=self.view, role=self.owner)
+        spr = StatePermissionRelation.objects.create(state=self.private, permission=self.view, role=self.owner)
+        spr = StatePermissionRelation.objects.create(state=self.private, permission=self.edit, role=self.owner)
 
         # Add inheritance block for single states
         sib = StateInheritanceBlock.objects.create(state=self.private, permission=self.view)
         self.assertEqual(wpr.__unicode__(), "Standard View")
 
         # StatePermissionRelation
-        self.owner = permissions.utils.register_group("Owner")
-        spr = StatePermissionRelation.objects.create(state=self.public, permission=self.view, group=self.owner)
+        self.owner = permissions.utils.register_role("Owner")
+        spr = StatePermissionRelation.objects.create(state=self.public, permission=self.view, role=self.owner)
         self.assertEqual(spr.__unicode__(), "Public Owner View")
 
 # Helpers ####################################################################

File workflows/utils.py

 # django imports
-from django.contrib.auth.models import Group
 from django.contrib.contenttypes.models import ContentType
 
 # workflows imports
 
 # permissions imports
 import permissions.utils
+from permissions.models import Role
 
 def get_objects_for_workflow(workflow):
     """Returns all objects which have passed workflow.
     state = get_state(obj)
 
     # Remove all permissions for the workflow
-    for group in Group.objects.all():
+    for role in Role.objects.all():
         for wpr in WorkflowPermissionRelation.objects.filter(workflow=workflow):
-            permissions.utils.remove_permission(obj, wpr.permission, group)
+            permissions.utils.remove_permission(obj, wpr.permission, role)
 
     # Grant permission for the state
     for spr in StatePermissionRelation.objects.filter(state=state):
-        permissions.utils.grant_permission(obj, spr.permission, spr.group)
+        permissions.utils.grant_permission(obj, spr.permission, spr.role)
 
     # Remove all inheritance blocks from the object
     for wpr in WorkflowPermissionRelation.objects.filter(workflow=workflow):