示例#1
0
    def free_signals(self, request, queryset):
        filtered_signals = queryset.filter(status__state=workflow.VERZONDEN)

        with transaction.atomic():
            updated_signal_ids = []
            for signal in filtered_signals:
                new_status = Status(
                    _signal=signal,
                    state=workflow.AFGEHANDELD_EXTERN,
                    text='Vastgelopen melding vrijgegeven zonder tussenkomst CityControl.',
                    created_by=request.user.email
                )
                new_status.save()
                signal.status = new_status
                signal.save()
                updated_signal_ids.append(signal.id)

            if updated_signal_ids:
                msg = 'Successfully freed the following IDs: {}'.format(','.join(
                    str(_id) for _id in updated_signal_ids
                ))
            else:
                msg = 'No IDs were freed.'

            transaction.on_commit(lambda: self.message_user(request, msg))
示例#2
0
    def test_state_afgehandeld_text_required_invalid(self):
        new_status = Status(_signal=self.signal,
                            state=workflow.AFGEHANDELD,
                            text=None)

        with self.assertRaises(ValidationError) as error:
            new_status.full_clean()
        self.assertIn('text', error.exception.error_dict)
示例#3
0
    def test_state_transition_not_required_target_api(self):
        new_status = Status(_signal=self.signal,
                            state=workflow.ON_HOLD,
                            target_api=Status.TARGET_API_SIGMAX)

        with self.assertRaises(ValidationError) as error:
            new_status.full_clean()
        self.assertIn('target_api', error.exception.error_dict)
示例#4
0
    def test_state_te_verzenden_required_target_api_invalid_empty_choice(self):
        new_status = Status(_signal=self.signal,
                            state=workflow.TE_VERZENDEN,
                            target_api=None)

        with self.assertRaises(ValidationError) as error:
            new_status.full_clean()
        self.assertIn('target_api', error.exception.error_dict)
示例#5
0
    def validate(self, data):
        is_status_change_to_sigmax = (data['state'] == workflow.TE_VERZENDEN and
                                      data.get('target_api', None) == Status.TARGET_API_SIGMAX)
        if is_status_change_to_sigmax:
            request = self.context.get('request', None)
            if request and not request.user.has_perm('signals.push_to_sigmax'):
                raise PermissionDenied({
                    'state': "You don't have permissions to push to Sigmax/CityControl."
                })

        try:
            status = Status(**data)
            status.clean()
        except ValidationError as e:
            raise serializers.ValidationError(e.error_dict)

        return data
示例#6
0
def trigger_mail_action_for_email_preview(signal, status_data):
    """
    Helper function that will check which mail action will be triggered if a new status is requested.
    """
    from signals.apps.email_integrations.services import MailService

    # Create the "new" status we want to use to trigger the mail
    try:
        status = Status(_signal=signal, **status_data)
        status.full_clean()
        status.id = 0  # Fake id so that we still can trigger the action rule
    except ValidationError as e:
        raise convert_validation_error(e)

    subject = message = html_message = None
    for action in MailService._status_actions:
        # Execute the rule associated with the action
        if action.rule.validate(signal, status):
            # action found now render the subject, message and html_message and break the loop
            email_context = action.get_context(signal, dry_run=True)

            # overwrite the status context
            email_context.update({
                'status_text':
                status_data['text'],  # overwrite the status text
                'status_state':
                status_data['state'],  # overwrite the status state
                'afhandelings_text':
                status_data['text'],  # overwrite for the 'optional' action
                'reaction_request_answer':
                status_data[
                    'text'],  # overwrite for the 'reaction received' action
            })

            subject, message, html_message = action.render_mail_data(
                context=email_context)
            break

    if subject is None:
        raise NotFound(
            'No email preview available for given status transition')

    return subject, message, html_message
示例#7
0
    def test_state_te_verzenden_required_target_api_valid(self):
        new_status = Status(_signal=self.signal,
                            state=workflow.TE_VERZENDEN,
                            target_api=Status.TARGET_API_SIGMAX)
        new_status.full_clean()
        new_status.save()

        self.assertTrue(new_status.id)
示例#8
0
    def test_state_afgehandeld_text_required_valid(self):
        new_status = Status(_signal=self.signal,
                            state=workflow.BEHANDELING,
                            text='Working on it.')
        new_status.full_clean()
        new_status.save()

        self.signal.status = new_status
        self.signal.save()

        new_status = Status(_signal=self.signal,
                            state=workflow.AFGEHANDELD,
                            text='Done with it.')
        new_status.full_clean()
        new_status.save()

        self.assertTrue(new_status.id)
示例#9
0
    def test_state_transition_invalid(self):
        new_status = Status(_signal=self.signal, state=workflow.VERZONDEN)

        with self.assertRaises(ValidationError) as error:
            new_status.full_clean()
        self.assertIn('state', error.exception.error_dict)
示例#10
0
    def test_state_transition_valid(self):
        new_status = Status(_signal=self.signal, state=workflow.AFWACHTING)
        new_status.full_clean()
        new_status.save()

        self.assertTrue(new_status.id)