Exemple #1
0
    def process_mail_creation(self, session, tid, data):
        user_id = data['user']['id']
        language = data['user']['language']

        # Do not spool emails if the receiver has opted out of ntfns for this tip.
        if not data['tip']['enable_notifications']:
            log.debug("Discarding emails for %s due to receiver's preference.", user_id)
            return

        data['node'] = self.serialize_config(session, 'node', tid, language)

        data['submission_statuses'] = db_get_submission_statuses(session, tid, language)

        if data['node']['mode'] == 'default':
            data['notification'] = self.serialize_config(session, 'notification', tid, language)
        else:
            data['notification'] = self.serialize_config(session, 'notification', 1, language)

        subject, body = Templating().get_mail_subject_and_body(data)

        # If the receiver has encryption enabled encrypt the mail body
        if data['user']['pgp_key_public']:
            pgpctx = PGPContext(self.state.settings.tmp_path)
            fingerprint = pgpctx.load_key(data['user']['pgp_key_public'])['fingerprint']
            body = pgpctx.encrypt_message(fingerprint, body)

        session.add(models.Mail({
            'address': data['user']['mail_address'],
            'subject': subject,
            'body': body,
            'tid': tid,
        }))
Exemple #2
0
def get_public_resources(session, tid, language):
    """
    Transaction that compose the public API

    :param session: An ORM session
    :param tid: The tenant ID
    :param language: The language to be used for serialization
    :return: The public API descriptor
    """
    return {
        'node': db_serialize_node(session, tid, language),
        'contexts': db_get_contexts(session, tid, language),
        'questionnaires': db_get_questionnaires(session, tid, language),
        'receivers': db_get_receivers(session, tid, language),
        'submission_statuses':
        db_get_submission_statuses(session, tid, language)
    }
Exemple #3
0
def get_tip_export(session, tid, user_id, rtip_id, language):
    rtip, itip = db_access_rtip(session, tid, user_id, rtip_id)

    user, context = session.query(models.User, models.Context) \
                           .filter(models.User.id == rtip.receiver_id,
                                   models.Context.id == models.InternalTip.context_id,
                                   models.InternalTip.id == rtip.internaltip_id,
                                   models.User.tid == tid).one()

    rtip_dict = serialize_rtip(session, rtip, itip, language)

    return {
        'type': 'export_template',
        'node': db_admin_serialize_node(session, tid, language),
        'notification': db_get_notification(session, tid, language),
        'tip': rtip_dict,
        'crypto_tip_prv_key': Base64Encoder.decode(rtip.crypto_tip_prv_key),
        'user': user_serialize_user(session, user, language),
        'context': admin_serialize_context(session, context, language),
        'submission_statuses':
        db_get_submission_statuses(session, tid, language)
    }