def 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 """ ret_dict = { 'id': receiver.user.id, 'name': receiver.user.name, 'username': receiver.user.username if GLSettings.memory_copy.simplified_login else '', 'state': receiver.user.state, 'configuration': receiver.configuration, 'presentation_order': receiver.presentation_order, 'pgp_key_status': receiver.user.pgp_key_status, 'contexts': [c.id for c in receiver.contexts] } # description and eventually other localized strings should be taken from user model get_localized_values(ret_dict, receiver.user, ['description'], language) return get_localized_values(ret_dict, receiver, receiver.localized_keys, language)
def serialize_receiver(session, receiver, language, data=None): """ 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 """ if data is None: data = db_prepare_receivers_serialization(session, [receiver]) user = data['users'][receiver.id] ret_dict = { 'id': receiver.id, 'username': user.username, 'name': user.name, 'state': user.state, 'configuration': receiver.configuration, 'can_delete_submission': receiver.can_delete_submission, 'can_postpone_expiration': receiver.can_postpone_expiration, 'can_grant_permissions': receiver.can_grant_permissions, 'picture': data['imgs'].get(user.id, '') } # description and eventually other localized strings should be taken from user model get_localized_values(ret_dict, user, ['description'], language) return get_localized_values(ret_dict, receiver, receiver.localized_keys, language)
def _db_serialize_archived_field_recursively(field, language): #if field['sensitive_data'] == True: # print "ho trovato un campo sensibile" # return for key, _ in field.get('attrs', {}).items(): if key not in field['attrs']: continue if 'type' not in field['attrs'][key]: continue if field['attrs'][key]['type'] == u'localized': if language in field['attrs'][key].get('value', []): field['attrs'][key]['value'] = field['attrs'][key]['value'][ language] else: field['attrs'][key]['value'] = "" for o in field.get('options', []): get_localized_values(o, o, models.FieldOption.localized_keys, language) for c in field.get('children', []): _db_serialize_archived_field_recursively(c, language) return get_localized_values(field, field, models.Field.localized_keys, language)
def db_serialize_archived_questionnaire_schema(session, questionnaire_schema, language): questionnaire = copy.deepcopy(questionnaire_schema) for step in questionnaire: for field in step['children']: _db_serialize_archived_field_recursively(field, language) get_localized_values(step, step, models.Step.localized_keys, language) return questionnaire
def serialize_receiver(store, receiver, language, data=None): """ 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 """ if data is None: data = db_prepare_receivers_serialization(store, [receiver]) user = data['users'][receiver.id] if (user.img_id is not None and user.img_id in data['imgs']): img = data['imgs'][user.img_id] else: img = '' ret_dict = { 'id': receiver.id, 'name': user.public_name, 'username': receiver.user.username if GLSettings.memory_copy.simplified_login else '', 'state': user.state, 'configuration': receiver.configuration, 'presentation_order': receiver.presentation_order, 'can_delete_submission': receiver.can_delete_submission, 'can_postpone_expiration': receiver.can_postpone_expiration, 'can_grant_permissions': receiver.can_grant_permissions, 'picture': data['imgs'][receiver.id], 'contexts': data['contexts'][receiver.id] } # description and eventually other localized strings should be taken from user model get_localized_values(ret_dict, receiver.user, ['description'], language) return get_localized_values(ret_dict, receiver, receiver.localized_keys, language)
def anon_serialize_option(option, field_type, language): """ Serialize a field option, localizing its content depending on the language. :param option: the field option object to be serialized :param language: the language in which to localize data :return: a serialization of the object """ ret_dict = {'id': option.id, 'attrs': {}, 'value': ''} keys = get_field_option_localized_keys(field_type) get_localized_values(ret_dict['attrs'], option.attrs, keys, language) return ret_dict
def _db_get_archived_questionnaire_schema(store, hash, type, language): aqs = store.find(models.ArchivedSchema, models.ArchivedSchema.hash == hash, models.ArchivedSchema.type == type).one() if not aqs: log.err("Unable to find questionnaire schema with hash %s" % hash) questionnaire = [] else: questionnaire = copy.deepcopy(aqs.schema) for step in questionnaire: for field in step['children']: _db_get_archived_field_recursively(field, language) get_localized_values(step, step, models.Step.localized_keys, language) return questionnaire
def receiver_serialize_receiver(session, tid, receiver, user, language): user = session.query(models.User).filter( models.User.id == receiver.id, models.User.tid == tid).one_or_none() contexts = [x[0] for x in session.query(models.ReceiverContext.context_id) \ .filter(models.ReceiverContext.receiver_id == receiver.id, \ models.User.id == receiver.id, models.User.tid == tid)] ret_dict = user_serialize_user(session, user, language) ret_dict.update({ 'can_postpone_expiration': State.tenant_cache[tid].can_postpone_expiration or receiver.can_postpone_expiration, 'can_delete_submission': State.tenant_cache[tid].can_delete_submission or receiver.can_delete_submission, 'can_grant_permissions': State.tenant_cache[tid].can_grant_permissions or receiver.can_grant_permissions, 'tip_notification': receiver.tip_notification, 'contexts': contexts }) return get_localized_values(ret_dict, receiver, receiver.localized_keys, language)
def db_admin_serialize_node(store, language): node = store.find(models.Node).one() # Contexts and Receivers relationship configured = store.find(models.ReceiverContext).count() > 0 custom_homepage = os.path.isfile(os.path.join(GLSettings.static_path, "custom_homepage.html")) ret_dict = { "name": node.name, "presentation": node.presentation, "hidden_service": node.hidden_service, "public_site": node.public_site, "version": node.version, "version_db": node.version_db, "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, "tor2web_admin": node.tor2web_admin, "tor2web_custodian": node.tor2web_custodian, "tor2web_whistleblower": node.tor2web_whistleblower, "tor2web_receiver": node.tor2web_receiver, "tor2web_unauth": node.tor2web_unauth, "submission_minimum_delay": node.submission_minimum_delay, "submission_maximum_ttl": node.submission_maximum_ttl, "can_postpone_expiration": node.can_postpone_expiration, "can_delete_submission": node.can_delete_submission, "can_grant_permissions": node.can_grant_permissions, "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, "disable_donation_panel": node.disable_donation_panel, "simplified_login": node.simplified_login, "enable_captcha": node.enable_captcha, "enable_proof_of_work": node.enable_proof_of_work, "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, "threshold_free_disk_megabytes_high": node.threshold_free_disk_megabytes_high, "threshold_free_disk_megabytes_medium": node.threshold_free_disk_megabytes_medium, "threshold_free_disk_megabytes_low": node.threshold_free_disk_megabytes_low, "threshold_free_disk_percentage_high": node.threshold_free_disk_percentage_high, "threshold_free_disk_percentage_medium": node.threshold_free_disk_percentage_medium, "threshold_free_disk_percentage_low": node.threshold_free_disk_percentage_low, } return get_localized_values(ret_dict, node, models.Node.localized_keys, language)
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)
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)
def serialize_node(store, language): """ Serialize node infos. """ node = store.find(models.Node).one() # Contexts and Receivers relationship configured = store.find(models.ReceiverContext).count() > 0 ret_dict = { 'name': node.name, 'hidden_service': node.hidden_service, 'public_site': node.public_site, 'languages_enabled': node.languages_enabled, 'languages_supported': LANGUAGES_SUPPORTED, 'default_language': node.default_language, 'default_timezone': node.default_timezone, 'maximum_namesize': node.maximum_namesize, 'maximum_textsize': node.maximum_textsize, 'maximum_filesize': node.maximum_filesize, 'tor2web_admin': node.tor2web_admin, 'tor2web_custodian': node.tor2web_custodian, 'tor2web_whistleblower': node.tor2web_whistleblower, 'tor2web_receiver': node.tor2web_receiver, 'tor2web_unauth': node.tor2web_unauth, 'submission_minimum_delay': 0 if GLSettings.devel_mode else GLSettings.memory_copy.submission_minimum_delay, 'submission_maximum_ttl': GLSettings.memory_copy.submission_maximum_ttl, 'ahmia': node.ahmia, 'allow_indexing': node.allow_indexing, 'can_postpone_expiration': node.can_postpone_expiration, 'can_delete_submission': node.can_delete_submission, 'can_grant_permissions': node.can_grant_permissions, 'wizard_done': node.wizard_done, 'allow_unencrypted': node.allow_unencrypted, 'disable_encryption_warnings': node.disable_encryption_warnings, 'allow_iframes_inclusion': node.allow_iframes_inclusion, 'configured': configured, 'password': u'', 'old_password': u'', 'disable_submissions': node.disable_submissions, '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, 'disable_donation_panel': node.disable_donation_panel, 'simplified_login': node.simplified_login, 'enable_custom_privacy_badge': node.enable_custom_privacy_badge, 'landing_page': node.landing_page, 'context_selector_type': node.context_selector_type, 'show_contexts_in_alphabetical_order': node.show_contexts_in_alphabetical_order, 'show_small_context_cards': node.show_small_context_cards, 'accept_submissions': GLSettings.accept_submissions, 'enable_captcha': node.enable_captcha, 'enable_proof_of_work': node.enable_proof_of_work, 'enable_experimental_features': node.enable_experimental_features, 'logo': node.logo.data if node.logo is not None else '', 'css': node.css.data if node.css is not None else '' } return get_localized_values(ret_dict, node, node.localized_keys, language)
def anon_serialize_context(store, context, language): """ Serialize context description @param context: a valid Storm object @return: a dict describing the contexts available for submission, (e.g. checks if almost one receiver is associated) """ receivers = [r.id for r in context.receivers] if not len(receivers): return None steps = [anon_serialize_step(store, s, language) for s in context.steps] ret_dict = { 'id': context.id, 'tip_timetolive': context.tip_timetolive, 'description': context.description, 'select_all_receivers': context.select_all_receivers, 'maximum_selectable_receivers': context.maximum_selectable_receivers, 'show_small_cards': context.show_small_cards, 'show_receivers': context.show_receivers, 'enable_comments': context.enable_comments, 'enable_private_messages': context.enable_private_messages, 'presentation_order': context.presentation_order, 'show_receivers_in_alphabetical_order': context.show_receivers_in_alphabetical_order, 'steps_arrangement': context.steps_arrangement, 'receivers': receivers, 'steps': steps } return get_localized_values(ret_dict, context, context.localized_strings, language)
def _db_serialize_archived_questionnaire_schema(store, aqs, language): questionnaire = copy.deepcopy(aqs.schema) if aqs.type == 'questionnaire': for step in questionnaire: for field in step['children']: _db_serialize_archived_field_recursively(field, language) get_localized_values(step, step, models.Step.localized_keys, language) elif aqs.type == 'preview': for field in questionnaire: _db_serialize_archived_field_recursively(field, language) return questionnaire
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] ret_dict = { 'id': context.id, '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, 'maximum_selectable_receivers': context.maximum_selectable_receivers, 'show_small_cards': context.show_small_cards, 'show_receivers': context.show_receivers, 'enable_comments': context.enable_comments, 'enable_private_messages': context.enable_private_messages, 'presentation_order': context.presentation_order, 'show_receivers_in_alphabetical_order': context.show_receivers_in_alphabetical_order, 'steps_arrangement': context.steps_arrangement, 'reset_steps': False, 'steps': steps } return get_localized_values(ret_dict, context, context.localized_strings, language)
def serialize_step(store, step, language): """ Serialize a step, localizing its content depending on the language. :param step: the step to be serialized. :param language: the language in which to localize data :return: a serialization of the object """ triggered_by_options = [] _triggered_by_options = store.find( models.FieldOption, models.FieldOption.trigger_step == step.id) for trigger in _triggered_by_options: triggered_by_options.append({ 'step': trigger.step_id, 'option': trigger.id }) children = store.find(models.Field, models.Field.step_id == step.id) data = db_prepare_fields_serialization(store, children) ret_dict = { 'id': step.id, 'questionnaire_id': step.questionnaire_id, 'presentation_order': step.presentation_order, 'triggered_by_score': step.triggered_by_score, 'triggered_by_options': triggered_by_options, 'children': [serialize_field(store, f, language, data) for f in children] } return get_localized_values(ret_dict, step, step.localized_keys, language)
def admin_serialize_notification(notif, language): ret_dict = { 'server': notif.server if notif.server else u"", 'port': notif.port if notif.port else u"", 'username': notif.username if notif.username else u"", 'password': notif.password if notif.password else u"", 'security': notif.security if notif.security else u"", 'source_name': notif.source_name, 'source_email': notif.source_email, 'disable_admin_notification_emails': notif.disable_admin_notification_emails, 'disable_custodian_notification_emails': notif.disable_custodian_notification_emails, 'disable_receiver_notification_emails': notif.disable_receiver_notification_emails, 'send_email_for_every_event': notif.send_email_for_every_event, 'reset_templates': False, 'tip_expiration_threshold': notif.tip_expiration_threshold, 'notification_threshold_per_hour': notif.notification_threshold_per_hour, 'notification_suspension_time': notif.notification_suspension_time, 'exception_email_address': notif.exception_email_address, 'exception_email_pgp_key_info': notif.exception_email_pgp_key_info, 'exception_email_pgp_key_fingerprint': notif.exception_email_pgp_key_fingerprint, 'exception_email_pgp_key_public': notif.exception_email_pgp_key_public, 'exception_email_pgp_key_expiration': datetime_to_ISO8601(notif.exception_email_pgp_key_expiration), 'exception_email_pgp_key_status': notif.exception_email_pgp_key_status, 'exception_email_pgp_key_remove': False } return get_localized_values(ret_dict, notif, notif.localized_keys, language)
def anon_serialize_context(store, context, language): """ Serialize context description @param context: a valid Storm object @return: a dict describing the contexts available for submission, (e.g. checks if almost one receiver is associated) """ ret_dict = { 'id': context.id, 'presentation_order': context.presentation_order, 'tip_timetolive': context.tip_timetolive, 'select_all_receivers': context.select_all_receivers, 'maximum_selectable_receivers': context.maximum_selectable_receivers, 'show_context': context.show_context, 'show_receivers': context.show_receivers, 'show_small_cards': context.show_small_cards, 'enable_comments': context.enable_comments, 'enable_messages': context.enable_messages, 'enable_two_way_comments': context.enable_two_way_comments, 'enable_two_way_messages': context.enable_two_way_messages, 'enable_attachments': context.enable_attachments, 'field_whistleblower_identity': '', 'show_receivers_in_alphabetical_order': context.show_receivers_in_alphabetical_order, 'questionnaire_layout': context.questionnaire_layout, 'custodians': [c.id for c in context.custodians], 'receivers': [r.id for r in context.receivers], 'steps': [anon_serialize_step(store, s, language) for s in context.steps] } return get_localized_values(ret_dict, context, context.localized_keys, language)
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)
def admin_serialize_receiver(store, receiver, language): """ Serialize the specified receiver :param language: the language in which to localize data :return: a dictionary representing the serialization of the receiver """ contexts = [ rc.context_id for rc in store.find(models.ReceiverContext, models.ReceiverContext.receiver_id == receiver.id) ] ret_dict = user_serialize_user(receiver.user, language) ret_dict.update({ 'can_delete_submission': receiver.can_delete_submission, 'can_postpone_expiration': receiver.can_postpone_expiration, 'can_grant_permissions': receiver.can_grant_permissions, 'mail_address': receiver.user.mail_address, 'configuration': receiver.configuration, 'contexts': contexts, 'tip_notification': receiver.tip_notification, 'presentation_order': receiver.presentation_order }) return get_localized_values(ret_dict, receiver, receiver.localized_keys, language)
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)
def serialize_field_attr(attr, language): """ Serialize a field attribute, localizing its content depending on the language. :param option: the field attribute object to be serialized :param language: the language in which to localize data :return: a serialization of the object """ ret_dict = {"id": attr.id, "name": attr.name, "type": attr.type, "value": attr.value} if attr.type == "bool": ret_dict["value"] = True if ret_dict["value"] == "True" else False elif attr.type == u"localized": get_localized_values(ret_dict, ret_dict, ["value"], language) return ret_dict
def receiver_serialize_receiver(receiver, node, language): ret_dict = { 'id': receiver.id, 'name': receiver.name, 'can_postpone_expiration': node.can_postpone_expiration or receiver.can_postpone_expiration, 'can_delete_submission': node.can_delete_submission or 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.user.mail_address, 'ping_mail_address': receiver.ping_mail_address, 'tip_expiration_threshold': receiver.tip_expiration_threshold, '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)
def serialize_context(store, context, language): """ Serialize context description @param context: a valid Storm object @return: a dict describing the contexts available for submission, (e.g. checks if almost one receiver is associated) """ ret_dict = { "id": context.id, "presentation_order": context.presentation_order, "tip_timetolive": context.tip_timetolive, "select_all_receivers": context.select_all_receivers, "maximum_selectable_receivers": context.maximum_selectable_receivers, "show_context": context.show_context, "show_receivers": context.show_receivers, "show_small_cards": context.show_small_cards, "enable_comments": context.enable_comments, "enable_messages": context.enable_messages, "enable_two_way_comments": context.enable_two_way_comments, "enable_two_way_messages": context.enable_two_way_messages, "enable_attachments": context.enable_attachments, "field_whistleblower_identity": "", "show_receivers_in_alphabetical_order": context.show_receivers_in_alphabetical_order, "questionnaire_layout": context.questionnaire_layout, "custodians": [c.id for c in context.custodians], "receivers": [r.id for r in context.receivers], "steps": [serialize_step(store, s, language) for s in context.steps], } return get_localized_values(ret_dict, context, context.localized_keys, language)
def serialize_step(store, step, language): """ Serialize a step, localizing its content depending on the language. :param step: the step to be serialized. :param language: the language in which to localize data :return: a serialization of the object """ triggered_by_options = [{ 'field': trigger.field_id, 'option': trigger.id } for trigger in step.triggered_by_options] data = db_prepare_fields_serialization(store, step.children) ret_dict = { 'id': step.id, 'questionnaire_id': step.questionnaire_id, 'presentation_order': step.presentation_order, 'triggered_by_score': step.triggered_by_score, 'triggered_by_options': triggered_by_options, 'children': [serialize_field(store, f, language, data) for f in step.children] } return get_localized_values(ret_dict, step, step.localized_keys, language)
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)
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)
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. """ ret_dict = { 'id': context.id, 'receivers': [r.id for r in context.receivers], 'tip_timetolive': context.tip_timetolive / (60 * 60 * 24), 'select_all_receivers': context.select_all_receivers, 'maximum_selectable_receivers': context.maximum_selectable_receivers, 'show_context': context.show_context, 'show_recipients_details': context.show_recipients_details, 'allow_recipients_selection': context.allow_recipients_selection, 'show_small_cards': context.show_small_cards, 'enable_comments': context.enable_comments, 'enable_messages': context.enable_messages, 'enable_two_way_comments': context.enable_two_way_comments, 'enable_two_way_messages': context.enable_two_way_messages, 'enable_attachments': context.enable_attachments, 'presentation_order': context.presentation_order, 'show_receivers_in_alphabetical_order': context.show_receivers_in_alphabetical_order, 'questionnaire_layout': context.questionnaire_layout, 'reset_questionnaire': False, 'steps': [serialize_step(store, s, language) for s in context.steps] } return get_localized_values(ret_dict, context, context.localized_keys, language)
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)
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)
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. """ receivers = [id for id in store.find(models.ReceiverContext.receiver_id, models.ReceiverContext.context_id == context.id)] picture = db_get_model_img(store, models.Context, context.id) ret_dict = { 'id': context.id, 'tip_timetolive': context.tip_timetolive, 'select_all_receivers': context.select_all_receivers, 'maximum_selectable_receivers': context.maximum_selectable_receivers, 'show_context': context.show_context, 'show_recipients_details': context.show_recipients_details, 'allow_recipients_selection': context.allow_recipients_selection, 'show_small_receiver_cards': context.show_small_receiver_cards, 'enable_comments': context.enable_comments, 'enable_messages': context.enable_messages, 'enable_two_way_comments': context.enable_two_way_comments, 'enable_two_way_messages': context.enable_two_way_messages, 'enable_attachments': context.enable_attachments, 'enable_rc_to_wb_files': context.enable_rc_to_wb_files, 'presentation_order': context.presentation_order, 'show_receivers_in_alphabetical_order': context.show_receivers_in_alphabetical_order, 'questionnaire_id': context.questionnaire_id, 'receivers': receivers, 'picture': picture } return get_localized_values(ret_dict, context, context.localized_keys, language)
def anon_serialize_context(store, context, language): """ Serialize context description @param context: a valid Storm object @return: a dict describing the contexts available for submission, (e.g. checks if almost one receiver is associated) """ receivers = [r.id for r in context.receivers] if not len(receivers): return None steps = [anon_serialize_step(store, s, language) for s in context.steps] ret_dict = { 'id': context.id, 'tip_timetolive': context.tip_timetolive, 'description': context.description, 'select_all_receivers': context.select_all_receivers, 'maximum_selectable_receivers': context.maximum_selectable_receivers, 'show_small_cards': context.show_small_cards, 'show_receivers': context.show_receivers, 'enable_comments': context.enable_comments, 'enable_private_messages': context.enable_private_messages, 'presentation_order': context.presentation_order, 'show_receivers_in_alphabetical_order': context.show_receivers_in_alphabetical_order, 'steps_arrangement': context.steps_arrangement, 'receivers': receivers, 'steps': steps } return get_localized_values(ret_dict, context, context.localized_strings, language)
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)
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)
def receiver_serialize_receiver(receiver, language): ret_dict = user_serialize_user(receiver.user, language) if receiver.user.role == 'custodian': can_postpone_expiration = False can_delete_submission = False can_grant_permissions = False tip_notification = False contexts = [] else: can_postpone_expiration = GLSettings.memory_copy.can_postpone_expiration or receiver.can_postpone_expiration can_delete_submission = GLSettings.memory_copy.can_delete_submission or receiver.can_delete_submission can_grant_permissions = GLSettings.memory_copy.can_grant_permissions or receiver.can_grant_permissions tip_notification = receiver.tip_notification contexts = [c.id for c in receiver.contexts] ret_dict.update({ 'can_postpone_expiration': can_postpone_expiration, 'can_delete_submission': can_delete_submission, 'can_grant_permissions': can_grant_permissions, 'tip_notification': tip_notification, 'contexts': contexts }) return get_localized_values(ret_dict, receiver, receiver.localized_keys, language)
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)
def receiver_serialize_receiver(store, receiver, user, language): user = store.find(models.User, id=receiver.id).one() contexts = [ id for id in store.find(models.ReceiverContext.context_id, models.ReceiverContext.receiver_id == receiver.id) ] ret_dict = user_serialize_user(store, user, language) ret_dict.update({ 'can_postpone_expiration': GLSettings.memory_copy.can_postpone_expiration or receiver.can_postpone_expiration, 'can_delete_submission': GLSettings.memory_copy.can_delete_submission or receiver.can_delete_submission, 'can_grant_permissions': GLSettings.memory_copy.can_grant_permissions or receiver.can_grant_permissions, 'tip_notification': receiver.tip_notification, 'contexts': contexts }) return get_localized_values(ret_dict, receiver, receiver.localized_keys, language)
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] ret_dict = { 'id': context.id, '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, 'maximum_selectable_receivers': context.maximum_selectable_receivers, 'show_small_cards': context.show_small_cards, 'show_receivers': context.show_receivers, 'enable_comments': context.enable_comments, 'enable_private_messages': context.enable_private_messages, 'presentation_order': context.presentation_order, 'show_receivers_in_alphabetical_order': context.show_receivers_in_alphabetical_order, 'steps_arrangement': context.steps_arrangement, 'reset_steps': False, 'steps': steps } return get_localized_values(ret_dict, context, context.localized_strings, language)
def serialize_context(store, context, language): """ Serialize context description @param context: a valid Storm object @return: a dict describing the contexts available for submission, (e.g. checks if almost one receiver is associated) """ ret_dict = { 'id': context.id, 'presentation_order': context.presentation_order, 'tip_timetolive': context.tip_timetolive, 'select_all_receivers': context.select_all_receivers, 'maximum_selectable_receivers': context.maximum_selectable_receivers, 'show_context': context.show_context, 'show_recipients_details': context.show_recipients_details, 'allow_recipients_selection': context.allow_recipients_selection, 'show_small_cards': context.show_small_cards, 'enable_comments': context.enable_comments, 'enable_messages': context.enable_messages, 'enable_two_way_comments': context.enable_two_way_comments, 'enable_two_way_messages': context.enable_two_way_messages, 'enable_attachments': context.enable_attachments, 'show_receivers_in_alphabetical_order': context.show_receivers_in_alphabetical_order, 'questionnaire': serialize_questionnaire(store, context.questionnaire, language), 'receivers': [r.id for r in context.receivers] } return get_localized_values(ret_dict, context, context.localized_keys, language)
def serialize_questionnaire(session, tid, questionnaire, language): """ Serialize the specified questionnaire :param session: the session on which perform queries. :param language: the language in which to localize data. :return: a dictionary representing the serialization of the questionnaire. """ steps = session.query(models.Step).filter( models.Step.questionnaire_id == questionnaire.id, models.Questionnaire.id == questionnaire.id) ret_dict = { 'id': questionnaire.id, 'editable': questionnaire.editable and questionnaire.tid == tid, 'name': questionnaire.name, 'steps': sorted([serialize_step(session, tid, s, language) for s in steps], key=lambda x: x['presentation_order']) } return get_localized_values(ret_dict, questionnaire, questionnaire.localized_keys, language)
def serialize_step(session, tid, step, language): """ Serialize a step, localizing its content depending on the language. :param step: the step to be serialized. :param language: the language in which to localize data :return: a serialization of the object """ children = session.query( models.Field).filter(models.Field.step_id == step.id) data = db_prepare_fields_serialization(session, children) ret_dict = { 'id': step.id, 'questionnaire_id': step.questionnaire_id, 'presentation_order': step.presentation_order, 'children': [serialize_field(session, tid, f, language, data) for f in children] } return get_localized_values(ret_dict, step, step.localized_keys, language)
def serialize_context(session, context, language, data=None): """ Serialize context description @param context: a valid Storm object @return: a dict describing the contexts available for submission, (e.g. checks if almost one receiver is associated) """ ret_dict = { 'id': context.id, 'presentation_order': context.presentation_order, 'tip_timetolive': context.tip_timetolive, 'select_all_receivers': context.select_all_receivers, 'maximum_selectable_receivers': context.maximum_selectable_receivers, 'show_context': context.show_context, 'show_recipients_details': context.show_recipients_details, 'allow_recipients_selection': context.allow_recipients_selection, 'show_small_receiver_cards': context.show_small_receiver_cards, 'enable_comments': context.enable_comments, 'enable_messages': context.enable_messages, 'enable_two_way_comments': context.enable_two_way_comments, 'enable_two_way_messages': context.enable_two_way_messages, 'enable_attachments': context.enable_attachments, 'enable_rc_to_wb_files': context.enable_rc_to_wb_files, 'show_receivers_in_alphabetical_order': context.show_receivers_in_alphabetical_order, 'questionnaire_id': context.questionnaire_id, 'receivers': data['receivers'].get(context.id, []), 'picture': data['imgs'].get(context.id, '') } return get_localized_values(ret_dict, context, context.localized_keys, language)
def receiver_serialize_receiver(receiver, node, language): ret_dict = { "id": receiver.id, "name": receiver.name, "can_postpone_expiration": node.can_postpone_expiration or receiver.can_postpone_expiration, "can_delete_submission": node.can_delete_submission or 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.user.mail_address, "ping_mail_address": receiver.ping_mail_address, "tip_expiration_threshold": receiver.tip_expiration_threshold, "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)
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)
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)
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(GLSettings.static_path, "custom_homepage.html")) ret_dict = { 'name': node.name, 'presentation': node.presentation, 'hidden_service': node.hidden_service, 'public_site': node.public_site, 'email': node.email, 'version': GLSettings.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': GLSettings.memory_copy.tor2web_admin, 'tor2web_submission': GLSettings.memory_copy.tor2web_submission, 'tor2web_receiver': GLSettings.memory_copy.tor2web_receiver, 'tor2web_unauth': GLSettings.memory_copy.tor2web_unauth, 'submission_minimum_delay' : GLSettings.memory_copy.submission_minimum_delay, 'submission_maximum_ttl' : GLSettings.memory_copy.submission_maximum_ttl, '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)
def anon_serialize_context(store, 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) """ receivers = [r.id for r in context.receivers] if not len(receivers): return None steps = [ anon_serialize_step(store, s, language) for s in context.steps.order_by(models.Step.number) ] ret_dict = { "id": context.id, "file_max_download": context.file_max_download, "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, "show_small_cards": context.show_small_cards, "show_receivers": context.show_receivers, "enable_private_messages": context.enable_private_messages, "presentation_order": context.presentation_order, "receivers": receivers, "steps": steps } return get_localized_values(ret_dict, context, context.localized_strings, language)
def admin_serialize_receiver(receiver, language): """ Serialize the specified receiver :param language: the language in which to localize data :return: a dictionary representing the serialization of the receiver """ ret_dict = user_serialize_user(receiver.user, language) ret_dict.update({ 'can_delete_submission': receiver.can_delete_submission, 'can_postpone_expiration': receiver.can_postpone_expiration, 'mail_address': receiver.user.mail_address, 'ping_mail_address': receiver.ping_mail_address, 'configuration': receiver.configuration, 'contexts': [c.id for c in receiver.contexts], 'tip_notification': receiver.tip_notification, 'ping_notification': receiver.ping_notification, 'presentation_order': receiver.presentation_order, 'tip_expiration_threshold': receiver.tip_expiration_threshold, }) return get_localized_values(ret_dict, receiver, receiver.localized_keys, language)
def admin_serialize_receiver(receiver, language): """ Serialize the specified receiver :param language: the language in which to localize data :return: a dictionary representing the serialization of the receiver """ ret_dict = { 'id': receiver.id, 'name': receiver.name, 'can_delete_submission': receiver.can_delete_submission, 'can_postpone_expiration': receiver.can_postpone_expiration, 'username': receiver.user.username, 'mail_address': receiver.user.mail_address, 'ping_mail_address': receiver.ping_mail_address, 'password': u'', 'state': receiver.user.state, 'configuration': receiver.configuration, 'contexts': [c.id for c in receiver.contexts], 'pgp_key_info': receiver.pgp_key_info, 'pgp_key_public': receiver.pgp_key_public, 'pgp_key_remove': False, 'pgp_key_fingerprint': receiver.pgp_key_fingerprint, '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, 'presentation_order': receiver.presentation_order, 'language': receiver.user.language, 'timezone': receiver.user.timezone, 'tip_expiration_threshold': receiver.tip_expiration_threshold, 'password_change_needed': receiver.user.password_change_needed, } return get_localized_values(ret_dict, receiver, receiver.localized_strings, language)
def serialize_context(store, context, language): """ Serialize context description @param context: a valid Storm object @return: a dict describing the contexts available for submission, (e.g. checks if almost one receiver is associated) """ ret_dict = { 'id': context.id, 'presentation_order': context.presentation_order, 'tip_timetolive': context.tip_timetolive, 'select_all_receivers': context.select_all_receivers, 'maximum_selectable_receivers': context.maximum_selectable_receivers, 'show_context': context.show_context, 'show_recipients_details': context.show_recipients_details, 'allow_recipients_selection': context.allow_recipients_selection, 'show_small_cards': context.show_small_cards, 'enable_comments': context.enable_comments, 'enable_messages': context.enable_messages, 'enable_two_way_comments': context.enable_two_way_comments, 'enable_two_way_messages': context.enable_two_way_messages, 'enable_attachments': context.enable_attachments, 'field_whistleblower_identity': '', 'show_receivers_in_alphabetical_order': context.show_receivers_in_alphabetical_order, 'questionnaire_layout': context.questionnaire_layout, 'receivers': [r.id for r in context.receivers], 'steps': [serialize_step(store, s, language) for s in context.steps] } return get_localized_values(ret_dict, context, context.localized_keys, language)
def _db_get_archived_questionnaire_schema(store, hash, type, language): aqs = store.find(models.ArchivedSchema, models.ArchivedSchema.hash == hash, models.ArchivedSchema.type == type).one() if not aqs: log.err("Unable to find questionnaire schema with hash %s" % hash) questionnaire = [] else: questionnaire = copy.deepcopy(aqs.schema) for step in questionnaire: for field in step['children']: _db_get_archived_field_recursively(field, language) get_localized_values(step, step, models.Step.localized_keys, language) return questionnaire
def _db_get_archived_field_recursively(field, language): for key, value in field.get('attrs', {}).iteritems(): if key not in field['attrs']: continue if 'type' not in field['attrs'][key]: continue if field['attrs'][key]['type'] == u'localized': if language in field['attrs'][key].get('value', []): field['attrs'][key]['value'] = field['attrs'][key]['value'][language] else: field['attrs'][key]['value'] = "" for o in field.get('options', []): get_localized_values(o, o, models.FieldOption.localized_keys, language) for c in field.get('children', []): _db_get_archived_field_recursively(c, language) return get_localized_values(field, field, models.Field.localized_keys, language)
def anon_serialize_option(option, field_type, language): """ Serialize a field option, localizing its content depending on the language. :param option: the field option object to be serialized :param language: the language in which to localize data :return: a serialization of the object """ ret_dict = { 'id': option.id, 'attrs': {}, 'value': '' } keys = get_field_option_localized_keys(field_type) get_localized_values(ret_dict['attrs'], option.attrs, keys, language) return ret_dict
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)
def _db_get_archived_field_recursively(field, language): for key, value in field.get("attrs", {}).iteritems(): if key not in field["attrs"]: continue if "type" not in field["attrs"][key]: continue if field["attrs"][key]["type"] == u"localized": if language in field["attrs"][key].get("value", []): field["attrs"][key]["value"] = field["attrs"][key]["value"][language] else: field["attrs"][key]["value"] = "" for o in field.get("options", []): get_localized_values(o, o, models.FieldOption.localized_keys, language) for c in field.get("children", []): _db_get_archived_field_recursively(c, language) return get_localized_values(field, field, models.Field.localized_keys, language)
def serialize_field_attr(attr, language): """ Serialize a field attribute, localizing its content depending on the language. :param option: the field attribute object to be serialized :param language: the language in which to localize data :return: a serialization of the object """ ret_dict = { 'id': attr.id, 'name': attr.name, 'type': attr.type, 'value': attr.value } if attr.type == 'bool': ret_dict['value'] = True if ret_dict['value'] == 'True' else False elif attr.type == u'localized': get_localized_values(ret_dict, ret_dict, ['value'], language) return ret_dict
def receiver_serialize_receiver(receiver, language): ret_dict = user_serialize_user(receiver.user, language) ret_dict.update({ 'can_postpone_expiration': GLSettings.memory_copy.can_postpone_expiration or receiver.can_postpone_expiration, 'can_delete_submission': GLSettings.memory_copy.can_delete_submission or receiver.can_delete_submission, 'can_grant_permissions': GLSettings.memory_copy.can_grant_permissions or receiver.can_grant_permissions, 'tip_notification': receiver.tip_notification, 'contexts': [c.id for c in receiver.contexts] }) return get_localized_values(ret_dict, receiver, receiver.localized_keys, language)
def serialize_node(store, language): """ Serialize node infos. """ node = store.find(models.Node).one() # Contexts and Receivers relationship configured = store.find(models.ReceiverContext).count() > 0 ret_dict = { "name": node.name, "hidden_service": node.hidden_service, "public_site": node.public_site, "languages_enabled": node.languages_enabled, "languages_supported": LANGUAGES_SUPPORTED, "default_language": node.default_language, "default_timezone": node.default_timezone, "maximum_namesize": node.maximum_namesize, "maximum_textsize": node.maximum_textsize, "maximum_filesize": node.maximum_filesize, "tor2web_admin": node.tor2web_admin, "tor2web_custodian": node.tor2web_custodian, "tor2web_whistleblower": node.tor2web_whistleblower, "tor2web_receiver": node.tor2web_receiver, "tor2web_unauth": node.tor2web_unauth, "submission_minimum_delay": 0 if GLSettings.devel_mode else GLSettings.memory_copy.submission_minimum_delay, "submission_maximum_ttl": GLSettings.memory_copy.submission_maximum_ttl, "ahmia": node.ahmia, "can_postpone_expiration": node.can_postpone_expiration, "can_delete_submission": node.can_delete_submission, "can_grant_permissions": node.can_grant_permissions, "wizard_done": node.wizard_done, "allow_unencrypted": node.allow_unencrypted, "allow_iframes_inclusion": node.allow_iframes_inclusion, "configured": configured, "password": u"", "old_password": u"", "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, "disable_donation_panel": node.disable_donation_panel, "simplified_login": node.simplified_login, "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, "accept_submissions": GLSettings.accept_submissions, "enable_captcha": node.enable_captcha, "enable_proof_of_work": node.enable_proof_of_work, } return get_localized_values(ret_dict, node, node.localized_keys, language)
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 ret_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, 'default_timezone' : node.default_timezone, # 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, 'allow_unencrypted': node.allow_unencrypted, '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, '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)