def db_serialize_node(session, tid, language): """ Serialize node info. """ # Contexts and Receivers relationship configured = session.query(models.ReceiverContext).filter( models.ReceiverContext.context_id == models.Context.id, models.Context.tid == tid).count() > 0 node_dict = ConfigFactory(session, tid, 'public_node').serialize() l10n_dict = NodeL10NFactory(session, tid).localized_dict(language) ret_dict = merge_dicts(node_dict, l10n_dict) ret_dict['root_tenant'] = tid == 1 ret_dict['languages_enabled'] = models.EnabledLanguage.list( session, tid) if node_dict['wizard_done'] else list(LANGUAGES_SUPPORTED_CODES) ret_dict['languages_supported'] = LANGUAGES_SUPPORTED ret_dict['configured'] = configured ret_dict['accept_submissions'] = State.accept_submissions ret_dict['logo'] = db_get_file(session, tid, u'logo') ret_dict['favicon'] = db_get_file(session, tid, u'favicon') ret_dict['css'] = db_get_file(session, tid, u'css') ret_dict['script'] = db_get_file(session, tid, u'script') if tid != 1: root_tenant_node = ConfigFactory(session, 1, 'public_node') if language not in models.EnabledLanguage.list(session, tid): language = root_tenant_node.get_val(u'default_language') for x in [u'logo', u'favicon', u'css', u'scripts']: if not ret_dict[x]: ret_dict[x] = db_get_file(session, 1, x) root_tenant_l10n = NodeL10NFactory(session, tid) if not root_tenant_node.get_val(u'enable_footer_customization'): ret_dict['footer'] = root_tenant_l10n.get_val(u'footer', language) if ret_dict['mode'] == u'whistleblowing.it': ret_dict['whistleblowing_question'] = root_tenant_l10n.get_val( u'whistleblowing_question', language) ret_dict['whistleblowing_button'] = root_tenant_l10n.get_val( u'whistleblowing_button', language) ret_dict['enable_disclaimer'] = root_tenant_node.get_val( u'enable_disclaimer') ret_dict['disclaimer_title'] = root_tenant_l10n.get_val( u'disclaimer_title', language) ret_dict['disclaimer_text'] = root_tenant_l10n.get_val( u'disclaimer_text', language) return ret_dict
def db_admin_serialize_node(session, tid, language, config_node='admin_node'): config = ConfigFactory(session, tid, config_node).serialize() # Contexts and Receivers relationship configured = session.query(models.ReceiverContext).filter( models.ReceiverContext.context_id == models.Context.id, models.Context.tid).count() > 0 misc_dict = { 'languages_supported': LANGUAGES_SUPPORTED, 'languages_enabled': models.EnabledLanguage.list(session, tid), 'configured': configured, 'root_tenant': tid == 1, 'https_possible': tid == 1 or State.tenant_cache[1].reachable_via_web, } if tid != 1: root_tenant_node = ConfigFactory(session, 1, 'node') misc_dict['version'] = root_tenant_node.get_val(u'version') misc_dict['latest_version'] = root_tenant_node.get_val( u'latest_version') misc_dict['enable_footer_customization'] = root_tenant_node.get_val( u'enable_footer_customization') l10n_dict = NodeL10NFactory(session, tid).localized_dict(language) return utils.sets.merge_dicts(config, misc_dict, l10n_dict)
def db_update_node(session, tid, request, language): """ Update and serialize the node infos :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 node """ node = ConfigFactory(session, tid, 'node') if tid != 1: request['enable_signup'] = False node.update(request) if request['basic_auth'] and request['basic_auth_username'] and request['basic_auth_password']: node.set_val(u'basic_auth', True) node.set_val(u'basic_auth_username', request['basic_auth_username']) node.set_val(u'basic_auth_password', request['basic_auth_password']) else: node.set_val(u'basic_auth', False) db_update_enabled_languages(session, tid, request['languages_enabled'], request['default_language']) if language in request['languages_enabled']: node_l10n = NodeL10NFactory(session, tid) node_l10n.update(request, language) db_refresh_memory_variables(session, [tid]) # TODO pass instance of db_update_node into admin_serialize return db_admin_serialize_node(session, tid, language)
def db_serialize_node(session, tid, language): """ Serialize node info. """ # Contexts and Receivers relationship configured = session.query(models.ReceiverContext).filter( models.ReceiverContext.context_id == models.Context.id, models.Context.tid == tid).count() > 0 node = ConfigFactory(session, tid, 'public_node').serialize() misc_dict = { 'languages_enabled': models.EnabledLanguage.list(session, tid) if node['wizard_done'] else list(LANGUAGES_SUPPORTED_CODES), 'languages_supported': LANGUAGES_SUPPORTED, 'configured': configured, 'accept_submissions': State.accept_submissions, 'logo': db_get_file(session, tid, u'logo'), 'favicon': db_get_file(session, tid, u'favicon'), 'css': db_get_file(session, tid, u'css'), 'homepage': db_get_file(session, tid, u'homepage'), 'script': db_get_file(session, tid, u'script') } l10n_dict = NodeL10NFactory(session, tid).localized_dict(language) if tid != 1: root_tenant_node = ConfigFactory(session, 1, 'public_node') misc_dict['enable_footer_customization'] = root_tenant_node.get_val( u'enable_footer_customization') if language not in models.EnabledLanguage.list(session, tid): language = root_tenant_node.get_val(u'default_language') root_tenant_l10n = NodeL10NFactory(session, tid) l10n_dict['footer'] = root_tenant_l10n.get_val(u'footer', language) return merge_dicts(node, l10n_dict, misc_dict)
def db_update_node(session, tid, request, language, config_node): """ Update and serialize the node infos :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 node """ node = ConfigFactory(session, tid, config_node) node.update(request) if 'basic_auth' in request: if request['basic_auth'] and request[ 'basic_auth_username'] and request['basic_auth_password']: node.set_val(u'basic_auth', True) node.set_val(u'basic_auth_username', request['basic_auth_username']) node.set_val(u'basic_auth_password', request['basic_auth_password']) else: node.set_val(u'basic_auth', False) # Validate that IP addresses/ranges we're getting are goo if 'ip_filter_authenticated' in request: if request['ip_filter_authenticated_enable'] and request[ 'ip_filter_authenticated']: # Make sure we can validate and parse the whole thing parse_csv_ip_ranges_to_ip_networks( request['ip_filter_authenticated']) if 'languages_enabled' in request and 'default_language' in request: db_update_enabled_languages(session, tid, request['languages_enabled'], request['default_language']) if language in models.EnabledLanguage.list(session, tid): node_l10n = NodeL10NFactory(session, tid) node_l10n.update(request, language) db_refresh_memory_variables(session, [tid]) return db_admin_serialize_node(session, tid, language)