Exemplo n.º 1
0
 def get_applications_for_reviewer(self, reviewer, state=None):
     '''
         Returns the applications that the user is a reviewer for
         
         @param reviewer: The user object for the reviewer.
         @param state: If specified then the returned list will be filtered so that only
         applications in this state are retunred. If the state cannot be resolved then all
         applications will be retunred.
     '''
     reviewer_code= getattr(settings, 'REVIEWER_ROLE', None)
     
     if isinstance(state, str):
         try:
             state = State.objects.get(name=state)
         except ObjectDoesNotExist:
             state = None
     
     if reviewer_code != None:
         try:
             reviewer_role = Role.objects.get(name=reviewer_code)  
             
             applications = get_object_for_principle_as_role(principle=reviewer, principle_role=reviewer_role)           
             
             
             if state == None:
                 return applications 
             else:
                 return self._filter_applications_on_state(applications, state)
                 
         except ObjectDoesNotExist:
             raise ImproperlyConfigured('The workflow you specify in REVIEWER_ROLE must actually be configured in the db')
     else:
         raise ImproperlyConfigured('You must set REVIEWER_ROLE in the settings file')
     
     return []
Exemplo n.º 2
0
 def test_get_object_for_principle_as_role_none(self):
     
     '''
         If the principle is a not a member of any roles then an empty list should be
         returned.
     '''
     objects = get_object_for_principle_as_role(principle=self.test_principle, principle_role=self.tester_role)
     self.assertEqual(objects, [])
Exemplo n.º 3
0
 def test_get_object_for_principle_as_role_string_role(self):
     '''
         If you specify a string instead of a role then this function should
         look up the role using the sting as the role name
     
     '''
     an_object = Permission.objects.create(name='an_object', codename='an_object')
     add_local_role(an_object, self.test_principle, self.tester_role)
     
     another_object = Permission.objects.create(name='another_object', codename='another_object')
     add_local_role(another_object, self.test_principle, self.tester_role)
     
     objects = get_object_for_principle_as_role(principle=self.test_principle, principle_role='testRole')
     
     self.assertTrue(an_object in objects)
     self.assertTrue(another_object in objects)
Exemplo n.º 4
0
 def test_get_object_for_principle_as_role_local(self):
     '''
         If the principle is a member of a local role for a given object then
         this object should be returned.
         
         This test is difficult to do:
         1. You need to have a model to test against
             can we use one of the models that the permissions package defines?
         
     '''
     an_object = Permission.objects.create(name='an_object', codename='an_object')
     add_local_role(an_object, self.test_principle, self.tester_role)
     
     another_object = Permission.objects.create(name='another_object', codename='another_object')
     add_local_role(another_object, self.test_principle, self.tester_role)
     
     objects = get_object_for_principle_as_role(principle=self.test_principle, principle_role=self.tester_role)
     
     self.assertTrue(an_object in objects)
     self.assertTrue(another_object in objects)
Exemplo n.º 5
0
    def get_applications_for_reviewer(self, reviewer, state=None):
        '''
            Returns the applications that the user is a reviewer for
            
            @param reviewer: The user object for the reviewer.
            @param state: If specified then the returned list will be filtered so that only
            applications in this state are retunred. If the state cannot be resolved then all
            applications will be retunred.
        '''
        reviewer_code = getattr(settings, 'REVIEWER_ROLE', None)

        if isinstance(state, str):
            try:
                state = State.objects.get(name=state)
            except ObjectDoesNotExist:
                state = None

        if reviewer_code != None:
            try:
                reviewer_role = Role.objects.get(name=reviewer_code)

                applications = get_object_for_principle_as_role(
                    principle=reviewer, principle_role=reviewer_role)

                if state == None:
                    return applications
                else:
                    return self._filter_applications_on_state(
                        applications, state)

            except ObjectDoesNotExist:
                raise ImproperlyConfigured(
                    'The workflow you specify in REVIEWER_ROLE must actually be configured in the db'
                )
        else:
            raise ImproperlyConfigured(
                'You must set REVIEWER_ROLE in the settings file')

        return []