def test_delete_propagate(mocker): Setting = mocker.patch('indico.core.settings.core.Setting') SettingPrincipal = mocker.patch('indico.core.settings.core.SettingPrincipal') proxy = SettingsProxy('foo', {'reg': None}, acls={'acl'}) proxy.delete('reg', 'acl') Setting.delete.assert_called_once_with('foo', 'reg') SettingPrincipal.delete.assert_called_with('foo', 'acl')
def test_delete_propagate(mocker): Setting = mocker.patch('indico.core.settings.proxy.Setting') SettingPrincipal = mocker.patch('indico.core.settings.proxy.SettingPrincipal') proxy = SettingsProxy('foo', {'reg': None}, acls={'acl'}) proxy.delete('reg', 'acl') Setting.delete.assert_called_once_with('foo', 'reg') SettingPrincipal.delete.assert_called_with('foo', 'acl')
def test_proxy_strict(): proxy = SettingsProxy('test', {'hello': 'world'}) pytest.raises(ValueError, proxy.get, 'foo') pytest.raises(ValueError, proxy.get, 'foo', 'bar') pytest.raises(ValueError, proxy.set, 'foo', 'foobar') pytest.raises(ValueError, proxy.set_multi, {'hello': 'world', 'foo': 'foobar'}) pytest.raises(ValueError, proxy.delete, 'hello', 'foo') assert proxy.get('hello') == 'world'
def test_set_multi_propagate(mocker): Setting = mocker.patch('indico.core.settings.proxy.Setting') SettingPrincipal = mocker.patch( 'indico.core.settings.proxy.SettingPrincipal') proxy = SettingsProxy('foo', {'reg': None}, acls={'acl'}) proxy.set_multi({'reg': 'bar', 'acl': {'u'}}) Setting.set_multi.assert_called_once_with('foo', {'reg': 'bar'}) SettingPrincipal.set_acl_multi.assert_called_with('foo', {'acl': {'u'}})
def test_prefix_settings_invalid(): foo_proxy = SettingsProxy('foo', {'a': 1, 'b': 2}) bar_proxy = SettingsProxy('bar', {'x': 3, 'y': 4}) proxy = PrefixSettingsProxy({'foo': foo_proxy, 'bar': bar_proxy}) pytest.raises(ValueError, proxy.get, 'x') pytest.raises(ValueError, proxy.get, 'x_y') pytest.raises(ValueError, proxy.set, 'x', 'test') pytest.raises(ValueError, proxy.set, 'x_y', 'test')
def test_proxy_defaults(): proxy = SettingsProxy('test', {'hello': 'world', 'foo': None}) assert proxy.get('hello') == 'world' assert proxy.get('foo') is None assert proxy.get('foo', 'bar') == 'bar' assert not proxy.get_all(True) proxy.set('foo', 'bar') assert proxy.get_all(True) == {'foo': 'bar'} assert proxy.get_all() == {'hello': 'world', 'foo': 'bar'}
def test_set_multi_propagate(mocker): Setting = mocker.patch('indico.core.settings.core.Setting') SettingPrincipal = mocker.patch('indico.core.settings.core.SettingPrincipal') proxy = SettingsProxy('foo', {'reg': None}, acls={'acl'}) proxy.set_multi({ 'reg': 'bar', 'acl': {'u'} }) Setting.set_multi.assert_called_once_with('foo', {'reg': 'bar'}) SettingPrincipal.set_acl_multi.assert_called_with('foo', {'acl': {'u'}})
def test_proxy_delete_all(): defaults = {'hello': 'world', 'foo': None} proxy = SettingsProxy('test', defaults) assert proxy.get_all() == defaults proxy.set('hello', 'test') assert proxy.get_all() == {'hello': 'test', 'foo': None} proxy.delete_all() assert proxy.get_all() == defaults
def settings(cls): """:class:`SettingsProxy` for the plugin's settings""" if cls.name is None: raise RuntimeError('Plugin has not been loaded yet') instance = cls.instance with instance.plugin_context(): # in case the default settings come from a property return SettingsProxy('plugin_{}'.format(cls.name), instance.default_settings, cls.strict_settings, acls=cls.acl_settings, converters=cls.settings_converters)
def test_acls_invalid(): user = User() proxy = SettingsProxy('foo', {'reg': None}, acls={'acl'}) pytest.raises(ValueError, proxy.get, 'acl') pytest.raises(ValueError, proxy.set, 'acl', 'foo') pytest.raises(ValueError, proxy.acls.get, 'reg') pytest.raises(ValueError, proxy.acls.set, 'reg', {user}) pytest.raises(ValueError, proxy.acls.contains_user, 'reg', user) pytest.raises(ValueError, proxy.acls.add_principal, 'reg', user) pytest.raises(ValueError, proxy.acls.remove_principal, 'reg', user)
def test_acls(dummy_user, create_user): other_user = create_user(123) proxy = SettingsProxy('foo', acls={'acl'}) assert proxy.acls.get('acl') == set() proxy.acls.set('acl', {dummy_user}) assert proxy.acls.get('acl') == {dummy_user} assert proxy.acls.contains_user('acl', dummy_user) assert not proxy.acls.contains_user('acl', other_user) proxy.acls.add_principal('acl', other_user) assert proxy.acls.contains_user('acl', other_user) assert proxy.acls.get('acl') == {dummy_user, other_user} proxy.acls.remove_principal('acl', dummy_user) assert proxy.acls.get('acl') == {other_user}
def test_proxy_converters_all(): epoch_dt = datetime(1970, 1, 1, tzinfo=pytz.utc) xmas_dt = datetime(2016, 12, 24, 20, tzinfo=pytz.utc) newyear_dt = datetime(2017, 1, 2, tzinfo=pytz.utc) duration = timedelta(days=2) defaults = {'epoch': epoch_dt, 'xmas': None, 'newyear': None, 'duration': None} converters = {name: DatetimeConverter if name != 'duration' else TimedeltaConverter for name in defaults} proxy = SettingsProxy('test', defaults, converters=converters) proxy.set('xmas', xmas_dt) proxy.set_multi({'newyear': newyear_dt, 'duration': duration}) assert proxy.get_all() == {'epoch': epoch_dt, 'xmas': xmas_dt, 'newyear': newyear_dt, 'duration': duration}
def test_proxy_preload(count_queries): defaults = {'hello': 'world', 'foo': None, 'bar': None} proxy = SettingsProxy('test', defaults) proxy.set('bar', 'test') with count_queries() as cnt: # this one preloads assert proxy.get('hello') == 'world' assert cnt() == 1 with count_queries() as cnt: # this one has no value in the db assert proxy.get('foo') is None assert proxy.get('foo', 'bar') == 'bar' assert cnt() == 0 with count_queries() as cnt: assert proxy.get('bar') is 'test' assert cnt() == 0
def test_proxy_strict_nodefaults(): with pytest.raises(ValueError): SettingsProxy('test', {})
from indico.util.i18n import _ from indico.web.flask.util import url_for from indico.web.menu import SideMenuItem, TopMenuItem logger = Logger.get('rb') rb_cache = make_scoped_cache('roombooking') rb_settings = SettingsProxy( 'roombooking', { 'managers_edit_rooms': False, 'excluded_categories': [], 'notification_before_days': 2, 'notification_before_days_weekly': 5, 'notification_before_days_monthly': 7, 'notifications_enabled': True, 'end_notification_daily': 1, 'end_notification_weekly': 3, 'end_notification_monthly': 7, 'end_notifications_enabled': True, 'booking_limit': 365, 'tileserver_url': None, 'grace_period': None, }, acls={'admin_principals', 'authorized_principals'}, converters={'excluded_categories': ModelListConverter(Category)}) @signals.core.import_tasks.connect def _import_tasks(sender, **kwargs): import indico.modules.rb.tasks # noqa: F401
from indico.web.flask.util import url_for from indico.web.menu import SideMenuItem _DEFAULT_RESTRICTED_DISCLAIMER = ("Circulation to people other than the intended audience is not authorized. " "You are obliged to treat the information with the appropriate level of " "confidentiality.") _DEFAULT_PROTECTED_DISCLAIMER = ("As such, this information is intended for an internal audience only. " "You are obliged to treat the information with the appropriate level of " "confidentiality.") legal_settings = SettingsProxy('legal', { 'network_protected_disclaimer': _DEFAULT_PROTECTED_DISCLAIMER, 'restricted_disclaimer': _DEFAULT_RESTRICTED_DISCLAIMER, 'tos_url': '', 'tos': '', 'privacy_policy_url': '', 'privacy_policy': '' }) '''@signals.menu.items.connect_via('admin-sidemenu') def _sidemenu_items(sender, **kwargs): if session.user.is_admin: yield SideMenuItem('legal_messages', _('Legal/Disclaimers'), url_for('legal.manage'), section='security')''' @template_hook('page-footer', priority=50) def _inject_tos_footer(**kwargs): url = legal_settings.get('tos_url') if url or legal_settings.get('tos'):
def test_get_all_acls(): proxy = SettingsProxy('foo', {'reg': None}, acls={'acl'}) assert proxy.get_all() == {'reg': None, 'acl': set()}
def test_proxy_strict_off(): proxy = SettingsProxy('test', {}, False) assert proxy.get('foo') is None proxy.get('foo', 'bar') == 'bar' proxy.set('foo', 'foobar') assert proxy.get('foo') == 'foobar'
from indico.core.settings import SettingsProxy from indico.core.settings.converters import DatetimeConverter from indico.util.date_time import now_utc from indico.util.i18n import _ from indico.web.flask.templating import template_hook from indico.web.flask.util import url_for from indico.web.menu import SideMenuItem __all__ = ('celery', ) #: The Celery instance for all Indico tasks celery = IndicoCelery('indico') celery_settings = SettingsProxy('celery', { 'last_ping': None, 'last_ping_version': None }, converters={'last_ping': DatetimeConverter}) @signals.app_created.connect def _load_default_modules(app, **kwargs): celery.loader.import_default_modules() # load all tasks @import_modules.connect def _import_modules(*args, **kwargs): import indico.core.emails # noqa: F401 import indico.util.tasks # noqa: F401 signals.import_tasks.send()
def test_proxy_cache_mutable(): proxy = SettingsProxy('test', {'foo': []}) foo = proxy.get('foo') assert foo is not proxy.defaults['foo'] foo.append('test') assert not proxy.get('foo')
'lang': None, 'timezone': None, 'force_timezone': False, # always use the user's timezone instead of an event's timezone 'show_future_events': False, 'show_past_events': False, 'name_format': NameFormat.first_last, 'use_previewer_pdf': True, 'synced_fields': None, # None to synchronize all fields, empty set to not synchronize 'suggest_categories': False # whether the user should receive category suggestions }, converters={'name_format': EnumConverter(NameFormat)}) user_management_settings = SettingsProxy('user_management', {'notify_account_creation': False}) @signals.category.deleted.connect def _category_deleted(category, **kwargs): category.favorite_of.clear() @signals.menu.items.connect_via('admin-sidemenu') def _extend_admin_menu(sender, **kwargs): if session.user.is_admin: yield SideMenuItem('admins', _("Admins"), url_for('users.admins'), section='user_management') yield SideMenuItem('users',
CONDITIONS = ( "CANCELLATION:\n" "All refunds requests must be in writing by mail to the Conference Secretary as soon as possible.\n" "The Conference committee reserves the right to refuse reimbursement of part or all of the fee in the " "case of late cancellation. However, each case of cancellation would be considered individually." ) settings = SettingsProxy( 'payment', { 'currencies': [{ 'code': 'EUR', 'name': 'Euro' }, { 'code': 'USD', 'name': 'US Dollar' }], 'currency': 'EUR', 'conditions': CONDITIONS, 'checkout_session_timeout': 10 }) event_settings = EventSettingsProxy('payment', { 'currency': None, 'conditions': None, }) @signals.menu.items.connect_via('admin-sidemenu')
__all__ = ('settings', ) class APIMode(int, IndicoEnum): KEY = 0 # public requests without API key, authenticated requests with api key ONLYKEY = 1 # all requests require an API key SIGNED = 2 # public requests without API key, authenticated requests with api key and signature ONLYKEY_SIGNED = 3 # all requests require an API key, authenticated requests need signature ALL_SIGNED = 4 # all requests require an api key and a signature api_settings = SettingsProxy( 'api', { 'allow_persistent': False, 'security_mode': APIMode.KEY.value, 'cache_ttl': 600, 'signature_ttl': 600 }) @signals.users.merged.connect def _merge_users(target, source, **kwargs): # Get the current active API keys ak_user = target.api_key ak_merged = source.api_key # Move all inactive keys to the new user APIKey.find(user_id=source.id, is_active=False).update({'user_id': target.id}) if ak_merged and not ak_user: ak_merged.user = target
from indico.modules.rb.models.locations import Location from indico.modules.rb.models.reservations import Reservation from indico.modules.rb.models.rooms import Room from indico.modules.rb.util import rb_is_admin from indico.util.i18n import _ from indico.web.flask.util import url_for from indico.web.menu import SideMenuItem, SideMenuSection, TopMenuItem logger = Logger.get('rb') rb_settings = SettingsProxy('roombooking', { 'google_maps_api_key': '', 'assistance_emails': [], 'vc_support_emails': [], 'notification_before_days': 2, 'notification_before_days_weekly': 5, 'notification_before_days_monthly': 7, 'notifications_enabled': True, 'booking_limit': 365 }, acls={'admin_principals', 'authorized_principals'}) @signals.import_tasks.connect def _import_tasks(sender, **kwargs): import indico.modules.rb.tasks @signals.menu.items.connect_via('admin-sidemenu') def _extend_admin_menu(sender, **kwargs): if not config.ENABLE_ROOMBOOKING:
from indico.core import signals from indico.core.db.sqlalchemy.protection import make_acl_log_fn from indico.core.logger import Logger from indico.core.permissions import ManagementPermission, check_permissions from indico.core.settings import SettingsProxy from indico.modules.categories.models.categories import Category from indico.modules.logs.models.entries import CategoryLogRealm from indico.util.i18n import _ from indico.web.flask.util import url_for from indico.web.menu import SideMenuItem logger = Logger.get('categories') upcoming_events_settings = SettingsProxy('upcoming_events', { 'entries': [], 'max_entries': 10 }) # Log ACL changes signals.acl.entry_changed.connect(make_acl_log_fn(Category, CategoryLogRealm.category), sender=Category, weak=False) @signals.core.import_tasks.connect def _import_tasks(sender, **kwargs): import indico.modules.categories.tasks # noqa: F401 @signals.users.merged.connect
from indico.web.flask.util import url_for from indico.web.menu import SideMenuItem __all__ = ('settings', 'event_settings', 'PaymentPluginMixin', 'PaymentPluginSettingsFormBase', 'PaymentEventSettingsFormBase') CONDITIONS = ("CANCELLATION:\n" "All refunds requests must be in writing by mail to the Conference Secretary as soon as possible.\n" "The Conference committee reserves the right to refuse reimbursement of part or all of the fee in the " "case of late cancellation. However, each case of cancellation would be considered individually.") settings = SettingsProxy('payment', { 'currencies': [{'code': 'EUR', 'name': 'Euro'}, {'code': 'USD', 'name': 'US Dollar'}], 'currency': 'EUR', 'conditions': CONDITIONS }) event_settings = EventSettingsProxy('payment', { 'currency': None, 'conditions': None, }) @signals.menu.items.connect_via('admin-sidemenu') def _extend_admin_menu(sender, **kwargs): if session.user.is_admin: return SideMenuItem('payment', _("Payment"), url_for('payment.admin_settings'), section='customization')
# You should have received a copy of the GNU General Public License # along with Indico; if not, see <http://www.gnu.org/licenses/>. from __future__ import unicode_literals from indico.core import signals from indico.core.logger import Logger from indico.core.settings import SettingsProxy from indico.util.i18n import _ from indico.web.flask.util import url_for from indico.web.menu import SideMenuItem __all__ = ('logger', 'cephalopod_settings') logger = Logger.get('cephalopod') cephalopod_settings = SettingsProxy('cephalopod', { 'joined': False, 'contact_email': None, 'contact_name': None, 'uuid': None }) @signals.menu.items.connect_via('admin-sidemenu') def _extend_admin_menu(sender, **kwargs): return SideMenuItem('cephalopod', _("Community Hub"), url_for('cephalopod.index'), section='integration')
from indico.modules.rb.models.blocking_principals import BlockingPrincipal from indico.modules.rb.models.blockings import Blocking from indico.modules.rb.models.locations import Location from indico.modules.rb.models.reservations import Reservation from indico.modules.rb.models.rooms import Room from indico.modules.rb.util import rb_is_admin from indico.web.flask.util import url_for from indico.util.i18n import _ from indico.web.menu import SideMenuSection, SideMenuItem logger = Logger.get('rb') settings = SettingsProxy('roombooking', { 'assistance_emails': [], 'vc_support_emails': [], 'notification_hour': 6, 'notification_before_days': 1, 'notifications_enabled': True }, acls={'admin_principals', 'authorized_principals'}) @signals.import_tasks.connect def _import_tasks(sender, **kwargs): import indico.modules.rb.tasks @signals.menu.items.connect_via('admin-sidemenu') def _extend_admin_menu(sender, **kwargs): return SideMenuItem('rb', _("Rooms"), url_for('rooms_admin.settings'),
from flask import session from indico.core import signals from indico.core.logger import Logger from indico.core.settings import SettingsProxy from indico.util.i18n import _ from indico.web.flask.util import url_for from indico.web.menu import SideMenuItem __all__ = ('logger', 'cephalopod_settings') logger = Logger.get('cephalopod') cephalopod_settings = SettingsProxy( 'cephalopod', { 'show_migration_message': False, 'joined': False, 'contact_email': None, 'contact_name': None, 'uuid': None }) @signals.menu.items.connect_via('admin-sidemenu') def _extend_admin_menu(sender, **kwargs): if session.user.is_admin: return SideMenuItem('cephalopod', _("Community Hub"), url_for('cephalopod.index'), section='integration')
# You should have received a copy of the GNU General Public License # along with Indico; if not, see <http://www.gnu.org/licenses/>. from __future__ import unicode_literals from flask import render_template, session from indico.core import signals from indico.core.settings import SettingsProxy from indico.web.flask.templating import template_hook from indico.web.flask.util import url_for from indico.web.menu import SideMenuItem from indico.util.i18n import _ announcement_settings = SettingsProxy('announcement', { 'enabled': False, 'message': '' }) @template_hook('global-announcement') def _inject_announcement_header(**kwargs): if not announcement_settings.get('enabled'): return message = announcement_settings.get('message') if message: return render_template('announcement/display.html', message=message) @signals.menu.items.connect_via('admin-sidemenu') def _sidemenu_items(sender, **kwargs): if session.user.is_admin:
from indico.core import signals from indico.core.logger import Logger from indico.core.settings import SettingsProxy from indico.util.i18n import _ from indico.web.flask.util import url_for from indico.web.menu import SideMenuItem logger = Logger.get('news') news_settings = SettingsProxy( 'news', { # Whether to show the recent news on the home page 'show_recent': True, # The number of recent news to show on the home page 'max_entries': 3, # How old a news may be to be shown on the home page 'max_age': 0, # How long a news is labelled as 'new' 'new_days': 14 }) @signals.menu.items.connect_via('admin-sidemenu') def _sidemenu_items(sender, **kwargs): if session.user.is_admin: yield SideMenuItem('news', _('News'), url_for('news.manage'), section='homepage')
# This file is part of Indico. # Copyright (C) 2002 - 2022 CERN # # Indico is free software; you can redistribute it and/or # modify it under the terms of the MIT License; see the # LICENSE file for more details. from indico.core.settings import SettingsProxy core_settings = SettingsProxy('core', { 'site_title': 'Indico', 'site_organization': '' }) social_settings = SettingsProxy('social', { 'enabled': False, 'facebook_app_id': '' })