Example #1
0
def send_json_list(
    user,
    action: Action,
    action_info: Mapping,
    log_item: Optional[Log] = None,
):
    """Send single json object to target URL.

    Sends a single json object to the URL in the action

    :param user: User object that executed the action

    :param action: Action from where to take the messages

    :param log_item: Log object to store results

    :param action_info: Object with the additional parameters

    :return: Empty list (there are no column values for multiple sends)
    """
    # Evaluate the action string and obtain the list of list of JSON objects
    action_text = evaluate_row_action_out(
        action, get_action_evaluation_context(action, {}))

    _send_and_log_json(
        user, action, json.loads(action_text), {
            'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'Authorization': 'Bearer {0}'.format(action_info['token']),
        }, {
            'user': user.id,
            'action': action.id
        })

    return []
Example #2
0
def send_json_list(
    user,
    action: Action,
    log_item: Log,
    action_info: Mapping,
):
    """Send single json object to target URL.

    Sends a single json object to the URL in the action

    :param user: User object that executed the action

    :param action: Action from where to take the messages

    :param log_item: Log object to store results

    :param action_info: Object with the additional parameters

    :return: Nothing
    """
    # Evaluate the action string and obtain the list of list of JSON objects
    action_text = evaluate_row_action_out(
        action,
        get_action_evaluation_context(action, {}))

    _send_and_log_json(
        user,
        action,
        json.loads(action_text),
        {
            'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'Authorization': 'Bearer {0}'.format(action_info['token']),
        },
        {'user': user.id, 'action': action.id})

    # Update data in the overall log item
    log_item.payload['filter_present'] = action.get_filter() is not None
    log_item.payload['datetime'] = str(
        datetime.datetime.now(pytz.timezone(settings.TIME_ZONE)))
    log_item.save()
Example #3
0
    def execute_operation(
        self,
        user,
        workflow: Optional[models.Workflow] = None,
        action: Optional[models.Action] = None,
        payload: Optional[Dict] = None,
        log_item: Optional[models.Log] = None,
    ):
        """Send action content evaluated once to include lists.

        Sends a single email for the given action with the lists expanded and
        with the given subject evaluated also with respect to the attributes.

        :param user: User object that executed the action
        :param workflow: Optional object
        :param action: Action from where to take the messages
        :param log_item: Log object to store results
        :param payload: Dictionary key, value
        :return: Nothing
        """
        if log_item is None:
            action.log(user, self.log_event, **payload)

        # Evaluate the action string, evaluate the subject, and get the value
        # of the email column.
        action_text = evaluate_row_action_out(
            action, get_action_evaluation_context(action, {}))

        cc_email = _check_email_list(payload['cc_email'])
        bcc_email = _check_email_list(payload['bcc_email'])

        # Context to log the events
        msg = _create_single_message(
            [action_text, payload['subject'], payload['email_to']],
            '',
            user.email,
            cc_email,
            bcc_email,
            attachments=action.attachments.all(),
            filter_formula=action.get_filter_formula())

        try:
            # Send email out
            mail.get_connection().send_messages([msg])
        except Exception as exc:
            raise Exception(
                _('Error when sending the list email: {0}').format(str(exc)), )

        # Log the event
        context = {
            'action':
            action.id,
            'subject':
            msg.subject,
            'body':
            msg.body,
            'from_email':
            msg.from_email,
            'to_email':
            msg.to[0],
            'email_sent_datetime':
            str(datetime.datetime.now(pytz.timezone(settings.TIME_ZONE)))
        }
        action.last_executed_log = action.log(user,
                                              models.Log.ACTION_EMAIL_SENT,
                                              **context)
        action.save(update_fields=['last_executed_log'])
Example #4
0
def send_list_email(
    user,
    action: Action,
    action_info: Dict,
    log_item: Optional[Log] = None,
) -> List[str]:
    """Send action content evaluated once to include lists.

    Sends a single email for the given action with the lists expanded and with
    the given subject evaluated also with respect to the attributes.

    :param user: User object that executed the action
    :param action: Action from where to take the messages
    :param log_item: Log object to store results
    :param action_info: Dictionary key, value as defined in EmailPayload

    :return: Empty list (because it is a single email sent)
    """
    # Evaluate the action string, evaluate the subject, and get the value of
    # the email column.
    action_text = evaluate_row_action_out(
        action, get_action_evaluation_context(action, {}))

    # Turn cc_email and bcc email into lists
    action_info['cc_email'] = action_info['cc_email'].split()
    action_info['bcc_email'] = action_info['bcc_email'].split()

    _check_cc_lists(action_info['cc_email'], action_info['bcc_email'])

    # Context to log the events
    msg = _create_single_message(
        [action_text, action_info['subject'], action_info['email_to']],
        '',
        user.email,
        action_info['cc_email'],
        action_info['bcc_email'],
    )

    try:
        # Send email out
        mail.get_connection().send_messages([msg])
    except Exception as exc:
        raise Exception(
            _('Error when sending the list email: {0}').format(str(exc)), )

    # Log the event
    context = {
        'email_sent_datetime':
        str(datetime.datetime.now(pytz.timezone(settings.TIME_ZONE)), ),
        'subject':
        msg.subject,
        'body':
        msg.body,
        'from_email':
        msg.from_email,
        'to_email':
        msg.to[0]
    }
    action.log(user, Log.ACTION_EMAIL_SENT, **context)

    return []