Exemple #1
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
Exemple #2
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
    }
Exemple #3
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

    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()),
        }

        mo = Rosetta(rtip.receiver.localized_strings)
        mo.acquire_storm_object(rtip.receiver)
        receiver_desc["description"] = mo.dump_localized_key("description", language)
        receiver_list.append(receiver_desc)

    return receiver_list
Exemple #4
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)
    """
    receiver_dict = {
        "contexts": [],
    }

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

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

    receiver_dict.update({
        "can_delete_submission": receiver.can_delete_submission,
        "creation_date": pretty_date_time(receiver.creation_date),
        "update_date": pretty_date_time(receiver.last_update),
        "name": unicode(receiver.name),
        "receiver_gus": unicode(receiver.id),
        "receiver_level": int(receiver.receiver_level),
        "tags": receiver.tags,
    })

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

    return receiver_dict
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
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
Exemple #7
0
def receiver_serialize_receiver(receiver, language=GLSetting.memory_copy.default_language):
    receiver_dict = {
        "receiver_gus": receiver.id,
        "name": receiver.name,
        "update_date": pretty_date_time(receiver.last_update),
        "creation_date": pretty_date_time(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,
        "gpg_enable_files": receiver.gpg_enable_files,
        "tags": receiver.tags,
        "tip_notification" : receiver.tip_notification,
        "file_notification" : receiver.file_notification,
        "comment_notification" : receiver.comment_notification,
        "notification_fields": dict(receiver.notification_fields),
        "failed_login": receiver.user.failed_login_count,
        "contexts": []
    }

    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
def anon_serialize_ahmia(store, language=GLSetting.memory_copy.default_language):
    """
    Request reaches only if ahmia is enabled
    """
    node = store.find(models.Node).one()

    mo = Rosetta()
    mo.acquire_storm_object(node)

    ahmia_description = {
        "title": node.name,
        "description": mo.dump_translated('description', language),

        # TODO support tags/keyword in Node.
        "keywords": "%s (GlobaLeaks instance)" % node.name,
        "relation": node.public_site,

        # TODO ask Ahmia to support a list of languages
        "language": node.default_language,

        # TODO say to the admin that its email will be public
        "contactInformation": u'',
        "type": "GlobaLeaks"
    }

    return ahmia_description
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
Exemple #10
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()
    }
Exemple #11
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
Exemple #12
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,
    }
Exemple #13
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
Exemple #14
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_strings)
        mo.acquire_storm_object(itip.context)
        tip_description['context_name'] = mo.dump_localized_attr('name', language)

        for rtip in itip.receivertips:
            tip_description['receivertips'].append({
                'access_counter': rtip.access_counter,
                'notification_date': datetime_to_ISO8601(rtip.notification_date),
                # 'creation_date': datetime_to_ISO8601(rtip.creation_date),
                'receiver_id': rtip.receiver.id,
                'receiver_username': rtip.receiver.user.username,
                'receiver_name': rtip.receiver.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
Exemple #15
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()
    }
Exemple #16
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
Exemple #17
0
def anon_serialize_node(store, language=GLSetting.memory_copy.default_language):
    node = store.find(models.Node).one()

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

    custom_homepage = False

    try: 
        custom_homepage = os.path.isfile(os.path.join(GLSetting.static_path, "custom_homepage.html"))
    except:
        pass

    node_dict = {
      'name': node.name,
      'hidden_service': node.hidden_service,
      'public_site': node.public_site,
      'email': node.email,
      'languages_enabled': node.languages_enabled,
      'languages_supported': LANGUAGES_SUPPORTED,
      'default_language' : node.default_language,
      # extended settings info:
      'maximum_namesize': node.maximum_namesize,
      'maximum_textsize': node.maximum_textsize,
      'maximum_filesize': node.maximum_filesize,
      # public serialization use GLSetting memory var, and
      # not the real one, because needs to bypass
      # Tor2Web unsafe deny default settings
      '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,
      'ahmia': node.ahmia,
      'postpone_superpower': node.postpone_superpower,
      'can_delete_submission': node.can_delete_submission,
      'wizard_done': node.wizard_done,
      'anomaly_checks': node.anomaly_checks,
      'allow_unencrypted': node.allow_unencrypted,
      'x_frame_options_mode': node.x_frame_options_mode,
      'x_frame_options_allow_from': node.x_frame_options_allow_from,
      'receipt_regexp': node.receipt_regexp,
      '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
    }

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

    return node_dict
Exemple #18
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
Exemple #19
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
Exemple #20
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
    }
Exemple #21
0
def anon_serialize_node(store,
                        language=GLSetting.memory_copy.default_language):
    node = store.find(models.Node).one()

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

    node_dict = {
        'name': node.name,
        'hidden_service': node.hidden_service,
        'public_site': node.public_site,
        'email': node.email,
        'languages_enabled': node.languages_enabled,
        'languages_supported': LANGUAGES_SUPPORTED,
        'default_language': node.default_language,
        # extended settings info:
        'maximum_namesize': node.maximum_namesize,
        'maximum_textsize': node.maximum_textsize,
        'maximum_filesize': node.maximum_filesize,
        # public serialization use GLSetting memory var, and
        # not the real one, because needs to bypass
        # Tor2Web unsafe deny default settings
        '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,
        'ahmia': node.ahmia,
        'postpone_superpower': node.postpone_superpower,
        'can_delete_submission': node.can_delete_submission,
        'wizard_done': node.wizard_done,
        'anomaly_checks': node.anomaly_checks,
        'allow_unencrypted': node.allow_unencrypted,
        'receipt_regexp': node.receipt_regexp,
        'configured': True if associated else False,
        'password': u"",
        'old_password': u"",
    }

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

    return node_dict
Exemple #22
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),
            'expiration_date': datetime_to_ISO8601(itip.expiration_date),
            'context_id': itip.context_id
        }

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

        tip_description_list.append(tip_description)

    return tip_description_list
Exemple #23
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),
            'expiration_date': datetime_to_ISO8601(itip.expiration_date),
            'context_id': itip.context_id
        }

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

        tip_description_list.append(tip_description)

    return tip_description_list
def serialize_ahmia(store, language):
    """
    Serialize Ahmia.fi descriptor.
    """
    node = store.find(models.Node).one()

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

    ret_dict = {
        'title': node.name,
        'description': mo.dump_localized_key('description', language),
        'keywords': '%s (GlobaLeaks instance)' % node.name,
        'relation': node.public_site,
        'language': node.default_language,
        'contactInformation': u'',
        'type': 'GlobaLeaks'
    }

    return ret_dict
Exemple #25
0
def wb_serialize_tip(internaltip, language):
    ret_dict = {
        'id': internaltip.id,
        'context_id': internaltip.context.id,
        'creation_date': datetime_to_ISO8601(internaltip.creation_date),
        'last_activity': datetime_to_ISO8601(internaltip.creation_date),
        'expiration_date': datetime_to_ISO8601(internaltip.expiration_date),
        'wb_steps': internaltip.wb_steps,
        'enable_private_messages': internaltip.context.enable_private_messages,
        'show_receivers': internaltip.context.show_receivers,
    }

    # 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
Exemple #26
0
def serialize_ahmia(store, language):
    """
    Serialize Ahmia.fi descriptor.
    """
    node = store.find(models.Node).one()

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

    ret_dict = {
        "title": node.name,
        "description": mo.dump_localized_key("description", language),
        "keywords": "%s (GlobaLeaks instance)" % node.name,
        "relation": node.public_site,
        "language": node.default_language,
        "contactInformation": u"",
        "type": "GlobaLeaks",
    }

    return ret_dict
Exemple #27
0
def get_receiver_list_receiver(store, user_id, tip_id, language):
    rtip = db_access_tip(store, user_id, tip_id)

    receiver_list = []
    for rtip in rtip.internaltip.receivertips:
        receiver_desc = {
            "pgp_key_status": rtip.receiver.pgp_key_status,
            "can_delete_submission": rtip.receiver.can_delete_submission,
            "name": unicode(rtip.receiver.name),
            "receiver_id": unicode(rtip.receiver.id),
            "access_counter": rtip.access_counter,
        }

        mo = Rosetta(rtip.receiver.localized_strings)
        mo.acquire_storm_object(rtip.receiver)
        receiver_desc["description"] = mo.dump_localized_key("description", language)

        receiver_list.append(receiver_desc)

    return receiver_list
Exemple #28
0
def serialize_identityaccessrequest(identityaccessrequest, language):
    iar = {
        'id': identityaccessrequest.id,
        'receivertip_id': identityaccessrequest.receivertip_id,
        'request_date': datetime_to_ISO8601(identityaccessrequest.request_date),
        'request_user_name': identityaccessrequest.receivertip.receiver.user.name,
        'request_motivation': identityaccessrequest.request_motivation,
        'reply_date': datetime_to_ISO8601(identityaccessrequest.reply_date),
        'reply_user_name': identityaccessrequest.reply_user.name \
                if identityaccessrequest.reply_user is not None else '',
        'reply': identityaccessrequest.reply,
        'reply_motivation': identityaccessrequest.reply_motivation,
        'submission_date': datetime_to_ISO8601(identityaccessrequest.receivertip.internaltip.creation_date)
    }

    mo = Rosetta(identityaccessrequest.receivertip.internaltip.context.localized_keys)
    mo.acquire_storm_object(identityaccessrequest.receivertip.internaltip.context)
    iar["submission_context"] = mo.dump_localized_key('name', language)

    return iar
Exemple #29
0
def serialize_ahmia(store, language):
    """
    Serialize Ahmia.fi descriptor.
    """
    node = store.find(models.Node).one()

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

    ret_dict = {
        'title': node.name,
        'description': mo.dump_localized_key('description', language),
        'keywords': '%s (GlobaLeaks instance)' % node.name,
        'relation': node.public_site,
        'language': node.default_language,
        'contactInformation': u'',
        'type': 'GlobaLeaks'
    }

    return ret_dict
Exemple #30
0
def anon_serialize_context(context,
                           language=GLSetting.memory_copy.default_language):
    """
    @param context: a valid Storm object
    @return: a dict describing the contexts available for submission,
        (e.g. checks if almost one receiver is associated)
    """

    mo = Rosetta()
    mo.acquire_storm_object(context)
    fo = Fields(context.localized_fields, context.unique_fields)

    context_dict = {
        "id": context.id,
        "escalation_threshold": 0,
        "file_max_download": context.file_max_download,
        "file_required": context.file_required,
        "selectable_receiver": context.selectable_receiver,
        "tip_max_access": context.tip_max_access,
        "tip_timetolive": context.tip_timetolive,
        "submission_introduction":
        u'NYI',  # unicode(context.submission_introduction), # optlang
        "submission_disclaimer":
        u'NYI',  # unicode(context.submission_disclaimer), # optlang
        "select_all_receivers": context.select_all_receivers,
        "maximum_selectable_receivers": context.maximum_selectable_receivers,
        'require_pgp': context.require_pgp,
        "show_small_cards": context.show_small_cards,
        "presentation_order": context.presentation_order,
        # list is needed because .values returns a generator
        "receivers": list(context.receivers.values(models.Receiver.id)),
        'name': mo.dump_translated('name', language),
        "description": mo.dump_translated('description', language),
        "fields": fo.dump_fields(language)
    }

    if not len(context_dict['receivers']):
        return None

    return context_dict
Exemple #31
0
def wb_serialize_tip(internaltip, language=GLSetting.memory_copy.default_language):
    itip_dict = {
        'context_id': internaltip.context.id,
        'creation_date' : datetime_to_ISO8601(internaltip.creation_date),
        'last_activity' : 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,
    }

    # 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
Exemple #32
0
def anon_serialize_context(context, language=GLSetting.memory_copy.default_language):
    """
    @param context: a valid Storm object
    @return: a dict describing the contexts available for submission,
        (e.g. checks if almost one receiver is associated)
    """

    mo = Rosetta()
    mo.acquire_storm_object(context)
    fo = Fields(context.localized_fields, context.unique_fields)

    context_dict = {
        "id": context.id,
        "escalation_threshold": 0,
        "file_max_download": context.file_max_download,
        "file_required": context.file_required,
        "selectable_receiver": context.selectable_receiver,
        "tip_max_access": context.tip_max_access,
        "tip_timetolive": context.tip_timetolive,
        "submission_introduction": u'NYI', # unicode(context.submission_introduction), # optlang
        "submission_disclaimer": u'NYI', # unicode(context.submission_disclaimer), # optlang
        "select_all_receivers": context.select_all_receivers,
        "maximum_selectable_receivers": context.maximum_selectable_receivers,
        'require_pgp': context.require_pgp,
        "show_small_cards": context.show_small_cards,
        "show_receivers": context.show_receivers,
        "enable_private_messages": context.enable_private_messages,
        "presentation_order": context.presentation_order,
                     # list is needed because .values returns a generator
        "receivers": list(context.receivers.values(models.Receiver.id)),
        'name': mo.dump_translated('name', language),
        "description": mo.dump_translated('description', language),
        "fields": fo.dump_fields(language)
    }

    if not len(context_dict['receivers']):
        return None

    return context_dict
Exemple #33
0
def wb_serialize_tip(store, internaltip, language):
    ret_dict = {
        'id': internaltip.id,
        'context_id': internaltip.context.id,
        'show_receivers': internaltip.context.show_receivers,
        'creation_date': datetime_to_ISO8601(internaltip.creation_date),
        'expiration_date': datetime_to_ISO8601(internaltip.expiration_date),
        'questionnaire': db_get_archived_questionnaire_schema(store, internaltip.questionnaire_hash, language),
        'answers': db_serialize_questionnaire_answers(store, internaltip),
        'tor2web': internaltip.tor2web,
        'enable_comments': internaltip.context.enable_comments,
        '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_key(attr, language)

    return ret_dict
Exemple #34
0
def wb_serialize_tip(internaltip, language):
    ret_dict = {
        'context_id': internaltip.context.id,
        'creation_date': datetime_to_ISO8601(internaltip.creation_date),
        'last_activity': 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,
        'enable_private_messages': internaltip.context.enable_private_messages,
        'show_receivers': internaltip.context.show_receivers,
    }

    # 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
Exemple #35
0
def anon_serialize_context(context, language=GLSetting.memory_copy.default_language):
    """
    @param context: a valid Storm object
    @return: a dict describing the contexts available for submission,
        (e.g. checks if almost one receiver is associated)
    """
    context_dict = {
        "receivers": []
    }

    for receiver in context.receivers:
        context_dict['receivers'].append(unicode(receiver.id))

    if not len(context_dict['receivers']):
        return None

    context_dict.update({
        "context_gus": unicode(context.id),
        "escalation_threshold": None,
        "file_max_download": int(context.file_max_download),
        "file_required": context.file_required,
        "selectable_receiver": bool(context.selectable_receiver),
        "tip_max_access": int(context.tip_max_access),
        "tip_timetolive": int(context.tip_timetolive),
        "receipt_description": u'NYI', # unicode(context.receipt_description), # optlang
        "submission_introduction": u'NYI', # unicode(context.submission_introduction), # optlang
        "submission_disclaimer": u'NYI', # unicode(context.submission_disclaimer), # optlang
        "select_all_receivers": context.select_all_receivers
    })

    mo = Rosetta()
    mo.acquire_storm_object(context)
    context_dict['name'] = mo.dump_translated('name', language)
    context_dict['description'] = mo.dump_translated('description', language)

    fo = Fields(context.localized_fields, context.unique_fields)
    context_dict['fields'] = fo.dump_fields(language)

    return context_dict
Exemple #36
0
def get_receiver_list_receiver(store, user_id, tip_id, language):
    rtip = db_access_tip(store, user_id, tip_id)

    receiver_list = []
    # Improvement TODO, instead of looping over rtip, that can be A LOTS, we
    # can just iterate over receiver, and then remove the receiver not present
    # in the specific InternalTip
    for rtip in rtip.internaltip.receivertips:
        receiver_desc = {
            "pgp_key_status": rtip.receiver.pgp_key_status,
            "can_delete_submission": rtip.receiver.can_delete_submission,
            "name": unicode(rtip.receiver.name),
            "receiver_id": unicode(rtip.receiver.id),
            "access_counter": rtip.access_counter,
        }

        mo = Rosetta(rtip.receiver.localized_strings)
        mo.acquire_storm_object(rtip.receiver)
        receiver_desc["description"] = mo.dump_localized_key("description", language)

        receiver_list.append(receiver_desc)

    return receiver_list
Exemple #37
0
def wb_serialize_tip(internaltip,
                     language=GLSetting.memory_copy.default_language):
    itip_dict = {
        'context_id': internaltip.context.id,
        'creation_date': datetime_to_ISO8601(internaltip.creation_date),
        'last_activity': 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,
    }

    # 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
Exemple #38
0
def get_receivertip_list(store, receiver_id, language):
    node = store.find(Node).one()

    rtiplist = store.find(ReceiverTip, ReceiverTip.receiver_id == receiver_id)

    rtip_summary_list = []

    for rtip in rtiplist:
        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,
            }
        )

        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
Exemple #39
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
Exemple #40
0
def get_receiver_list_receiver(store, user_id, tip_id, language):
    rtip = db_access_tip(store, user_id, tip_id)

    receiver_list = []
    # Improvement TODO, instead of looping over rtip, that can be A LOTS, we
    # can just iterate over receiver, and then remove the receiver not present
    # in the specific InternalTip
    for rtip in rtip.internaltip.receivertips:
        receiver_desc = {
            "pgp_key_status": rtip.receiver.pgp_key_status,
            "can_delete_submission": rtip.receiver.can_delete_submission,
            "name": unicode(rtip.receiver.name),
            "receiver_id": unicode(rtip.receiver.id),
            "access_counter": rtip.access_counter,
        }

        mo = Rosetta(rtip.receiver.localized_strings)
        mo.acquire_storm_object(rtip.receiver)
        receiver_desc["description"] = mo.dump_localized_key(
            "description", language)

        receiver_list.append(receiver_desc)

    return receiver_list
Exemple #41
0
def get_receiver_list_receiver(store, user_id, tip_id, language=GLSetting.memory_copy.default_language):

    rtip = access_tip(store, user_id, tip_id)

    receiver_list = []
    for rtip in rtip.internaltip.receivertips:

        receiver_desc = {
            "gpg_key_status": rtip.receiver.gpg_key_status,
            "can_delete_submission": rtip.receiver.can_delete_submission,
            "name": unicode(rtip.receiver.name),
            "receiver_id": unicode(rtip.receiver.id),
            "receiver_level": int(rtip.receiver.receiver_level),
            "tags": rtip.receiver.tags,
            "access_counter": rtip.access_counter,
        }

        mo = Rosetta()
        mo.acquire_storm_object(rtip.receiver)
        receiver_desc["description"] = mo.dump_translated("description", language)

        receiver_list.append(receiver_desc)

    return receiver_list
Exemple #42
0
def anon_serialize_node(store, language=GLSetting.memory_copy.default_language):
    node = store.find(models.Node).one()

    # Contexts and Receivers relationship
    associated = store.find(models.ReceiverContext).count()
    
    node_dict = {
      'name': unicode(node.name),
      'hidden_service': unicode(node.hidden_service),
      'public_site': unicode(node.public_site),
      'email': unicode(node.email),
      'languages_enabled': node.languages_enabled,
      'languages_supported': LANGUAGES_SUPPORTED,
      'default_language' : node.default_language,
      'configured': True if associated else False,
      # extended settings info:
      'maximum_namesize': node.maximum_namesize,
      'maximum_textsize': node.maximum_textsize,
      'maximum_filesize': node.maximum_filesize,
      # public serialization use GLSetting memory var, and
      # not the real one, because needs to bypass
      # Tor2Web unsafe deny default settings
      'tor2web_admin': GLSetting.memory_copy.tor2web_admin,
      'tor2web_submission': GLSetting.memory_copy.tor2web_submission,
      'tor2web_tip': GLSetting.memory_copy.tor2web_tip,
      'tor2web_receiver': GLSetting.memory_copy.tor2web_receiver,
      'tor2web_unauth': GLSetting.memory_copy.tor2web_unauth,
      'postpone_superpower': node.postpone_superpower,
    }

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

    return node_dict
Exemple #43
0
def get_receiver_tip_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:

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

        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()

        your_messages = store.find(Message,
                                   Message.receivertip_id == rtip.id,
                                   Message.type == u'receiver').count()

        unread_messages = store.find(Message,
                                     Message.receivertip_id == rtip.id,
                                     Message.type == u'whistleblower',
                                     Message.visualized == False).count()

        read_messages = store.find(Message,
                                   Message.receivertip_id == rtip.id,
                                   Message.type == u'whistleblower',
                                   Message.visualized == True).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,
            'files_number': rfiles_n,
            'comments_number': rtip.internaltip.comments.count(),
            'unread_messages' : unread_messages,
            'read_messages' : read_messages,
            'your_messages' : your_messages,
            'postpone_superpower': postpone_superpower,
            '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
Exemple #44
0
def get_receiver_tip_list(store, receiver_id, language=GLSetting.memory_copy.default_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:

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

        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()

        your_messages = store.find(Message,
                                   Message.receivertip_id == rtip.id,
                                   Message.type == u'receiver').count()

        unread_messages = store.find(Message,
                                     Message.receivertip_id == rtip.id,
                                     Message.type == u'whistleblower',
                                     Message.visualized == False).count()

        read_messages = store.find(Message,
                                   Message.receivertip_id == rtip.id,
                                   Message.type == u'whistleblower',
                                   Message.visualized == True).count()

        single_tip_sum = dict({
            'id' : rtip.id,
            'expressed_pertinence': rtip.expressed_pertinence,
            '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,
            'files_number': rfiles_n,
            'comments_number': rtip.internaltip.comments.count(),
            'unread_messages' : unread_messages,
            'read_messages' : read_messages,
            'your_messages' : your_messages,
            'postpone_superpower': postpone_superpower,
            'can_delete_submission': can_delete_submission,
        })

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

        preview_data = []

        fo = Fields(rtip.internaltip.context.localized_fields, rtip.internaltip.context.unique_fields)
        for preview_key, preview_label in fo.get_preview_keys(language).iteritems():

            # preview in a format angular.js likes
            try:
                entry = dict({'label' : preview_label,
                              'text': rtip.internaltip.wb_fields[preview_key] })

            except KeyError as xxx:
                log.err("Legacy error: suppressed 'preview_keys' %s" % xxx.message )
                continue

            preview_data.append(entry)

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

    return rtip_summary_list
Exemple #45
0
def get_receivertip_list(store, receiver_id, language):
    rtip_summary_list = []

    rtips = store.find(ReceiverTip, ReceiverTip.receiver_id == receiver_id)
    itips_ids = [rtip.internaltip_id for rtip in rtips]

    itips_by_id = {}
    contexts_by_id = {}
    aqs_by_itip = {}
    comments_by_itip = {}
    internalfiles_by_itip = {}
    messages_by_rtip = {}

    for itip, context, archivedschema in store.find(
        (InternalTip, Context, ArchivedSchema), In(InternalTip.id, itips_ids),
            Context.id == InternalTip.context_id,
            ArchivedSchema.hash == InternalTip.questionnaire_hash,
            ArchivedSchema.type == u'preview'):
        itips_by_id[itip.id] = itip
        contexts_by_id[context.id] = context
        aqs_by_itip[itip.id] = archivedschema

    result = store.find(
        (ReceiverTip.id, Count()), ReceiverTip.receiver_id == receiver_id,
        ReceiverTip.id == Message.receivertip_id).group_by(ReceiverTip)
    for rtip_id, count in result:
        messages_by_rtip[rtip_id] = count

    result = store.find(
        (InternalTip.id, Count()), In(InternalTip.id, itips_ids),
        InternalTip.id == Comment.internaltip_id).group_by(InternalTip)
    for itip_id, count in result:
        comments_by_itip[itip_id] = count

    result = store.find(
        (InternalTip.id, Count()), In(InternalTip.id, itips_ids),
        InternalTip.id == InternalFile.internaltip_id).group_by(InternalTip)
    for itip_id, count in result:
        internalfiles_by_itip[itip_id] = count

    for rtip in rtips:
        internaltip = itips_by_id[rtip.internaltip_id]
        context = contexts_by_id[internaltip.context_id]
        archivedschema = aqs_by_itip[rtip.internaltip_id]
        mo = Rosetta(context.localized_keys)
        mo.acquire_storm_object(context)

        rtip_summary_list.append({
            'id':
            rtip.id,
            'creation_date':
            datetime_to_ISO8601(internaltip.creation_date),
            'last_access':
            datetime_to_ISO8601(rtip.last_access),
            'update_date':
            datetime_to_ISO8601(internaltip.update_date),
            'expiration_date':
            datetime_to_ISO8601(internaltip.expiration_date),
            'progressive':
            internaltip.progressive,
            'new':
            rtip.access_counter == 0
            or rtip.last_access < internaltip.update_date,
            'context_name':
            mo.dump_localized_key('name', language),
            'access_counter':
            rtip.access_counter,
            'file_counter':
            internalfiles_by_itip.get(internaltip.id, 0),
            'comment_counter':
            comments_by_itip.get(internaltip.id, 0),
            'message_counter':
            messages_by_rtip.get(rtip.id, 0),
            'tor2web':
            internaltip.tor2web,
            'preview_schema':
            db_serialize_archived_preview_schema(store, archivedschema,
                                                 language),
            'preview':
            internaltip.preview,
            'total_score':
            internaltip.total_score,
            'label':
            rtip.label
        })

    return rtip_summary_list
Exemple #46
0
def get_receivertip_list(store, receiver_id, language):
    rtip_summary_list = []

    user = store.find(Custodian, Custodian.id == receiver_id).one()

    if not user:
        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,
                '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,
                'status': rtip.internaltip.status.description,
                'identity_provided': rtip.internaltip.identity_provided
            })
    else:
        for rtip in store.find(ReceiverTip):
            mo = Rosetta(rtip.internaltip.context.localized_keys)
            mo.acquire_storm_object(rtip.internaltip.context)
            iar = store.find(IdentityAccessRequest, IdentityAccessRequest.receivertip_id == rtip.id).one()
            if iar.reply == 'pending':
                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,
                    '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,
                    'status': rtip.internaltip.status.description,
                    'identity_provided': rtip.internaltip.identity_provided
                })

    return rtip_summary_list
Exemple #47
0
def get_receiver_tip_list(store,
                          receiver_id,
                          language=GLSetting.memory_copy.default_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:

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

        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()

        your_messages = store.find(Message, Message.receivertip_id == rtip.id,
                                   Message.type == u'receiver').count()

        unread_messages = store.find(Message,
                                     Message.receivertip_id == rtip.id,
                                     Message.type == u'whistleblower',
                                     Message.visualized == False).count()

        read_messages = store.find(Message, Message.receivertip_id == rtip.id,
                                   Message.type == u'whistleblower',
                                   Message.visualized == True).count()

        single_tip_sum = dict({
            'id':
            rtip.id,
            'expressed_pertinence':
            rtip.expressed_pertinence,
            '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,
            'files_number':
            rfiles_n,
            'comments_number':
            rtip.internaltip.comments.count(),
            'unread_messages':
            unread_messages,
            'read_messages':
            read_messages,
            'your_messages':
            your_messages,
            'postpone_superpower':
            postpone_superpower,
            'can_delete_submission':
            can_delete_submission,
        })

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

        preview_data = []

        fo = Fields(rtip.internaltip.context.localized_fields,
                    rtip.internaltip.context.unique_fields)
        for preview_key, preview_label in fo.get_preview_keys(
                language).iteritems():

            # preview in a format angular.js likes
            try:
                entry = dict({
                    'label': preview_label,
                    'text': rtip.internaltip.wb_fields[preview_key]
                })

            except KeyError as xxx:
                log.err("Legacy error: suppressed 'preview_keys' %s" %
                        xxx.message)
                continue

            preview_data.append(entry)

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

    return rtip_summary_list
Exemple #48
0
def collect_tip_overview(store,
                         language=GLSetting.memory_copy.default_language):

    tip_description_list = []
    all_itips = store.find(models.InternalTip)
    all_itips.order_by(Desc(models.InternalTip.creation_date))

    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,
            "pertinence_counter": itip.pertinence_counter,
            "status": itip.mark,
            "receivertips": [],
            "internalfiles": [],
            "comments": [],
        }

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

        # strip uncompleted submission, until GLClient open new submission
        # also if no data has been supply
        if itip.mark == models.InternalTip._marker[0]:
            continue

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

        for ifile in itip.internalfiles:
            tip_description['internalfiles'].append({
                'name':
                ifile.name,
                'size':
                ifile.size,
                'status':
                ifile.mark,
                '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)
            })
        else:
            tip_description.update({
                'wb_access_counter': u'Deleted',
                'wb_last_access': u'Never'
            })

        tip_description_list.append(tip_description)

    return tip_description_list
Exemple #49
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
    """

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

    if not wb_tip:
        raise errors.TipReceiptNotFound

    # This part of code is used only in the short time between the first
    # WB access and the delivery schedule. In this moment
    # wb_tip.internaltips.receivertips is EMPTY, therefore we force
    # the Receivers values below
    if not wb_tip.internaltip.receivertips.count():
        receiver_list = []

        log.debug("Early access from the WB to the Tip (creation_date: %s UTC),"\
                  " Receiver not yet present: fallback on receiver list" %
                  datetime_to_pretty_str(wb_tip.creation_date))

        for receiver in wb_tip.internaltip.receivers:

            # This is the reduced version of Receiver serialization
            receiver_desc = {
                "name": receiver.name,
                "id": receiver.id,
                "gpg_key_status": receiver.gpg_key_status,
                "access_counter": 0,
                "unread_messages": 0,
                "read_messages": 0,
                "your_messages": 0,
                "creation_date": datetime_to_ISO8601(datetime_now()),
                # XXX ReceiverTip last activity ?
            }

            mo = Rosetta(receiver.localized_strings)
            mo.acquire_storm_object(receiver)
            receiver_desc["description"] = mo.dump_localized_attr(
                "description", language)

            receiver_list.append(receiver_desc)

        return receiver_list
    else:
        receiver_list = []
        for rtip in wb_tip.internaltip.receivertips:

            your_messages = store.find(
                Message, Message.receivertip_id == rtip.id,
                Message.type == u'whistleblower').count()

            unread_messages = store.find(Message,
                                         Message.receivertip_id == rtip.id,
                                         Message.type == u'receiver',
                                         Message.visualized == False).count()

            read_messages = store.find(Message,
                                       Message.receivertip_id == rtip.id,
                                       Message.type == u'receiver',
                                       Message.visualized == True).count()

            # if you change something here, check also 20 lines before!
            receiver_desc = {
                "name": rtip.receiver.name,
                "id": rtip.receiver.id,
                "access_counter": rtip.access_counter,
                "unread_messages": unread_messages,
                "read_messages": read_messages,
                "your_messages": your_messages,
                "creation_date": datetime_to_ISO8601(datetime_now()),
                # XXX ReceiverTip last activity ?
            }

            mo = Rosetta(rtip.receiver.localized_strings)
            mo.acquire_storm_object(rtip.receiver)
            receiver_desc["description"] = mo.dump_localized_attr(
                "description", language)

            receiver_list.append(receiver_desc)

        return receiver_list