Пример #1
0
def serialize_itip(store, internaltip, language):
    context = internaltip.context
    mo = Rosetta(context.localized_keys)
    mo.acquire_storm_object(context)

    return {
        'id': internaltip.id,
        'creation_date': datetime_to_ISO8601(internaltip.creation_date),
        'update_date': datetime_to_ISO8601(internaltip.update_date),
        'expiration_date': datetime_to_ISO8601(internaltip.expiration_date),
        'progressive': internaltip.progressive,
        'sequence_number': get_submission_sequence_number(internaltip),
        'context_id': internaltip.context_id,
        'context_name': mo.dump_localized_key('name', language),
        'questionnaire': db_get_archived_questionnaire_schema(store, internaltip.questionnaire_hash, language),
        'receivers': db_get_itip_receiver_list(store, internaltip, language),
        'tor2web': internaltip.tor2web,
        'timetolive': context.tip_timetolive,
        'enable_comments': context.enable_comments,
        'enable_messages': context.enable_messages,
        'enable_two_way_comments': internaltip.enable_two_way_comments,
        'enable_two_way_messages': internaltip.enable_two_way_messages,
        'enable_attachments': internaltip.enable_attachments,
        'enable_whistleblower_identity': internaltip.enable_whistleblower_identity,
        'identity_provided': internaltip.identity_provided,
        'identity_provided_date': datetime_to_ISO8601(internaltip.identity_provided_date),
        'show_recipients_details': context.show_recipients_details,
        'status_page_message': mo.dump_localized_key('status_page_message', language),
        'wb_last_access': datetime_to_ISO8601(internaltip.wb_last_access),
        'wb_access_revoked': internaltip.is_wb_access_revoked()
    }
Пример #2
0
def receiver_serialize_receiver(receiver, language):
    ret_dict = {
        "id": receiver.id,
        "name": receiver.name,
        "update_date": datetime_to_ISO8601(receiver.last_update),
        "creation_date": datetime_to_ISO8601(receiver.creation_date),
        "can_delete_submission": receiver.can_delete_submission,
        "username": receiver.user.username,
        "gpg_key_info": receiver.gpg_key_info,
        "gpg_key_fingerprint": receiver.gpg_key_fingerprint,
        "gpg_key_remove": False,
        "gpg_key_armor": receiver.gpg_key_armor,
        "gpg_key_expiration": datetime_to_ISO8601(receiver.gpg_key_expiration),
        "gpg_key_status": receiver.gpg_key_status,
        "tip_notification" : receiver.tip_notification,
        "file_notification" : receiver.file_notification,
        "comment_notification" : receiver.comment_notification,
        "message_notification" : receiver.message_notification,
        "ping_notification": receiver.ping_notification,
        "mail_address": receiver.mail_address,
        "ping_mail_address": receiver.ping_mail_address,
        "contexts": [c.id for c in receiver.contexts],
        "password": u"",
        "old_password": u"",
        "language": receiver.user.language,
        "timezone": receiver.user.timezone
    }

    for context in receiver.contexts:
        ret_dict['contexts'].append(context.id)

    return get_localized_values(ret_dict, receiver, receiver.localized_strings, language)
Пример #3
0
def serialize_itip(store, internaltip, language):
    context = internaltip.context
    mo = Rosetta(context.localized_keys)
    mo.acquire_storm_object(context)

    return {
        "id": internaltip.id,
        "creation_date": datetime_to_ISO8601(internaltip.creation_date),
        "update_date": datetime_to_ISO8601(internaltip.update_date),
        "expiration_date": datetime_to_ISO8601(internaltip.expiration_date),
        "progressive": internaltip.progressive,
        "context_id": internaltip.context_id,
        "context_name": mo.dump_localized_key("name", language),
        "questionnaire": db_get_archived_questionnaire_schema(store, internaltip.questionnaire_hash, language),
        "tor2web": internaltip.tor2web,
        "timetolive": context.tip_timetolive,
        "enable_comments": context.enable_comments,
        "enable_messages": context.enable_messages,
        "enable_two_way_comments": internaltip.enable_two_way_comments,
        "enable_two_way_messages": internaltip.enable_two_way_messages,
        "enable_attachments": internaltip.enable_attachments,
        "enable_whistleblower_identity": internaltip.enable_whistleblower_identity,
        "identity_provided": internaltip.identity_provided,
        "identity_provided_date": datetime_to_ISO8601(internaltip.identity_provided_date),
        "show_receivers": context.show_receivers,
    }
Пример #4
0
def receiver_serialize_file(internalfile, receiverfile, receivertip_id):
    """
    ReceiverFile is the mixing between the metadata present in InternalFile
    and the Receiver-dependent, and for the client sake receivertip_id is
    required to create the download link
    """
    wb_download_date = None
    if internalfile.wb_download_date:
        wb_download_date = datetime_to_ISO8601(internalfile.wb_download_date)

    if receiverfile.status != 'unavailable':

        ret_dict = {
            'id':
            receiverfile.id,
            'internalfile_id':
            internalfile.id,
            'status':
            receiverfile.status,
            'href':
            "/rtip/" + receivertip_id + "/download/" + receiverfile.id,
            # if the ReceiverFile has encrypted status, we append ".pgp" to the filename, to avoid mistake on Receiver side.
            'name': ("%s.pgp" % internalfile.name)
            if receiverfile.status == u'encrypted' else internalfile.name,
            'content_type':
            internalfile.content_type,
            'creation_date':
            datetime_to_ISO8601(internalfile.creation_date),
            'size':
            receiverfile.size,
            'downloads':
            receiverfile.downloads,
            'is_visible':
            internalfile.is_visible,
            'description':
            internalfile.description,
            'wb_download_date':
            wb_download_date
        }

    else:  # == 'unavailable' in this case internal file metadata is returned.

        ret_dict = {
            'id': receiverfile.id,
            'internalfile_id': internalfile.id,
            'status': 'unavailable',
            'href': "",
            'name': internalfile.name,  # original filename
            'content_type': internalfile.content_type,  # original content size
            'creation_date': datetime_to_ISO8601(
                internalfile.creation_date),  # original creation_date
            'size': int(internalfile.size),  # original filesize
            'downloads':
            unicode(receiverfile.downloads),  # this counter is always valid
            'is_visible': internalfile.is_visible,
            'description': internalfile.description,
            'wb_download_date': wb_download_date
        }

    return ret_dict
Пример #5
0
def serialize_itip(session, internaltip, language):
    x = session.query(models.InternalTipAnswers, models.ArchivedSchema) \
               .filter(models.ArchivedSchema.hash == models.InternalTipAnswers.questionnaire_hash,
                       models.InternalTipAnswers.internaltip_id == internaltip.id)

    questionnaires = []
    for ita, aqs in x:
        questionnaires.append({
            'steps': db_serialize_archived_questionnaire_schema(aqs.schema, language),
            'answers': ita.answers
        })

    wb_access_revoked = session.query(models.WhistleblowerTip).filter(models.WhistleblowerTip.id == internaltip.id).count() == 0

    return {
        'id': internaltip.id,
        'creation_date': datetime_to_ISO8601(internaltip.creation_date),
        'update_date': datetime_to_ISO8601(internaltip.update_date),
        'expiration_date': datetime_to_ISO8601(internaltip.expiration_date),
        'progressive': internaltip.progressive,
        'context_id': internaltip.context_id,
        'additional_questionnaire_id': internaltip.additional_questionnaire_id,
        'questionnaires': questionnaires,
        'receivers': db_get_itip_receiver_list(session, internaltip),
        'https': internaltip.https,
        'enable_two_way_comments': internaltip.enable_two_way_comments,
        'enable_two_way_messages': internaltip.enable_two_way_messages,
        'enable_attachments': internaltip.enable_attachments,
        'enable_whistleblower_identity': internaltip.enable_whistleblower_identity,
        'wb_last_access': datetime_to_ISO8601(internaltip.wb_last_access),
        'wb_access_revoked': wb_access_revoked,
        'score': internaltip.total_score,
        'status': internaltip.status,
        'substatus': internaltip.substatus
    }
Пример #6
0
 def test_datetime_to_ISO8601_to_datetime_to_dot_dot_dot(self):
     a = utility.datetime_null()
     b = utility.datetime_to_ISO8601(a)
     c = utility.ISO8601_to_datetime(b)
     d = utility.datetime_to_ISO8601(c)
     self.assertTrue(a, c)
     self.assertTrue(b, d)
Пример #7
0
def get_receivertip_list(store, receiver_id, language):
    rtip_summary_list = []

    for rtip in store.find(ReceiverTip, ReceiverTip.receiver_id == receiver_id):
        mo = Rosetta(rtip.internaltip.context.localized_keys)
        mo.acquire_storm_object(rtip.internaltip.context)

        rtip_summary_list.append({
            'id': rtip.id,
            'creation_date': datetime_to_ISO8601(rtip.internaltip.creation_date),
            'last_access': datetime_to_ISO8601(rtip.last_access),
            'update_date': datetime_to_ISO8601(rtip.internaltip.update_date),
            'expiration_date': datetime_to_ISO8601(rtip.internaltip.expiration_date),
            'timetolive': rtip.internaltip.context.tip_timetolive,
            'progressive': rtip.internaltip.progressive,
            'new': rtip.access_counter == 0 or rtip.last_access < rtip.internaltip.update_date,
            'context_name': mo.dump_localized_key('name', language),
            'access_counter': rtip.access_counter,
            'file_counter': rtip.internaltip.internalfiles.count(),
            'comment_counter': rtip.internaltip.comments.count(),
            'message_counter': rtip.messages.count(),
            'tor2web': rtip.internaltip.tor2web,
            'questionnaire_hash': rtip.internaltip.questionnaire_hash,
            'preview_schema': db_get_archived_preview_schema(store, rtip.internaltip.questionnaire_hash, language),
            'preview': rtip.internaltip.preview,
            'total_score': rtip.internaltip.total_score,
            'label': rtip.label
        })

    return rtip_summary_list
Пример #8
0
def receiver_serialize_rfile(receiverfile):
    internalfile = receiverfile.internalfile

    if receiverfile.status != 'unavailable':
        ret_dict = {
            'id': receiverfile.id,
            'internalfile_id': internalfile.id,
            'status': receiverfile.status,
            'href': "/rtip/" + receiverfile.receivertip_id + "/download/" + receiverfile.id,
            # if the ReceiverFile has encrypted status, we append ".pgp" to the filename, to avoid mistake on Receiver side.
            'name': ("%s.pgp" % internalfile.name) if receiverfile.status == u'encrypted' else internalfile.name,
            'content_type': internalfile.content_type,
            'creation_date': datetime_to_ISO8601(internalfile.creation_date),
            'size': receiverfile.size,
            'downloads': receiverfile.downloads
        }

    else:  # == 'unavailable' in this case internal file metadata is returned.
        ret_dict = {
            'id': receiverfile.id,
            'internalfile_id': internalfile.id,
            'status': 'unavailable',
            'href': "",
            'name': internalfile.name,
            'content_type': internalfile.content_type,
            'creation_date': datetime_to_ISO8601(internalfile.creation_date),
            'size': int(internalfile.size),
            'downloads': receiverfile.downloads
        }

    return ret_dict
Пример #9
0
def receiver_serialize_internal_tip(
        internaltip, language=GLSetting.memory_copy.default_language):

    itip_dict = {
        'context_id': internaltip.context.id,
        'creation_date' : datetime_to_ISO8601(internaltip.creation_date),
        'expiration_date' : datetime_to_ISO8601(internaltip.expiration_date),
        'download_limit' : internaltip.download_limit,
        'access_limit' : internaltip.access_limit,
        'mark' : internaltip.mark,
        'pertinence' : internaltip.pertinence_counter,
        'escalation_threshold' : internaltip.escalation_threshold,
        'fields' : internaltip.wb_fields,

        # these two fields are at the moment unsent by the client, but kept
        # maintained in unitTest. (tickets in wishlist)
        'is_pertinent' : False,
        'global_delete' : False,
        # this field "inform" the receiver of the new expiration date that can
        # be set, only if PUT with extend = True is updated
        'potential_expiration_date' : \
            datetime_to_ISO8601(utc_future_date(seconds=internaltip.context.tip_timetolive)),
        'extend' : False,
    }

    # context_name and context_description are localized field
    mo = Rosetta()
    mo.acquire_storm_object(internaltip.context)
    for attr in ['name', 'description']:
        key = "context_%s" % attr
        itip_dict[key] = mo.dump_translated(attr, language)

    return itip_dict
Пример #10
0
def receiver_serialize_rfile(receiverfile):
    internalfile = receiverfile.internalfile

    if receiverfile.status != 'unavailable':
        ret_dict = {
            'id': receiverfile.id,
            'internalfile_id': internalfile.id,
            'status': receiverfile.status,
            'href': "/rtip/" + receiverfile.receivertip_id + "/download/" + receiverfile.id,
            # if the ReceiverFile has encrypted status, we append ".pgp" to the filename, to avoid mistake on Receiver side.
            'name': ("%s.pgp" % internalfile.name) if receiverfile.status == u'encrypted' else internalfile.name,
            'content_type': internalfile.content_type,
            'creation_date': datetime_to_ISO8601(internalfile.creation_date),
            'size': receiverfile.size,
            'downloads': receiverfile.downloads
        }

    else:  # == 'unavailable' in this case internal file metadata is returned.
        ret_dict = {
            'id': receiverfile.id,
            'internalfile_id': internalfile.id,
            'status': 'unavailable',
            'href': "",
            'name': internalfile.name,
            'content_type': internalfile.content_type,
            'creation_date': datetime_to_ISO8601(internalfile.creation_date),
            'size': int(internalfile.size),
            'downloads': receiverfile.downloads
        }

    return ret_dict
Пример #11
0
def receiver_serialize_receiver(receiver, language=GLSetting.memory_copy.default_language):
    ret_dict = {
        "id": receiver.id,
        "name": receiver.name,
        "update_date": datetime_to_ISO8601(receiver.last_update),
        "creation_date": datetime_to_ISO8601(receiver.creation_date),
        "can_delete_submission": receiver.can_delete_submission,
        "username": receiver.user.username,
        "gpg_key_info": receiver.gpg_key_info,
        "gpg_key_fingerprint": receiver.gpg_key_fingerprint,
        "gpg_key_remove": False,
        "gpg_key_armor": receiver.gpg_key_armor,
        "gpg_key_status": receiver.gpg_key_status,
        "gpg_enable_notification": receiver.gpg_enable_notification,
        "tip_notification" : receiver.tip_notification,
        "file_notification" : receiver.file_notification,
        "comment_notification" : receiver.comment_notification,
        "message_notification" : receiver.message_notification,
        "mail_address": receiver.mail_address,
        "contexts": [c.id for c in receiver.contexts],
        "password": u'',
        "old_password": u'',
        'language': receiver.user.language,
        'timezone': receiver.user.timezone
    }

    for context in receiver.contexts:
        ret_dict['contexts'].append(context.id)

    return get_localized_values(ret_dict, receiver, receiver.localized_strings, language)
Пример #12
0
def db_admin_serialize_node(store, language):
    """
    Serialize node infos.

    :param store: the store on which perform queries.
    :param language: the language in which to localize data.
    :return: a dictionary including the node configuration.
    """
    node = store.find(models.Node).one()

    admin = store.find(models.User, (models.User.username == unicode('admin'))).one()

    # Contexts and Receivers relationship
    configured  = store.find(models.ReceiverContext).count() > 0

    custom_homepage = os.path.isfile(os.path.join(GLSetting.static_path, "custom_homepage.html"))

    ret_dict = {
        'name': node.name,
        'presentation': node.presentation,
        'creation_date': datetime_to_ISO8601(node.creation_date),
        'last_update': datetime_to_ISO8601(node.last_update),
        'hidden_service': node.hidden_service,
        'public_site': node.public_site,
        'email': node.email,
        'version': GLSetting.version_string,
        'languages_supported': LANGUAGES_SUPPORTED,
        'languages_enabled': node.languages_enabled,
        'default_language' : node.default_language,
        'default_timezone' : node.default_timezone,
        'maximum_filesize': node.maximum_filesize,
        'maximum_namesize': node.maximum_namesize,
        'maximum_textsize': node.maximum_textsize,
        'exception_email': node.exception_email,
        'tor2web_admin': GLSetting.memory_copy.tor2web_admin,
        'tor2web_submission': GLSetting.memory_copy.tor2web_submission,
        'tor2web_receiver': GLSetting.memory_copy.tor2web_receiver,
        'tor2web_unauth': GLSetting.memory_copy.tor2web_unauth,
        'can_postpone_expiration': node.can_postpone_expiration,
        'can_delete_submission': node.can_delete_submission,
        'ahmia': node.ahmia,
        'allow_unencrypted': node.allow_unencrypted,
        'allow_iframes_inclusion': node.allow_iframes_inclusion,
        'wizard_done': node.wizard_done,
        'configured': configured,
        'password': u'',
        'old_password': u'',
        'custom_homepage': custom_homepage,
        'disable_privacy_badge': node.disable_privacy_badge,
        'disable_security_awareness_badge': node.disable_security_awareness_badge,
        'disable_security_awareness_questions': node.disable_security_awareness_questions,
        'disable_key_code_hint': node.disable_key_code_hint,
        'admin_language': admin.language,
        'admin_timezone': admin.timezone,
        'enable_custom_privacy_badge': node.enable_custom_privacy_badge,
        'landing_page': node.landing_page,
        'show_contexts_in_alphabetical_order': node.show_contexts_in_alphabetical_order
    }

    return get_localized_values(ret_dict, node, node.localized_strings, language)
Пример #13
0
def db_admin_serialize_node(store, language):
    """
    Serialize node infos.

    :param store: the store on which perform queries.
    :param language: the language in which to localize data.
    :return: a dictionary including the node configuration.
    """
    node = store.find(models.Node).one()

    admin = store.find(models.User, (models.User.username == unicode('admin'))).one()

    # Contexts and Receivers relationship
    associated = store.find(models.ReceiverContext).count()
    custom_homepage = os.path.isfile(os.path.join(GLSetting.static_path, "custom_homepage.html"))

    ret_dict = {
        "name": node.name,
        "presentation": node.presentation,
        "creation_date": datetime_to_ISO8601(node.creation_date),
        "last_update": datetime_to_ISO8601(node.last_update),
        "hidden_service": node.hidden_service,
        "public_site": node.public_site,
        "stats_update_time": node.stats_update_time,
        "email": node.email,
        "version": GLSetting.version_string,
        "languages_supported": LANGUAGES_SUPPORTED,
        "languages_enabled": node.languages_enabled,
        "default_language" : node.default_language,
        'default_timezone' : node.default_timezone,
        'maximum_filesize': node.maximum_filesize,
        'maximum_namesize': node.maximum_namesize,
        'maximum_textsize': node.maximum_textsize,
        'exception_email': node.exception_email,
        'tor2web_admin': GLSetting.memory_copy.tor2web_admin,
        'tor2web_submission': GLSetting.memory_copy.tor2web_submission,
        'tor2web_receiver': GLSetting.memory_copy.tor2web_receiver,
        'tor2web_unauth': GLSetting.memory_copy.tor2web_unauth,
        'postpone_superpower': node.postpone_superpower,
        'can_delete_submission': node.can_delete_submission,
        'ahmia': node.ahmia,
        'allow_unencrypted': node.allow_unencrypted,
        'allow_iframes_inclusion': node.allow_iframes_inclusion,
        'wizard_done': node.wizard_done,
        'configured': True if associated else False,
        'password': u"",
        'old_password': u"",
        'custom_homepage': custom_homepage,
        'disable_privacy_badge': node.disable_privacy_badge,
        'disable_security_awareness_badge': node.disable_security_awareness_badge,
        'disable_security_awareness_questions': node.disable_security_awareness_questions,
        'admin_language': admin.language,
        'admin_timezone': admin.timezone,
        'enable_custom_privacy_badge': node.enable_custom_privacy_badge,
        'custom_privacy_badge_tor': node.custom_privacy_badge_tor,
        'custom_privacy_badge_none': node.custom_privacy_badge_none,
        'landing_page': node.landing_page
    }

    return get_localized_values(ret_dict, node, node.localized_strings, language)
Пример #14
0
def admin_serialize_context(store, context, language):
    """
    Serialize the specified context

    :param store: the store on which perform queries.
    :param language: the language in which to localize data.
    :return: a dictionary representing the serialization of the context.
    """
    steps = [anon_serialize_step(store, s, language)
           for s in context.steps.order_by(models.Step.number)]

    ret_dict = {
        "id": context.id,
        "creation_date": datetime_to_ISO8601(context.creation_date),
        "last_update": datetime_to_ISO8601(context.last_update),
        "tip_max_access": context.tip_max_access,
        "file_max_download": context.file_max_download,
        "receivers": [r.id for r in context.receivers],
        # tip expressed in day, submission in hours
        "tip_timetolive": context.tip_timetolive / (60 * 60 * 24),
        "submission_timetolive": context.submission_timetolive / (60 * 60),
        "select_all_receivers": context.select_all_receivers,
        "postpone_superpower": context.postpone_superpower,
        "can_delete_submission": context.can_delete_submission,
        "maximum_selectable_receivers": context.maximum_selectable_receivers,
        "show_small_cards": context.show_small_cards,
        "show_receivers": context.show_receivers,
        "enable_private_messages": context.enable_private_messages,
        "presentation_order": context.presentation_order,
        "steps": steps
    }

    return get_localized_values(ret_dict, context, context.localized_strings, language)
Пример #15
0
def anon_serialize_receiver(receiver,
                            language=GLSetting.memory_copy.default_language):
    """
    @param receiver: a valid Storm object
    @return: a dict describing the receivers available in the node
        (e.g. checks if almost one context is associated, or, in
         node where GPG encryption is enforced, that a valid key is registered)
    """
    mo = Rosetta()
    mo.acquire_storm_object(receiver)

    receiver_dict = {
        "creation_date": datetime_to_ISO8601(receiver.creation_date),
        "update_date": datetime_to_ISO8601(receiver.last_update),
        "name": receiver.name,
        "description": mo.dump_translated('description', language),
        "id": receiver.id,
        "receiver_level": receiver.receiver_level,
        "tags": receiver.tags,
        "presentation_order": receiver.presentation_order,
        "gpg_key_status": receiver.gpg_key_status,
        # list is needed because .values returns a generator
        "contexts": list(receiver.contexts.values(models.Context.id))
    }

    if not len(receiver_dict['contexts']):
        return None

    return receiver_dict
Пример #16
0
def receiver_serialize_receiver(receiver, language):
    ret_dict = {
        'id': receiver.id,
        'name': receiver.name,
        'update_date': datetime_to_ISO8601(receiver.last_update),
        'creation_date': datetime_to_ISO8601(receiver.creation_date),
        'can_delete_submission': receiver.can_delete_submission,
        'username': receiver.user.username,
        'pgp_key_info': receiver.pgp_key_info,
        'pgp_key_fingerprint': receiver.pgp_key_fingerprint,
        'pgp_key_remove': False,
        'pgp_key_public': receiver.pgp_key_public,
        'pgp_key_expiration': datetime_to_ISO8601(receiver.pgp_key_expiration),
        'pgp_key_status': receiver.pgp_key_status,
        'tip_notification': receiver.tip_notification,
        'ping_notification': receiver.ping_notification,
        'mail_address': receiver.mail_address,
        'ping_mail_address': receiver.ping_mail_address,
        'contexts': [c.id for c in receiver.contexts],
        'password': u'',
        'old_password': u'',
        'language': receiver.user.language,
        'timezone': receiver.user.timezone
    }

    for context in receiver.contexts:
        ret_dict['contexts'].append(context.id)

    return get_localized_values(ret_dict, receiver, receiver.localized_strings, language)
Пример #17
0
def serialize_itip(session, internaltip, language):
    aq = session.query(models.ArchivedSchema).filter(models.ArchivedSchema.hash == internaltip.questionnaire_hash).one()

    wb_access_revoked = session.query(models.WhistleblowerTip).filter(models.WhistleblowerTip.id == internaltip.id).count() == 0

    return {
        'id': internaltip.id,
        'creation_date': datetime_to_ISO8601(internaltip.creation_date),
        'update_date': datetime_to_ISO8601(internaltip.update_date),
        'expiration_date': datetime_to_ISO8601(internaltip.expiration_date),
        'progressive': internaltip.progressive,
        'context_id': internaltip.context_id,
        'questionnaire': db_serialize_archived_questionnaire_schema(session, aq.schema, language),
        'receivers': db_get_itip_receiver_list(session, internaltip),
        'https': internaltip.https,
        'enable_two_way_comments': internaltip.enable_two_way_comments,
        'enable_two_way_messages': internaltip.enable_two_way_messages,
        'enable_attachments': internaltip.enable_attachments,
        'enable_whistleblower_identity': internaltip.enable_whistleblower_identity,
        'identity_provided': internaltip.identity_provided,
        'identity_provided_date': datetime_to_ISO8601(internaltip.identity_provided_date),
        'wb_last_access': datetime_to_ISO8601(internaltip.wb_last_access),
        'wb_access_revoked': wb_access_revoked,
        'total_score': internaltip.total_score,
        'status': internaltip.status,
        'substatus': internaltip.substatus
    }
Пример #18
0
 def test_datetime_to_ISO8601_to_datetime_to_dot_dot_dot(self):
     a = utility.datetime_null()
     b = utility.datetime_to_ISO8601(a)
     c = utility.ISO8601_to_datetime(b)
     d = utility.datetime_to_ISO8601(c)
     self.assertTrue(a, c)
     self.assertTrue(b, d)
Пример #19
0
def admin_serialize_context(store, context, language=GLSetting.memory_copy.default_language):

    steps = [ anon_serialize_step(store, s, language)
              for s in context.steps.order_by(models.Step.number) ]

    ret_dict = {
        "id": context.id,
        "creation_date": datetime_to_ISO8601(context.creation_date),
        "last_update": datetime_to_ISO8601(context.last_update),
        "selectable_receiver": context.selectable_receiver,
        "tip_max_access": context.tip_max_access,
        "file_max_download": context.file_max_download,
        "receivers": [r.id for r in context.receivers],
        # tip expressed in day, submission in hours
        "tip_timetolive": context.tip_timetolive / (60 * 60 * 24),
        "submission_timetolive": context.submission_timetolive / (60 * 60),
        "select_all_receivers": context.select_all_receivers,
        "postpone_superpower": context.postpone_superpower,
        "can_delete_submission": context.can_delete_submission,
        "maximum_selectable_receivers": context.maximum_selectable_receivers,
        "show_small_cards": context.show_small_cards,
        "show_receivers": context.show_receivers,
        "enable_private_messages": context.enable_private_messages,
        "presentation_order": context.presentation_order,
        "steps": steps
    }

    return get_localized_values(ret_dict, context, context.localized_strings, language)
Пример #20
0
def receiver_serialize_internal_tip(internaltip, language=GLSetting.memory_copy.default_language):

    itip_dict = {
        'context_id': internaltip.context.id,
        'creation_date' : datetime_to_ISO8601(internaltip.creation_date),
        'expiration_date' : datetime_to_ISO8601(internaltip.expiration_date),
        'download_limit' : internaltip.download_limit,
        'access_limit' : internaltip.access_limit,
        'mark' : internaltip.mark,
        'pertinence' : internaltip.pertinence_counter,
        'escalation_threshold' : internaltip.escalation_threshold,
        'fields' : internaltip.wb_fields,

        # these two fields are at the moment unsent by the client, but kept
        # maintained in unitTest. (tickets in wishlist)
        'is_pertinent' : False,
        'global_delete' : False,
        # this field "inform" the receiver of the new expiration date that can
        # be set, only if PUT with extend = True is updated
        'potential_expiration_date' : \
            datetime_to_ISO8601(utc_future_date(seconds=internaltip.context.tip_timetolive)),
        'extend' : False,
        'enable_private_messages': internaltip.context.enable_private_messages
    }

    # context_name and context_description are localized field
    mo = Rosetta()
    mo.acquire_storm_object(internaltip.context)
    for attr in ['name', 'description' ]:
        key = "context_%s" % attr
        itip_dict[key] = mo.dump_translated(attr, language)

    return itip_dict
Пример #21
0
def get_tiptime_by_marker(store, marker):
    assert marker in InternalTip._marker

    itip_list = store.find(InternalTip, InternalTip.mark == marker)

    tipinfo_list = []
    for itip in itip_list:

        comment_cnt = store.find(Comment, Comment.internaltip_id == itip.id).count()
        files_cnt = store.find(InternalFile, InternalFile.internaltip_id == itip.id).count()

        if not itip.context:
            log.err("A Tip related to a not existent Context! This would not happen if delete on cascade is working")
            # And the removal is forced putting 1 second of life to the Tip.
            tip_timetolive = 1
            submission_timetolive = 1
        else:
            tip_timetolive = itip.context.tip_timetolive
            submission_timetolive = itip.context.submission_timetolive

        serialized_tipinfo = {
            'id': itip.id,
            'creation_date': datetime_to_ISO8601(itip.creation_date),
            'expiration_date': datetime_to_ISO8601(itip.expiration_date),
            'tip_life_seconds':  tip_timetolive,
            'submission_life_seconds':  submission_timetolive,
            'files': files_cnt,
            'comments': comment_cnt,
        }
        tipinfo_list.append(serialized_tipinfo)

    return tipinfo_list
Пример #22
0
def receiver_serialize_rfile(session, rfile):
    ifile = session.query(models.InternalFile) \
                   .filter(models.InternalFile.id == models.ReceiverFile.internalfile_id,
                           models.ReceiverFile.id == rfile.id).one()

    if rfile.status == 'unavailable':
        return {
            'id': rfile.id,
            'internalfile_id': ifile.id,
            'status': 'unavailable',
            'href': "",
            'name': ifile.name,
            'content_type': ifile.content_type,
            'creation_date': datetime_to_ISO8601(ifile.creation_date),
            'size': int(ifile.size),
            'downloads': rfile.downloads
        }

    return {
        'id': rfile.id,
        'internalfile_id': ifile.id,
        'status': rfile.status,
        'href': "/rtip/" + rfile.receivertip_id + "/download/" + rfile.id,
        # if the ReceiverFile has encrypted status, we append ".pgp" to the filename, to avoid mistake on Receiver side.
        'name': ("%s.pgp" % ifile.name) if rfile.status == u'encrypted' else ifile.name,
        'content_type': ifile.content_type,
        'creation_date': datetime_to_ISO8601(ifile.creation_date),
        'size': rfile.size,
        'downloads': rfile.downloads
    }
Пример #23
0
def get_receivertip_list(store, receiver_id, language):
    rtip_summary_list = []

    for rtip in store.find(ReceiverTip, ReceiverTip.receiver_id == receiver_id):
        mo = Rosetta(rtip.internaltip.context.localized_keys)
        mo.acquire_storm_object(rtip.internaltip.context)

        rtip_summary_list.append({
            'id': rtip.id,
            'creation_date': datetime_to_ISO8601(rtip.internaltip.creation_date),
            'last_access': datetime_to_ISO8601(rtip.last_access),
            'update_date': datetime_to_ISO8601(rtip.internaltip.update_date),
            'expiration_date': datetime_to_ISO8601(rtip.internaltip.expiration_date),
            'progressive': rtip.internaltip.progressive,
            'new': rtip.access_counter == 0 or rtip.last_access < rtip.internaltip.update_date,
            'context_name': mo.dump_localized_key('name', language),
            'access_counter': rtip.access_counter,
            'file_counter': rtip.internaltip.internalfiles.count(),
            'comment_counter': rtip.internaltip.comments.count(),
            'message_counter': rtip.messages.count(),
            'tor2web': rtip.internaltip.tor2web,
            'questionnaire_hash': rtip.internaltip.questionnaire_hash,
            'preview_schema': db_get_archived_preview_schema(store, rtip.internaltip.questionnaire_hash, language),
            'preview': rtip.internaltip.preview,
            'total_score': rtip.internaltip.total_score,
            'label': rtip.label
        })

    return rtip_summary_list
Пример #24
0
def get_tiptime_by_marker(store, marker):
    itip_list = store.find(InternalTip, InternalTip.mark == marker)

    tipinfo_list = []
    for itip in itip_list:

        comment_cnt = store.find(Comment,
                                 Comment.internaltip_id == itip.id).count()
        files_cnt = store.find(InternalFile,
                               InternalFile.internaltip_id == itip.id).count()

        if not itip.context:
            log.err(
                "A Tip related to a not existent Context! This would not happen if delete on cascade is working"
            )
            # And the removal is forced putting 1 second of life to the Tip.
            tip_timetolive = 1
            submission_timetolive = 1
        else:
            tip_timetolive = itip.context.tip_timetolive
            submission_timetolive = itip.context.submission_timetolive

        serialized_tipinfo = {
            'id': itip.id,
            'creation_date': datetime_to_ISO8601(itip.creation_date),
            'expiration_date': datetime_to_ISO8601(itip.expiration_date),
            'tip_life_seconds': tip_timetolive,
            'submission_life_seconds': submission_timetolive,
            'files': files_cnt,
            'comments': comment_cnt,
        }
        tipinfo_list.append(serialized_tipinfo)

    return tipinfo_list
Пример #25
0
def serialize_itip(store, internaltip, language):
    context = internaltip.context
    mo = Rosetta(context.localized_keys)
    mo.acquire_storm_object(context)

    return {
        'id': internaltip.id,
        'creation_date': datetime_to_ISO8601(internaltip.creation_date),
        'update_date': datetime_to_ISO8601(internaltip.update_date),
        'expiration_date': datetime_to_ISO8601(internaltip.expiration_date),
        'progressive': internaltip.progressive,
        'context_id': internaltip.context_id,
        'context_name': mo.dump_localized_key('name', language),
        'questionnaire': db_get_archived_questionnaire_schema(store, internaltip.questionnaire_hash, language),
        'tor2web': internaltip.tor2web,
        'timetolive': context.tip_timetolive,
        'enable_comments': context.enable_comments,
        'enable_messages': context.enable_messages,
        'enable_two_way_comments': internaltip.enable_two_way_comments,
        'enable_two_way_messages': internaltip.enable_two_way_messages,
        'enable_attachments': internaltip.enable_attachments,
        'enable_whistleblower_identity': internaltip.enable_whistleblower_identity,
        'identity_provided': internaltip.identity_provided,
        'identity_provided_date': datetime_to_ISO8601(internaltip.identity_provided_date),
        'show_receivers': context.show_receivers
    }
Пример #26
0
def serialize_itip(session, internaltip, language):
    x = session.query(models.InternalTipAnswers, models.ArchivedSchema) \
               .filter(models.ArchivedSchema.hash == models.InternalTipAnswers.questionnaire_hash,
                       models.InternalTipAnswers.internaltip_id == internaltip.id)

    questionnaires = []
    for ita, aqs in x:
        questionnaires.append({
            'steps': db_serialize_archived_questionnaire_schema(aqs.schema, language),
            'answers': ita.answers
        })

    wb_access_revoked = session.query(models.WhistleblowerTip).filter(models.WhistleblowerTip.id == internaltip.id).count() == 0

    return {
        'id': internaltip.id,
        'creation_date': datetime_to_ISO8601(internaltip.creation_date),
        'update_date': datetime_to_ISO8601(internaltip.update_date),
        'expiration_date': datetime_to_ISO8601(internaltip.expiration_date),
        'progressive': internaltip.progressive,
        'context_id': internaltip.context_id,
        'additional_questionnaire_id': internaltip.additional_questionnaire_id,
        'questionnaires': questionnaires,
        'receivers': db_get_itip_receiver_list(session, internaltip),
        'https': internaltip.https,
        'enable_two_way_comments': internaltip.enable_two_way_comments,
        'enable_two_way_messages': internaltip.enable_two_way_messages,
        'enable_attachments': internaltip.enable_attachments,
        'enable_whistleblower_identity': internaltip.enable_whistleblower_identity,
        'wb_last_access': datetime_to_ISO8601(internaltip.wb_last_access),
        'wb_access_revoked': wb_access_revoked,
        'total_score': internaltip.total_score,
        'status': internaltip.status,
        'substatus': internaltip.substatus
    }
Пример #27
0
def receiver_serialize_rfile(session, rfile):
    ifile = session.query(models.InternalFile) \
                   .filter(models.InternalFile.id == rfile.internalfile_id).one()

    if rfile.status == 'unavailable':
        return {
            'id': rfile.id,
            'internalfile_id': ifile.id,
            'status': 'unavailable',
            'href': "",
            'name': ifile.name,
            'content_type': ifile.content_type,
            'creation_date': datetime_to_ISO8601(ifile.creation_date),
            'size': ifile.size,
            'downloads': rfile.downloads
        }

    return {
        'id': rfile.id,
        'internalfile_id': ifile.id,
        'status': rfile.status,
        'href': "/rtip/" + rfile.receivertip_id + "/download/" + rfile.id,
        # if the ReceiverFile has encrypted status, we append ".pgp" to the filename, to avoid mistake on Receiver side.
        'name': ("%s.pgp" % ifile.name) if rfile.status == u'encrypted' else ifile.name,
        'content_type': ifile.content_type,
        'creation_date': datetime_to_ISO8601(ifile.creation_date),
        'size': ifile.size,
        'downloads': rfile.downloads
    }
Пример #28
0
def anon_serialize_receiver(receiver, language=GLSetting.memory_copy.default_language):
    """
    @param receiver: a valid Storm object
    @return: a dict describing the receivers available in the node
        (e.g. checks if almost one context is associated, or, in
         node where GPG encryption is enforced, that a valid key is registered)
    """
    mo = Rosetta()
    mo.acquire_storm_object(receiver)

    receiver_dict = {
        "creation_date": datetime_to_ISO8601(receiver.creation_date),
        "update_date": datetime_to_ISO8601(receiver.last_update),
        "name": receiver.name,
        "description": mo.dump_translated('description', language),
        "id": receiver.id,
        "receiver_level": receiver.receiver_level,
        "tags": receiver.tags,
        "presentation_order": receiver.presentation_order,
        "gpg_key_status": receiver.gpg_key_status,
                    # list is needed because .values returns a generator
        "contexts": list(receiver.contexts.values(models.Context.id))
    }

    if not len(receiver_dict['contexts']):
        return None

    return receiver_dict
Пример #29
0
def receiver_serialize_receiver(receiver, language=GLSetting.memory_copy.default_language):
    receiver_dict = {
        "id": receiver.id,
        "name": receiver.name,
        "update_date": datetime_to_ISO8601(receiver.last_update),
        "creation_date": datetime_to_ISO8601(receiver.creation_date),
        "receiver_level": receiver.receiver_level,
        "can_delete_submission": receiver.can_delete_submission,
        "username": receiver.user.username,
        "gpg_key_info": receiver.gpg_key_info,
        "gpg_key_fingerprint": receiver.gpg_key_fingerprint,
        "gpg_key_remove": False,
        "gpg_key_armor": receiver.gpg_key_armor,
        "gpg_key_status": receiver.gpg_key_status,
        "gpg_enable_notification": receiver.gpg_enable_notification,
        "tags": receiver.tags,
        "tip_notification" : receiver.tip_notification,
        "file_notification" : receiver.file_notification,
        "comment_notification" : receiver.comment_notification,
        "message_notification" : receiver.message_notification,
        "mail_address": receiver.mail_address,
                    # list is needed because .values returns a generator
        "contexts": list(receiver.contexts.values(Context.id)),
        "password": u'',
        "old_password": u'',
    }

    mo = Rosetta()
    mo.acquire_storm_object(receiver)
    receiver_dict["description"] = mo.dump_translated('description', language)

    for context in receiver.contexts:
        receiver_dict['contexts'].append(context.id)

    return receiver_dict
Пример #30
0
def get_tip_timings(store, new):
    itip_list = store.find(InternalTip, InternalTip.new == new)

    tipinfo_list = []

    for itip in itip_list:
        comment_cnt = store.find(Comment, Comment.internaltip_id == itip.id).count()
        files_cnt = store.find(InternalFile, InternalFile.internaltip_id == itip.id).count()

        tip_timetolive = itip.context.tip_timetolive

        serialized_tipinfo = {
            'id': itip.id,
            'creation_date': datetime_to_ISO8601(itip.creation_date),
            'expiration_date': datetime_to_ISO8601(itip.expiration_date),
            'upcoming_expiration_date':
                datetime_to_ISO8601(utc_dynamic_date(itip.expiration_date, hours=72)),
            'tip_life_seconds':  tip_timetolive,
            'files': files_cnt,
            'comments': comment_cnt,
        }

        tipinfo_list.append(serialized_tipinfo)

    return tipinfo_list
Пример #31
0
def serialize_identityaccessrequest(session, tid, identityaccessrequest):
    itip, user = session.query(models.InternalTip, models.User) \
                      .filter(models.InternalTip.id == models.ReceiverTip.internaltip_id,
                              models.ReceiverTip.id == identityaccessrequest.receivertip_id,
                              models.ReceiverTip.receiver_id == models.User.id,
                              models.UserTenant.user_id == models.User.id,
                              models.UserTenant.tenant_id == tid).one()

    reply_user = session.query(models.User) \
                      .filter(models.User.id == identityaccessrequest.reply_user_id,
                              models.UserTenant.user_id == models.User.id,
                              models.UserTenant.tenant_id == tid).one_or_none()
    return {
        'id': identityaccessrequest.id,
        'receivertip_id': identityaccessrequest.receivertip_id,
        'request_date':
        datetime_to_ISO8601(identityaccessrequest.request_date),
        'request_user_name': user.name,
        'request_motivation': identityaccessrequest.request_motivation,
        'reply_date': datetime_to_ISO8601(identityaccessrequest.reply_date),
        'reply_user_name': reply_user.id if reply_user is not None else '',
        'reply': identityaccessrequest.reply,
        'reply_motivation': identityaccessrequest.reply_motivation,
        'submission_date': datetime_to_ISO8601(itip.creation_date)
    }
Пример #32
0
def admin_serialize_context(store, context, language):
    """
    Serialize the specified context

    :param store: the store on which perform queries.
    :param language: the language in which to localize data.
    :return: a dictionary representing the serialization of the context.
    """
    steps = [anon_serialize_step(store, s, language)
                for s in context.steps.order_by(models.Step.number)]

    ret_dict = {
        'id': context.id,
        'creation_date': datetime_to_ISO8601(context.creation_date),
        'last_update': datetime_to_ISO8601(context.last_update),
        'receivers': [r.id for r in context.receivers],
        # tip expressed in day, submission in hours
        'tip_timetolive': context.tip_timetolive / (60 * 60 * 24),
        'select_all_receivers': context.select_all_receivers,
        'can_postpone_expiration': context.can_postpone_expiration,
        'can_delete_submission': context.can_delete_submission,
        'maximum_selectable_receivers': context.maximum_selectable_receivers,
        'show_small_cards': context.show_small_cards,
        'show_receivers': context.show_receivers,
        'enable_private_messages': context.enable_private_messages,
        'presentation_order': context.presentation_order,
        'show_receivers_in_alphabetical_order': context.show_receivers_in_alphabetical_order,
        'reset_steps': False,
        'steps': steps
    }

    return get_localized_values(ret_dict, context, context.localized_strings, language)
Пример #33
0
def get_receivertip_list(store, receiver_id, language):
    rtip_summary_list = []

    for rtip in store.find(ReceiverTip, ReceiverTip.receiver_id == receiver_id):
        mo = Rosetta(rtip.internaltip.context.localized_keys)
        mo.acquire_storm_object(rtip.internaltip.context)

        rtip_summary_list.append(
            {
                "id": rtip.id,
                "creation_date": datetime_to_ISO8601(rtip.internaltip.creation_date),
                "last_access": datetime_to_ISO8601(rtip.last_access),
                "update_date": datetime_to_ISO8601(rtip.internaltip.update_date),
                "expiration_date": datetime_to_ISO8601(rtip.internaltip.expiration_date),
                "timetolive": rtip.internaltip.context.tip_timetolive,
                "progressive": rtip.internaltip.progressive,
                "new": rtip.access_counter == 0 or rtip.last_access < rtip.internaltip.update_date,
                "context_name": mo.dump_localized_key("name", language),
                "access_counter": rtip.access_counter,
                "file_counter": rtip.internaltip.internalfiles.count(),
                "comment_counter": rtip.internaltip.comments.count(),
                "message_counter": rtip.messages.count(),
                "tor2web": rtip.internaltip.tor2web,
                "questionnaire_hash": rtip.internaltip.questionnaire_hash,
                "preview_schema": db_get_archived_preview_schema(store, rtip.internaltip.questionnaire_hash, language),
                "preview": rtip.internaltip.preview,
                "total_score": rtip.internaltip.total_score,
                "label": rtip.label,
            }
        )

    return rtip_summary_list
Пример #34
0
def user_serialize_user(session, user, language):
    """
    Serialize user description

    :param session: the session on which perform queries.
    :param username: the username of the user to be serialized
    :return: a serialization of the object
    """
    picture = db_get_model_img(session, 'users', user.id)

    ret_dict = {
        'id': user.id,
        'username': user.username,
        'password': '',
        'old_password': u'',
        'salt': '',
        'role': user.role,
        'state': user.state,
        'last_login': datetime_to_ISO8601(user.last_login),
        'name': user.name,
        'description': user.description,
        'mail_address': user.mail_address,
        'change_email_address': user.change_email_address,
        'language': user.language,
        'password_change_needed': user.password_change_needed,
        'password_change_date': datetime_to_ISO8601(user.password_change_date),
        'pgp_key_fingerprint': user.pgp_key_fingerprint,
        'pgp_key_public': user.pgp_key_public,
        'pgp_key_expiration': datetime_to_ISO8601(user.pgp_key_expiration),
        'pgp_key_remove': False,
        'picture': picture
    }

    return get_localized_values(ret_dict, user, user.localized_keys, language)
Пример #35
0
def serialize_itip(store, internaltip, language):
    context = internaltip.context
    mo = Rosetta(context.localized_keys)
    mo.acquire_storm_object(context)

    return {
        'id': internaltip.id,
        'creation_date': datetime_to_ISO8601(internaltip.creation_date),
        'update_date': datetime_to_ISO8601(internaltip.update_date),
        'expiration_date': datetime_to_ISO8601(internaltip.expiration_date),
        'progressive': internaltip.progressive,
        'sequence_number': get_submission_sequence_number(internaltip),
        'context_id': internaltip.context_id,
        'context_name': mo.dump_localized_key('name', language),
        'questionnaire': db_get_archived_questionnaire_schema(store, internaltip.questionnaire_hash, language),
        'tor2web': internaltip.tor2web,
        'timetolive': context.tip_timetolive,
        'enable_comments': context.enable_comments,
        'enable_messages': context.enable_messages,
        'enable_two_way_comments': internaltip.enable_two_way_comments,
        'enable_two_way_messages': internaltip.enable_two_way_messages,
        'enable_attachments': internaltip.enable_attachments,
        'enable_whistleblower_identity': internaltip.enable_whistleblower_identity,
        'identity_provided': internaltip.identity_provided,
        'identity_provided_date': datetime_to_ISO8601(internaltip.identity_provided_date),
        'show_recipients_details': context.show_recipients_details,
        'status_page_message': mo.dump_localized_key('status_page_message', language)
    }
Пример #36
0
def anon_serialize_receiver(receiver, language):
    """
    Serialize a receiver description

    :param receiver: the receiver to be serialized
    :param language: the language in which to localize data
    :return: a serializtion of the object
    """

    contexts = [c.id for c in receiver.contexts]
    if not len(contexts):
        return None

    ret_dict = {
        "creation_date": datetime_to_ISO8601(receiver.creation_date),
        "update_date": datetime_to_ISO8601(receiver.last_update),
        "name": receiver.name,
        "id": receiver.id,
        "state": receiver.user.state,
        "configuration": receiver.configuration,
        "presentation_order": receiver.presentation_order,
        "gpg_key_status": receiver.gpg_key_status,
        "contexts": contexts
    }

    return get_localized_values(ret_dict, receiver, receiver.localized_strings,
                                language)
Пример #37
0
def user_serialize_user(user, language):
    """
    Serialize user description

    :param store: the store on which perform queries.
    :param username: the username of the user to be serialized
    :return: a serialization of the object
    """
    ret_dict = {
        'id': user.id,
        'username': user.username,
        'password': '',
        'old_password': u'',
        'salt': '',
        'role': user.role,
        'deletable': user.deletable,
        'state': user.state,
        'last_login': datetime_to_ISO8601(user.last_login),
        'name': user.name,
        'description': user.description,
        'mail_address': user.mail_address,
        'language': user.language,
        'timezone': user.timezone,
        'password_change_needed': user.password_change_needed,
        'password_change_date': datetime_to_ISO8601(user.password_change_date),
        'pgp_key_info': user.pgp_key_info,
        'pgp_key_fingerprint': user.pgp_key_fingerprint,
        'pgp_key_public': user.pgp_key_public,
        'pgp_key_expiration': datetime_to_ISO8601(user.pgp_key_expiration),
        'pgp_key_status': user.pgp_key_status,
        'pgp_key_remove': False,
        'picture': user.picture.data if user.picture is not None else ''
    }

    return get_localized_values(ret_dict, user, user.localized_keys, language)
Пример #38
0
def receiver_serialize_file(internalfile, receiverfile, receivertip_id):
    """
    ReceiverFile is the mixing between the metadata present in InternalFile
    and the Receiver-dependent, and for the client sake receivertip_id is
    required to create the download link
    """

    if receiverfile.status != 'unavailable':

        rfile_dict = {
            'status': receiverfile.status,
            'href' : "/rtip/" + receivertip_id + "/download/" + receiverfile.id,
            # if the ReceiverFile has encrypted status, we append ".pgp" to the filename, to avoid mistake on Receiver side.
            'name' : ("%s.pgp" % internalfile.name) if receiverfile.status == u'encrypted' else internalfile.name,
            'content_type' : internalfile.content_type,
            'creation_date' : datetime_to_ISO8601(internalfile.creation_date),
            'size': receiverfile.size,
            'downloads': receiverfile.downloads
      }

    else: # == 'unavailable' in this case internal file metadata is returned.

        rfile_dict = {
            'status': 'unavailable',
            'href' : "",
            'name' : internalfile.name, # original filename
            'content_type' : internalfile.content_type, # original content size
            'creation_date' : datetime_to_ISO8601(internalfile.creation_date), # original creation_date
            'size': int(internalfile.size), # original filesize
            'downloads': unicode(receiverfile.downloads) # this counter is always valid
        }

    return rfile_dict
Пример #39
0
def anon_serialize_receiver(receiver, language=GLSetting.memory_copy.default_language):
    """
    @param receiver: a valid Storm object
    @return: a dict describing the receivers available in the node
        (e.g. checks if almost one context is associated, or, in
         node where GPG encryption is enforced, that a valid key is registered)
    """

    contexts = [c.id for c in receiver.contexts]
    if not len(contexts):
        return None

    ret_dict = {
        "creation_date": datetime_to_ISO8601(receiver.creation_date),
        "update_date": datetime_to_ISO8601(receiver.last_update),
        "name": receiver.name,
        "id": receiver.id,
        "state": receiver.user.state,
        "configuration": receiver.configuration, 
        "presentation_order": receiver.presentation_order,
        "gpg_key_status": receiver.gpg_key_status,
        "contexts": contexts
    }

    return get_localized_values(ret_dict, receiver, receiver.localized_strings, language)
Пример #40
0
def admin_serialize_receiver(receiver, language=GLSetting.memory_copy.default_language):

    ret_dict = {
        "id": receiver.id,
        "name": receiver.name,
        "creation_date": datetime_to_ISO8601(receiver.creation_date),
        "last_update": datetime_to_ISO8601(receiver.last_update),
        "can_delete_submission": receiver.can_delete_submission,
        "postpone_superpower": receiver.postpone_superpower,
        "username": receiver.user.username,
        "user_id": receiver.user.id,
        'mail_address': receiver.mail_address,
        "password": u"",
        "state": receiver.user.state,
        "configuration": receiver.configuration,
        "contexts": [c.id for c in receiver.contexts],
        "gpg_key_info": receiver.gpg_key_info,
        "gpg_key_armor": receiver.gpg_key_armor,
        "gpg_key_remove": False,
        "gpg_key_fingerprint": receiver.gpg_key_fingerprint,
        "gpg_key_status": receiver.gpg_key_status,
        "gpg_enable_notification": True if receiver.gpg_enable_notification else False,
        "comment_notification": True if receiver.comment_notification else False,
        "tip_notification": True if receiver.tip_notification else False,
        "file_notification": True if receiver.file_notification else False,
        "message_notification": True if receiver.message_notification else False,
        "presentation_order": receiver.presentation_order,
        "language": receiver.user.language,
        "timezone": receiver.user.timezone,
        "password_change_needed": receiver.user.password_change_needed
    }

    return get_localized_values(ret_dict, receiver, receiver.localized_strings, language)
Пример #41
0
def get_tip_timings(store):
    itip_list = store.find(InternalTip)

    tipinfo_list = []

    for itip in itip_list:
        comment_cnt = store.find(Comment, Comment.internaltip_id == itip.id).count()
        files_cnt = store.find(InternalFile, InternalFile.internaltip_id == itip.id).count()

        tip_timetolive = itip.context.tip_timetolive

        serialized_tipinfo = {
            'id': itip.id,
            'creation_date': datetime_to_ISO8601(itip.creation_date),
            'expiration_date': datetime_to_ISO8601(itip.expiration_date),
            'upcoming_expiration_date':
                datetime_to_ISO8601(utc_dynamic_date(itip.expiration_date, hours=-72)),
            'tip_life_seconds':  tip_timetolive,
            'files': files_cnt,
            'comments': comment_cnt,
        }

        # TODO, query ReceiverFile and ReceiverTip and check if the status is 'new'
        # in CleaningSched, if some of the 'new' is going to be deleted, we are
        # spotting a serious (sorry for the latinism) 'fancazzismo cronicarum' and the
        # Admin can be alerted about.

        tipinfo_list.append(serialized_tipinfo)

    return tipinfo_list
Пример #42
0
def user_serialize_user(user, language):
    """
    Serialize user description

    :param store: the store on which perform queries.
    :param username: the username of the user to be serialized
    :return: a serialization of the object
    """
    ret_dict = {
        'id': user.id,
        'username': user.username,
        'password': '',
        'old_password': u'',
        'salt': '',
        'role': user.role,
        'deletable': user.deletable,
        'state': user.state,
        'last_login': datetime_to_ISO8601(user.last_login),
        'name': user.name,
        'description': user.description,
        'mail_address': user.mail_address,
        'language': user.language,
        'timezone': user.timezone,
        'password_change_needed': user.password_change_needed,
        'password_change_date': datetime_to_ISO8601(user.password_change_date),
        'pgp_key_info': user.pgp_key_info,
        'pgp_key_fingerprint': user.pgp_key_fingerprint,
        'pgp_key_public': user.pgp_key_public,
        'pgp_key_expiration': datetime_to_ISO8601(user.pgp_key_expiration),
        'pgp_key_status': user.pgp_key_status,
        'pgp_key_remove': False,
    }

    return get_localized_values(ret_dict, user, user.localized_keys, language)
Пример #43
0
def receiver_serialize_internal_tip(internaltip, language):

    ret_dict = {
        'context_id': internaltip.context.id,
        'creation_date' : datetime_to_ISO8601(internaltip.creation_date),
        'expiration_date' : datetime_to_ISO8601(internaltip.expiration_date),
        'download_limit' : internaltip.download_limit,
        'access_limit' : internaltip.access_limit,
        'mark' : internaltip.mark,
        'wb_steps' : internaltip.wb_steps,
        'global_delete' : False,
        # this field "inform" the receiver of the new expiration date that can
        # be set, only if PUT with extend = True is updated
        'potential_expiration_date' : \
                datetime_to_ISO8601(utc_future_date(seconds=internaltip.context.tip_timetolive)),
        'extend' : False,
        'enable_private_messages': internaltip.context.enable_private_messages,
    }

    # context_name and context_description are localized fields
    mo = Rosetta(internaltip.context.localized_strings)
    mo.acquire_storm_object(internaltip.context)
    for attr in ['name', 'description']:
        key = "context_%s" % attr
        ret_dict[key] = mo.dump_localized_attr(attr, language)

    return ret_dict
Пример #44
0
def collect_users_overview(store):

    users_description_list = []

    all_receivers = store.find(models.Receiver)

    for receiver in all_receivers:
        # all public of private infos are stripped, because know between the Admin resources
        user_description = {
            'id': receiver.id,
            'name': receiver.name,
            'receiverfiles': [],
            'receivertips': [],
            'gpg_key_status': receiver.gpg_key_status,
        }

        rcvr_files = store.find(models.ReceiverFile,
                                models.ReceiverFile.receiver_id == receiver.id)
        for rfile in rcvr_files:

            if not rfile.internalfile:
                log.err(
                    "(user_overview) ReceiverFile without InternaFile available: skipped"
                )
                continue

            user_description['receiverfiles'].append({
                'id':
                rfile.id,
                'file_name':
                rfile.internalfile.name,
                'downloads':
                rfile.downloads,
                'last_access':
                datetime_to_ISO8601(rfile.last_access),
                'status':
                rfile.mark,
            })

        rcvr_tips = store.find(models.ReceiverTip,
                               models.ReceiverTip.receiver_id == receiver.id)
        for rtip in rcvr_tips:
            user_description['receivertips'].append({
                'internaltip_id':
                rtip.id,
                'status':
                rtip.mark,
                'last_access':
                datetime_to_ISO8601(rtip.last_access),
                'notification_date':
                datetime_to_ISO8601(rtip.notification_date),
                'access_counter':
                rtip.access_counter
            })

        users_description_list.append(user_description)

    return users_description_list
Пример #45
0
def user_serialize_user(session, user, language):
    """
    Serialize user model

    :param user: the user object
    :param language: the language of the data
    :param session: the session on which perform queries.
    :return: a serialization of the object
    """
    picture = db_get_model_img(session, 'users', user.id)

    # take only contexts for the current tenant
    contexts = [x[0] for x in session.query(models.ReceiverContext.context_id)
                                     .filter(models.ReceiverContext.receiver_id == user.id)]
    ret_dict = {
        'id': user.id,
        'username': user.username,
        'password': '',
        'old_password': '',
        'salt': '',
        'role': user.role,
        'state': user.state,
        'last_login': datetime_to_ISO8601(user.last_login),
        'name': user.name,
        'description': user.description,
        'public_name': user.public_name,
        'mail_address': user.mail_address,
        'change_email_address': user.change_email_address,
        'language': user.language,
        'password_change_needed': user.password_change_needed,
        'password_change_date': datetime_to_ISO8601(user.password_change_date),
        'pgp_key_fingerprint': user.pgp_key_fingerprint,
        'pgp_key_public': user.pgp_key_public,
        'pgp_key_expiration': datetime_to_ISO8601(user.pgp_key_expiration),
        'pgp_key_remove': False,
        'picture': picture,
        'can_edit_general_settings': user.can_edit_general_settings,
        'tid': user.tid,
        'notification': user.notification,
        'encryption': user.crypto_pub_key != '',
        'escrow': user.crypto_escrow_prv_key != '',
        'two_factor_enable': user.two_factor_enable,
        'recipient_configuration': user.recipient_configuration,
        'can_postpone_expiration': user.can_postpone_expiration,
        'can_delete_submission': user.can_delete_submission,
        'can_grant_permissions': user.can_grant_permissions,
        'contexts': contexts,
        'send_account_activation_link': False
    }

    if user.tid in State.tenant_cache:
        ret_dict.update({
            'can_postpone_expiration': State.tenant_cache[user.tid].can_postpone_expiration or user.can_postpone_expiration,
            'can_delete_submission': State.tenant_cache[user.tid].can_delete_submission or user.can_delete_submission,
            'can_grant_permissions': State.tenant_cache[user.tid].can_grant_permissions or user.can_grant_permissions
        })

    return get_localized_values(ret_dict, user, user.localized_keys, language)
Пример #46
0
def collect_tip_overview(store, language):
    tip_description_list = []

    all_itips = store.find(models.InternalTip)
    for itip in all_itips:
        tip_description = {
            'id': itip.id,
            'creation_date': datetime_to_ISO8601(itip.creation_date),
            'creation_lifetime': datetime_to_ISO8601(itip.creation_date),
            'expiration_date': datetime_to_ISO8601(itip.expiration_date),
            'context_id': itip.context_id,
            'receivertips': [],
            'internalfiles': [],
            'comments': [],
            'wb_access_counter': 0,
            'wb_last_access': u'Never'
        }

        mo = Rosetta(itip.context.localized_keys)
        mo.acquire_storm_object(itip.context)
        tip_description['context_name'] = mo.dump_localized_key('name', language)

        for rtip in itip.receivertips:
            tip_description['receivertips'].append({
                'access_counter': rtip.access_counter,
                'receiver_id': rtip.receiver.id,
                'receiver_username': rtip.receiver.user.username,
                'receiver_name': rtip.receiver.user.name,
                # last_access censored willingly
            })

        for ifile in itip.internalfiles:
            tip_description['internalfiles'].append({
                'name': ifile.name,
                'size': ifile.size,
                'content_type': ifile.content_type
            })

        for comment in itip.comments:
            tip_description['comments'].append({
                'type': comment.type,
                'lifetime': datetime_to_ISO8601(comment.creation_date),
            })

        # whistleblower tip has not a reference from itip, then:
        wbtip = store.find(models.WhistleblowerTip,
                           models.WhistleblowerTip.internaltip_id == itip.id).one()

        if wbtip is not None:
            tip_description.update({
                'wb_access_counter': wbtip.access_counter,
                'wb_last_access': datetime_to_ISO8601(wbtip.last_access)
            })

        tip_description_list.append(tip_description)

    return tip_description_list
Пример #47
0
def get_receiver_list_wb(store, wb_tip_id, language):
    """
    @return:
        This function contain the serialization of the receiver, this function is
        used only by /wbtip/receivers API

        The returned struct contain information on read/unread messages
    """
    receiver_list = []

    wb_tip = store.find(WhistleblowerTip,
                        WhistleblowerTip.id == unicode(wb_tip_id)).one()

    if not wb_tip:
        raise errors.TipReceiptNotFound

    def localize_and_append_receiver(receiver, receiver_desc):
        mo = Rosetta(receiver.localized_strings)
        mo.acquire_storm_object(receiver)
        receiver_desc["description"] = mo.dump_localized_attr("description", language)
        receiver_list.append(receiver_desc)

    if not wb_tip.internaltip.receivertips.count():

        # This part of code is used when receiver tips have still not been created
        for receiver in wb_tip.internaltip.receivers:
            # This is the reduced version of Receiver serialization
            receiver_desc = {
                "name": receiver.name,
                "id": receiver.id,
                "pgp_key_status": receiver.pgp_key_status,
                "access_counter": 0,
                "message_counter": 0,
                "creation_date": datetime_to_ISO8601(datetime_now()),
            }

            localize_and_append_receiver(receiver, receiver_desc)

    else:

        for rtip in wb_tip.internaltip.receivertips:
            message_counter = store.find(Message,
                                         Message.receivertip_id == rtip.id).count()

            receiver_desc = {
                "name": rtip.receiver.name,
                "id": rtip.receiver.id,
                "pgp_key_status": rtip.receiver.pgp_key_status,
                "access_counter": rtip.access_counter,
                "message_counter": message_counter,
                "creation_date": datetime_to_ISO8601(datetime_now()),
            }

            localize_and_append_receiver(rtip.receiver, receiver_desc)

    return receiver_list
Пример #48
0
def serialize_receivertip(receiver_tip):
    rtip_dict = {
        'id': receiver_tip.id,
        'creation_date' : datetime_to_ISO8601(receiver_tip.creation_date),
        'last_access' : datetime_to_ISO8601(receiver_tip.last_access),
        'access_counter' : receiver_tip.access_counter,
        'wb_steps': receiver_tip.internaltip.wb_steps,
        'context_id': receiver_tip.internaltip.context.id,
    }
    return rtip_dict
Пример #49
0
def serialize_receivertip(receiver_tip):
    rtip_dict = {
        'id': receiver_tip.id,
        'creation_date': datetime_to_ISO8601(receiver_tip.creation_date),
        'last_access': datetime_to_ISO8601(receiver_tip.last_access),
        'access_counter': receiver_tip.access_counter,
        'wb_steps': receiver_tip.internaltip.wb_steps,
        'context_id': receiver_tip.internaltip.context.id,
    }
    return rtip_dict
Пример #50
0
def db_admin_serialize_node(store, language=GLSetting.memory_copy.default_language):

    node = store.find(models.Node).one()

    admin = store.find(models.User, (models.User.username == unicode('admin'))).one()

    # Contexts and Receivers relationship
    associated = store.find(models.ReceiverContext).count()
    custom_homepage = os.path.isfile(os.path.join(GLSetting.static_path, "custom_homepage.html"))

    ret_dict = {
        "name": node.name,
        "presentation": node.presentation,
        "creation_date": datetime_to_ISO8601(node.creation_date),
        "last_update": datetime_to_ISO8601(node.last_update),
        "hidden_service": node.hidden_service,
        "public_site": node.public_site,
        "stats_update_time": node.stats_update_time,
        "email": node.email,
        "version": GLSetting.version_string,
        "languages_supported": LANGUAGES_SUPPORTED,
        "languages_enabled": node.languages_enabled,
        "default_language" : node.default_language,
        'default_timezone' : node.default_timezone,
        'maximum_filesize': node.maximum_filesize,
        'maximum_namesize': node.maximum_namesize,
        'maximum_textsize': node.maximum_textsize,
        'exception_email': node.exception_email,
        'tor2web_admin': GLSetting.memory_copy.tor2web_admin,
        'tor2web_submission': GLSetting.memory_copy.tor2web_submission,
        'tor2web_receiver': GLSetting.memory_copy.tor2web_receiver,
        'tor2web_unauth': GLSetting.memory_copy.tor2web_unauth,
        'postpone_superpower': node.postpone_superpower,
        'can_delete_submission': node.can_delete_submission,
        'ahmia': node.ahmia,
        'reset_css': False,
        'reset_homepage': False,
        'allow_unencrypted': node.allow_unencrypted,
        'wizard_done': node.wizard_done,
        'configured': True if associated else False,
        'password': u"",
        'old_password': u"",
        'custom_homepage': custom_homepage,
        'disable_privacy_badge': node.disable_privacy_badge,
        'disable_security_awareness_badge': node.disable_security_awareness_badge,
        'disable_security_awareness_questions': node.disable_security_awareness_questions,
        'admin_language': admin.language,
        'admin_timezone': admin.timezone,
        'enable_custom_privacy_badge': node.enable_custom_privacy_badge,
        'custom_privacy_badge_tbb': node.custom_privacy_badge_tbb,
        'custom_privacy_badge_tor': node.custom_privacy_badge_tor,
        'custom_privacy_badge_none': node.custom_privacy_badge_none,
    }

    return get_localized_values(ret_dict, node, node.localized_strings, language)
Пример #51
0
def signup_activation(session, state, tid, token, language):
    node = config.ConfigFactory(session, 1, 'node')

    if not node.get_val(u'enable_signup'):
        raise errors.ForbiddenOperation

    signup = session.query(models.Signup).filter(models.Signup.activation_token == token).one_or_none()
    if signup is None:
        return {}

    if signup.tid is None:
        signup.tid = db_create_tenant(session, {'label': signup.subdomain,
                                                'subdomain': signup.subdomain}).id

        wizard = {
            'node_name': signup.subdomain,
            'admin_name': signup.name + ' ' + signup.surname,
            'admin_password': '',
            'admin_mail_address': signup.email,
            'receiver_name': signup.name + ' ' + signup.surname,
            'receiver_mail_address': signup.email,
            'profile': 'default',
            'enable_developers_exception_notification': True
        }

        db_wizard(session, state, signup.tid, wizard, False, language)

        template_vars = {
            'type': 'activation',
            'node': db_admin_serialize_node(session, 1, language),
            'notification': db_get_notification(session, 1, language),
            'signup': serialize_signup(signup),
            'activation_url': '',
            'expiration_date': datetime_to_ISO8601(signup.registration_date + timedelta(days=7))
        }

        state.format_and_send_mail(session, 1, {'mail_address': signup.email}, template_vars)

    if session.query(models.Tenant).filter(models.Tenant.id == signup.tid).one_or_none() is not None:
        admin = session.query(models.User).filter(models.User.tid == signup.tid, models.User.role == u'admin').one()
        admin.password_change_needed = False

        recipient = session.query(models.User).filter(models.User.tid == signup.tid, models.User.role == u'receiver').one()
        recipient.password_change_needed = False

        return {
            'platform_url': 'https://%s.%s' % (signup.subdomain, node.get_val(u'rootdomain')),
            'login_url': 'https://%s.%s/#/login' % (signup.subdomain, node.get_val(u'rootdomain')),
            'admin_login_url': 'https://%s.%s/#/login?token=%s' % (signup.subdomain, node.get_val(u'rootdomain'), admin.auth_token),
            'recipient_login_url': 'https://%s.%s/#/login?token=%s' % (signup.subdomain, node.get_val(u'rootdomain'), recipient.auth_token),
            'expiration_date': datetime_to_ISO8601(signup.registration_date + timedelta(days=7))
        }
    else:
        return {}
Пример #52
0
def get_receivertip_list(store, receiver_id, language):
    rtiplist = store.find(ReceiverTip, ReceiverTip.receiver_id == receiver_id)
    rtiplist.order_by(Desc(ReceiverTip.creation_date))

    node = store.find(Node).one()

    rtip_summary_list = []

    for rtip in rtiplist:

        can_postpone_expiration = (node.can_postpone_expiration or
                                   rtip.internaltip.context.can_postpone_expiration or
                                   rtip.receiver.can_postpone_expiration)

        can_delete_submission = (node.can_delete_submission or
                                 rtip.internaltip.context.can_delete_submission or
                                 rtip.receiver.can_delete_submission)

        rfiles_n = store.find(ReceiverFile,
                              (ReceiverFile.internaltip_id == rtip.internaltip.id,
                               ReceiverFile.receiver_id == receiver_id)).count()

        message_counter = store.find(Message,
                                     Message.receivertip_id == rtip.id).count()

        single_tip_sum = dict({
            'id': rtip.id,
            'creation_date': datetime_to_ISO8601(rtip.creation_date),
            'last_access': datetime_to_ISO8601(rtip.last_access),
            'expiration_date': datetime_to_ISO8601(rtip.internaltip.expiration_date),
            'access_counter': rtip.access_counter,
            'file_counter': rfiles_n,
            'comment_counter': rtip.internaltip.comments.count(),
            'message_counter': message_counter,
            'can_postpone_expiration': can_postpone_expiration,
            'can_delete_submission': can_delete_submission,
        })

        mo = Rosetta(rtip.internaltip.context.localized_strings)
        mo.acquire_storm_object(rtip.internaltip.context)
        single_tip_sum["context_name"] = mo.dump_localized_attr('name', language)

        preview_data = []

        for s in rtip.internaltip.wb_steps:
            for f in s['children']:
                if f['preview']:
                    preview_data.append(f)

        single_tip_sum.update({'preview': preview_data})
        rtip_summary_list.append(single_tip_sum)

    return rtip_summary_list
Пример #53
0
def get_receivertip_list(store, receiver_id, language):
    rtiplist = store.find(ReceiverTip, ReceiverTip.receiver_id == receiver_id)

    rtip_summary_list = []

    for rtip in rtiplist:
        # TODO this store find in a potentially long loop is bad, is easier store in
        # InternalTip the file counter number...
        rfiles_n = store.find(
            ReceiverFile, (ReceiverFile.internaltip_id == rtip.internaltip.id,
                           ReceiverFile.receiver_id == receiver_id)).count()

        message_counter = store.find(
            Message, Message.receivertip_id == rtip.id).count()
        single_tip_sum = dict({
            'id':
            rtip.id,
            'creation_date':
            datetime_to_ISO8601(rtip.internaltip.creation_date),
            'last_access':
            datetime_to_ISO8601(rtip.last_access),
            'expiration_date':
            datetime_to_ISO8601(rtip.internaltip.expiration_date),
            'access_counter':
            rtip.access_counter,
            'file_counter':
            rfiles_n,
            'comment_counter':
            rtip.internaltip.comments.count(),
            'message_counter':
            message_counter,
            'tor2web':
            rtip.internaltip.tor2web,
            'questionnaire_hash':
            rtip.internaltip.questionnaire_hash,
            'preview_schema':
            db_get_archived_preview_schema(store,
                                           rtip.internaltip.questionnaire_hash,
                                           language),
            'preview':
            rtip.internaltip.preview,
            'label':
            rtip.label,
        })

        mo = Rosetta(rtip.internaltip.context.localized_strings)
        mo.acquire_storm_object(rtip.internaltip.context)
        single_tip_sum["context_name"] = mo.dump_localized_key(
            'name', language)

        rtip_summary_list.append(single_tip_sum)

    return rtip_summary_list
Пример #54
0
def wb_serialize_internaltip(internaltip):
    response = {
        'id': internaltip.id,
        'context_id': internaltip.context_id,
        'creation_date': datetime_to_ISO8601(internaltip.creation_date),
        'expiration_date': datetime_to_ISO8601(internaltip.expiration_date),
        'wb_steps': internaltip.wb_steps,
        'files': [f.id for f in internaltip.internalfiles],
        'receivers': [r.id for r in internaltip.receivers]
    }

    return response
Пример #55
0
def wb_serialize_internaltip(store, internaltip):
    response = {
        'id': internaltip.id,
        'context_id': internaltip.context_id,
        'creation_date': datetime_to_ISO8601(internaltip.creation_date),
        'expiration_date': datetime_to_ISO8601(internaltip.expiration_date),
        'answers': db_serialize_questionnaire_answers(store, internaltip),
        'files': [f.id for f in internaltip.internalfiles],
        'receivers': [r.id for r in internaltip.receivers]
    }

    return response
Пример #56
0
def serialize_receivertip(store, rtip, language):
    rtip_dict = {
        'id': rtip.id,
        'creation_date': datetime_to_ISO8601(rtip.internaltip.creation_date),
        'last_access': datetime_to_ISO8601(rtip.last_access),
        'access_counter': rtip.access_counter,
        'questionnaire': db_get_archived_questionnaire_schema(store, rtip.internaltip.questionnaire_hash, language),
        'answers': db_serialize_questionnaire_answers(store, rtip.internaltip),
        'context_id': rtip.internaltip.context.id,
        'expiration_date': datetime_to_ISO8601(rtip.internaltip.expiration_date)
    }

    return rtip_dict
Пример #57
0
def db_admin_serialize_node(store,
                            language=GLSetting.memory_copy.default_language):

    node = store.find(Node).one()

    mo = structures.Rosetta()
    mo.acquire_storm_object(node)

    # Contexts and Receivers relationship
    associated = store.find(models.ReceiverContext).count()

    node_dict = {
        "name": node.name,
        "presentation": node.presentation,
        "creation_date": datetime_to_ISO8601(node.creation_date),
        "last_update": datetime_to_ISO8601(node.last_update),
        "hidden_service": node.hidden_service,
        "public_site": node.public_site,
        "receipt_regexp": node.receipt_regexp,
        "receipt_example": generate_example_receipt(node.receipt_regexp),
        "stats_update_time": node.stats_update_time,
        "email": node.email,
        "version": GLSetting.version_string,
        "languages_supported": LANGUAGES_SUPPORTED,
        "languages_enabled": node.languages_enabled,
        "default_language": node.default_language,
        'maximum_filesize': node.maximum_filesize,
        'maximum_namesize': node.maximum_namesize,
        'maximum_textsize': node.maximum_textsize,
        'exception_email': node.exception_email,
        'tor2web_admin': GLSetting.memory_copy.tor2web_admin,
        'tor2web_submission': GLSetting.memory_copy.tor2web_submission,
        'tor2web_receiver': GLSetting.memory_copy.tor2web_receiver,
        'tor2web_unauth': GLSetting.memory_copy.tor2web_unauth,
        'postpone_superpower': node.postpone_superpower,
        'can_delete_submission': node.can_delete_submission,
        'ahmia': node.ahmia,
        'reset_css': False,
        'anomaly_checks': node.anomaly_checks,
        'allow_unencrypted': node.allow_unencrypted,
        'wizard_done': node.wizard_done,
        'receipt_regexp': node.receipt_regexp,
        'configured': True if associated else False,
        'password': u"",
        'old_password': u"",
    }

    for attr in mo.get_localized_attrs():
        node_dict[attr] = mo.dump_translated(attr, language)

    return node_dict
Пример #58
0
def serialize_receiverfile(rfile):
    rfile_dict = {
        'id':
        rfile.id,
        'creation_date':
        datetime_to_ISO8601(rfile.internalfile.internaltip.creation_date),
        'internaltip_id':
        rfile.internalfile.internaltip_id,
        'internalfile_id':
        rfile.internalfile_id,
        'receiver_id':
        rfile.receivertip.receiver_id,
        'receivertip_id':
        rfile.receivertip_id,
        'file_path':
        rfile.file_path,
        'size':
        rfile.size,
        'downloads':
        rfile.downloads,
        'last_access':
        rfile.last_access,
        'status':
        rfile.status,
    }

    return rfile_dict
Пример #59
0
 def synthesis(self):
     return {
         'id': self.event_id,
         'creation_date': datetime_to_ISO8601(self.creation_date)[:-8],
         'event': self.event_type,
         'duration': round(self.request_time, 1),
     }