Beispiel #1
0
        def process(workflow_object, field, user, action, next_state=None, god_mod=False):
            current_state = getattr(workflow_object, field)
            proceedings = ProceedingService.get_available_proceedings(workflow_object, field, [current_state],
                                                                      user=user, god_mod=god_mod)
            c = proceedings.count()
            if c == 0:
                raise RiverException(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER,
                                     "There is no available state for destination for the user.")
            if c > 1:
                if next_state:
                    proceedings = proceedings.filter(meta__transition__destination_state=next_state)
                    if proceedings.count() == 0:
                        available_states = StateService.get_available_states(workflow_object, field, user)
                        raise RiverException(ErrorCode.INVALID_NEXT_STATE_FOR_USER,
                                             "Invalid state is given(%s). Valid states is(are) %s" % (
                                                 next_state.__unicode__(),
                                                 ','.join([ast.__unicode__() for ast in available_states])))
                else:
                    raise RiverException(ErrorCode.NEXT_STATE_IS_REQUIRED,
                                         "State must be given when there are multiple states for destination")
            proceeding = proceedings[0]
            proceeding.status = action
            proceeding.transactioner = user
            proceeding.transaction_date = datetime.now()
            if workflow_object.proceeding:
                proceeding.previous = workflow_object.proceeding
            proceeding.save()


            return proceeding
Beispiel #2
0
    def process(workflow_object, field, user, action, next_state=None, god_mod=False):
        current_state = getattr(workflow_object, field)
        approvements = ApprovementService.get_approvements_object_waiting_for_approval(workflow_object, field, [current_state], user=user, god_mod=god_mod)
        c = approvements.count()
        if c == 0:
            raise RiverException(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER, "There is no available state for destination for the user.")
        if c > 1:
            if next_state:
                approvements = approvements.filter(meta__transition__destination_state=next_state)
                if approvements.count() == 0:
                    available_states = StateService.get_available_states(workflow_object, field, user)
                    raise RiverException(ErrorCode.INVALID_NEXT_STATE_FOR_USER,
                                         "Invalid state is given(%s). Valid states is(are) %s" % (next_state.__unicode__(), ','.join([ast.__unicode__() for ast in available_states])))
            else:
                raise RiverException(ErrorCode.NEXT_STATE_IS_REQUIRED, "State must be given when there are multiple states for destination")
        approvement = approvements[0]
        approvement.status = action
        approvement.transactioner = user
        approvement.transaction_date = datetime.now()
        approvement.save()

        c = False
        track = workflow_object.approvement_track
        while not c:
            track, c = approvement.tracks.get_or_create(previous_track=track)
        return approvement, track
Beispiel #3
0
        def process(workflow_object, user, action, next_state=None, god_mod=False):
            proceedings = ProceedingService.get_available_proceedings(
                workflow_object, [workflow_object.get_state()], user=user, god_mod=god_mod)
            c = proceedings.count()
            if c == 0:
                raise RiverException(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER,
                                     "There is no available state for destination for the user.")
            if c > 1:
                if next_state:
                    proceedings = proceedings.filter(meta__transition__destination_state=next_state)
                    if proceedings.count() == 0:
                        available_states = StateService.get_available_states(workflow_object, user)
                        raise RiverException(ErrorCode.INVALID_NEXT_STATE_FOR_USER, "Invalid state is given(%s). Valid states is(are) %s" % (
                            next_state.__str__(), ','.join([ast.__str__() for ast in available_states])))
                else:
                    raise RiverException(ErrorCode.NEXT_STATE_IS_REQUIRED,
                                         "State must be given when there are multiple states for destination")
            proceeding = proceedings[0]
            proceeding.status = action
            proceeding.transactioner = user
            proceeding.transaction_date = timezone.now()
            if workflow_object.proceeding:
                proceeding.previous = workflow_object.proceeding
            proceeding.save()

            return proceeding
Beispiel #4
0
    def process(workflow_object,
                field,
                user,
                action,
                next_state=None,
                god_mod=False):
        current_state = getattr(workflow_object, field)
        approvements = ApprovementService.get_approvements_object_waiting_for_approval(
            workflow_object,
            field, [current_state],
            user=user,
            god_mod=god_mod)
        c = approvements.count()
        if c == 0:
            raise RiverException(
                ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER,
                "There is no available state for destination for the user.")
        if c > 1:
            if next_state:
                approvements = approvements.filter(
                    meta__transition__destination_state=next_state)
                if approvements.count() == 0:
                    available_states = StateService.get_available_states(
                        workflow_object, field, user)
                    raise RiverException(
                        ErrorCode.INVALID_NEXT_STATE_FOR_USER,
                        "Invalid state is given(%s). Valid states is(are) %s" %
                        (next_state.__unicode__(), ','.join(
                            [ast.__unicode__() for ast in available_states])))
            else:
                raise RiverException(
                    ErrorCode.NEXT_STATE_IS_REQUIRED,
                    "State must be given when there are multiple states for destination"
                )
        approvement = approvements[0]
        approvement.status = action
        approvement.transactioner = user
        approvement.transaction_date = datetime.now()
        approvement.save()

        c = False
        track = workflow_object.approvement_track
        while not c:
            track, c = approvement.tracks.get_or_create(previous_track=track)
        return approvement, track
Beispiel #5
0
    def test_get_available_states(self):
        self.initialize_normal_scenario()

        ObjectService.register_object(self.objects[0])
        ObjectService.register_object(self.objects[1])

        available_states = StateService.get_available_states(
            self.objects[0], self.user2, include_user=False)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])
        available_states = StateService.get_available_states(self.objects[0],
                                                             self.user2,
                                                             include_user=True)
        self.assertEqual(0, available_states.count())
        available_states = StateService.get_available_states(
            self.objects[0], self.user2)
        self.assertEqual(0, available_states.count())

        available_states = StateService.get_available_states(
            self.objects[0], self.user3, include_user=False)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])
        available_states = StateService.get_available_states(self.objects[0],
                                                             self.user3,
                                                             include_user=True)
        self.assertEqual(0, available_states.count())
        available_states = StateService.get_available_states(
            self.objects[0], self.user3)
        self.assertEqual(0, available_states.count())

        available_states = StateService.get_available_states(
            self.objects[0], self.user4, include_user=False)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])
        available_states = StateService.get_available_states(self.objects[0],
                                                             self.user4,
                                                             include_user=True)
        self.assertEqual(0, available_states.count())
        available_states = StateService.get_available_states(
            self.objects[0], self.user4)
        self.assertEqual(0, available_states.count())

        available_states = StateService.get_available_states(
            self.objects[0], self.user1, include_user=False)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])
        available_states = StateService.get_available_states(self.objects[0],
                                                             self.user1,
                                                             include_user=True)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])

        available_states = StateService.get_available_states(
            self.objects[0], self.user1)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])
    def test_get_available_states(self):
        ObjectService.register_object(self.objects[0], self.field)
        ObjectService.register_object(self.objects[1], self.field)

        available_states = StateService.get_available_states(
            self.objects[0], self.field, self.user2, include_user=False)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])
        available_states = StateService.get_available_states(self.objects[0],
                                                             self.field,
                                                             self.user2,
                                                             include_user=True)
        self.assertEqual(0, available_states.count())
        available_states = StateService.get_available_states(
            self.objects[0], self.field, self.user2)
        self.assertEqual(0, available_states.count())

        available_states = StateService.get_available_states(
            self.objects[0], self.field, self.user3, include_user=False)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])
        available_states = StateService.get_available_states(self.objects[0],
                                                             self.field,
                                                             self.user3,
                                                             include_user=True)
        self.assertEqual(0, available_states.count())
        available_states = StateService.get_available_states(
            self.objects[0], self.field, self.user3)
        self.assertEqual(0, available_states.count())

        available_states = StateService.get_available_states(
            self.objects[0], self.field, self.user4, include_user=False)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])
        available_states = StateService.get_available_states(self.objects[0],
                                                             self.field,
                                                             self.user4,
                                                             include_user=True)
        self.assertEqual(0, available_states.count())
        available_states = StateService.get_available_states(
            self.objects[0], self.field, self.user4)
        self.assertEqual(0, available_states.count())

        available_states = StateService.get_available_states(
            self.objects[0], self.field, self.user1, include_user=False)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])
        available_states = StateService.get_available_states(self.objects[0],
                                                             self.field,
                                                             self.user1,
                                                             include_user=True)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])

        available_states = StateService.get_available_states(
            self.objects[0], self.field, self.user1)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])
Beispiel #7
0
    def test_get_available_states(self):
        ObjectService.register_object(self.objects[0], self.field)
        ObjectService.register_object(self.objects[1], self.field)

        available_states = StateService.get_available_states(self.objects[0], self.field, self.user2, include_user=False)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])
        available_states = StateService.get_available_states(self.objects[0], self.field, self.user2, include_user=True)
        self.assertEqual(0, available_states.count())
        available_states = StateService.get_available_states(self.objects[0], self.field, self.user2)
        self.assertEqual(0, available_states.count())

        available_states = StateService.get_available_states(self.objects[0], self.field, self.user3, include_user=False)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])
        available_states = StateService.get_available_states(self.objects[0], self.field, self.user3, include_user=True)
        self.assertEqual(0, available_states.count())
        available_states = StateService.get_available_states(self.objects[0], self.field, self.user3)
        self.assertEqual(0, available_states.count())

        available_states = StateService.get_available_states(self.objects[0], self.field, self.user4, include_user=False)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])
        available_states = StateService.get_available_states(self.objects[0], self.field, self.user4, include_user=True)
        self.assertEqual(0, available_states.count())
        available_states = StateService.get_available_states(self.objects[0], self.field, self.user4)
        self.assertEqual(0, available_states.count())

        available_states = StateService.get_available_states(self.objects[0], self.field, self.user1, include_user=False)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])
        available_states = StateService.get_available_states(self.objects[0], self.field, self.user1, include_user=True)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])

        available_states = StateService.get_available_states(self.objects[0], self.field, self.user1)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])
    def test_get_available_states(self):
        self.initialize_normal_scenario()

        ObjectService.register_object(self.objects[0])
        ObjectService.register_object(self.objects[1])

        available_states = StateService.get_available_states(self.objects[0], self.user2, include_user=False)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])
        available_states = StateService.get_available_states(self.objects[0], self.user2, include_user=True)
        self.assertEqual(0, available_states.count())
        available_states = StateService.get_available_states(self.objects[0], self.user2)
        self.assertEqual(0, available_states.count())

        available_states = StateService.get_available_states(self.objects[0], self.user3, include_user=False)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])
        available_states = StateService.get_available_states(self.objects[0], self.user3, include_user=True)
        self.assertEqual(0, available_states.count())
        available_states = StateService.get_available_states(self.objects[0], self.user3)
        self.assertEqual(0, available_states.count())

        available_states = StateService.get_available_states(self.objects[0], self.user4, include_user=False)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])
        available_states = StateService.get_available_states(self.objects[0], self.user4, include_user=True)
        self.assertEqual(0, available_states.count())
        available_states = StateService.get_available_states(self.objects[0], self.user4)
        self.assertEqual(0, available_states.count())

        available_states = StateService.get_available_states(self.objects[0], self.user1, include_user=False)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])
        available_states = StateService.get_available_states(self.objects[0], self.user1, include_user=True)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])

        available_states = StateService.get_available_states(self.objects[0], self.user1)
        self.assertEqual(1, available_states.count())
        self.assertEqual(State.objects.get(label='s2'), available_states[0])