Beispiel #1
0
def db_refresh_memory_variables(store):
    """
    This routine loads in memory few variables of node and notification tables
    that are subject to high usage.
    """
    node_ro = ObjectDict(NodeFactory(store).admin_export())

    GLSettings.memory_copy = node_ro

    GLSettings.memory_copy.accept_tor2web_access = {
        'admin': node_ro.tor2web_admin,
        'custodian': node_ro.tor2web_custodian,
        'whistleblower': node_ro.tor2web_whistleblower,
        'receiver': node_ro.tor2web_receiver
    }

    enabled_langs = models.l10n.EnabledLanguage.list(store)
    GLSettings.memory_copy.languages_enabled = enabled_langs

    notif_fact = NotificationFactory(store)
    notif_ro = ObjectDict(notif_fact.admin_export())

    GLSettings.memory_copy.notif = notif_ro

    if GLSettings.developer_name:
        GLSettings.memory_copy.notif.source_name = GLSettings.developer_name

    db_refresh_exception_delivery_list(store)

    GLSettings.memory_copy.private = ObjectDict(
        PrivateFactory(store).mem_copy_export())
Beispiel #2
0
def db_refresh_memory_variables(store):
    """
    This routine loads in memory few variables of node and notification tables
    that are subject to high usage.
    """
    node_ro = ObjectDict(NodeFactory(store).admin_export())

    GLSettings.memory_copy = node_ro

    GLSettings.memory_copy.accept_tor2web_access = {
        'admin': node_ro.tor2web_admin,
        'custodian': node_ro.tor2web_custodian,
        'whistleblower': node_ro.tor2web_whistleblower,
        'receiver': node_ro.tor2web_receiver,
        'unauth': node_ro.tor2web_unauth
    }

    enabled_langs = models.l10n.EnabledLanguage.get_all_strings(store)
    GLSettings.memory_copy.languages_enabled = enabled_langs

    notif_ro = ObjectDict(NotificationFactory(store).admin_export())

    GLSettings.memory_copy.notif = notif_ro

    if GLSettings.developer_name:
        GLSettings.memory_copy.notif.source_name = GLSettings.developer_name

    if GLSettings.disable_mail_notification:
        GLSettings.memory_copy.notif.disable_admin_notification_emails = True
        GLSettings.memory_copy.notif.disable_custodian_notification_emails = True
        GLSettings.memory_copy.notif.disable_receiver_notification_emails = True

    GLSettings.memory_copy.private = ObjectDict(
        PrivateFactory(store).mem_copy_export())
Beispiel #3
0
def db_refresh_exception_delivery_list(store):
    """
    Constructs a list of (email_addr, public_key) pairs that will receive errors from the platform.
    If the email_addr is empty, drop the tuple from the list.
    """
    notif_fact = NotificationFactory(store)
    error_addr = notif_fact.get_val('exception_email_address')
    error_pk = notif_fact.get_val('exception_email_pgp_key_public')

    lst = [(error_addr, error_pk)]

    results = store.find(User, User.role==unicode('admin')) \
                   .values(User.mail_address, User.pgp_key_public)

    lst.extend([(mail, pub_key) for (mail, pub_key) in results])
    trimmed = filter(lambda x: x[0] != '', lst)
    GLSettings.memory_copy.notif.exception_delivery_list = trimmed
Beispiel #4
0
def update_notification(store, request, language):
    notif = NotificationFactory(store)
    notif.update(request)

    smtp_pw = request.pop('smtp_password', u'')
    if smtp_pw != u'':
        PrivateFactory(store).set_val(u'smtp_password', smtp_pw)

    notif_l10n = NotificationL10NFactory(store)
    notif_l10n.update(request, language)

    if request.pop('reset_templates'):
        notif_l10n.reset_templates(load_appdata())

    # Since the Notification object has been changed refresh the global copy.
    db_refresh_memory_variables(store)

    return admin_serialize_notification(store, language)
Beispiel #5
0
def admin_serialize_notification(store, language):
    config_dict = NotificationFactory(store).admin_export()
    conf_l10n_dict = NotificationL10NFactory(store).localized_dict(language)

    cmd_flags = {
        'reset_templates': False,
        'exception_email_pgp_key_remove': False,
        'smtp_password': '',
    }

    return merge_dicts(config_dict, cmd_flags, conf_l10n_dict)
Beispiel #6
0
def update_notification(store, request, language):
    notif_l10n = NotificationL10NFactory(store)
    notif_l10n.update(request, language)

    if request.pop('reset_templates'):
        appdata = load_appdata()
        notif_l10n.reset_templates(appdata)

    smtp_pw = request.pop('smtp_password', u'')
    if smtp_pw != u'':
        PrivateFactory(store).set_val('smtp_password', smtp_pw)

    notif = NotificationFactory(store)
    notif.update(request)

    parse_pgp_options(notif, request)

    # Since the Notification object has been changed refresh the global copy.
    db_refresh_memory_variables(store)

    return admin_serialize_notification(store, language)
Beispiel #7
0
def db_refresh_memory_variables(store):
    """
    This routine loads in memory few variables of node and notification tables
    that are subject to high usage.
    """
    node_ro = ObjectDict(NodeFactory(store).admin_export())

    GLSettings.memory_copy = node_ro

    GLSettings.memory_copy.accept_tor2web_access = {
        'admin': node_ro.tor2web_admin,
        'custodian': node_ro.tor2web_custodian,
        'whistleblower': node_ro.tor2web_whistleblower,
        'receiver': node_ro.tor2web_receiver
    }

    enabled_langs = models.l10n.EnabledLanguage.list(store)
    GLSettings.memory_copy.languages_enabled = enabled_langs

    notif_fact = NotificationFactory(store)
    notif_ro = ObjectDict(notif_fact.admin_export())

    GLSettings.memory_copy.notif = notif_ro

    if GLSettings.developer_name:
        GLSettings.memory_copy.notif.source_name = GLSettings.developer_name

    db_refresh_exception_delivery_list(store)

    GLSettings.memory_copy.private = ObjectDict(
        PrivateFactory(store).mem_copy_export())

    if GLSettings.memory_copy.private.admin_api_token_digest != '':
        api_id = store.find(User.id, User.role == u'admin').order_by(
            User.creation_date).first()
        if api_id is not None:
            GLSettings.appstate.api_token_session = GLSession(
                api_id, 'admin', 'enabled')