Exemplo n.º 1
0
def test_delete_propagate(mocker):
    Setting = mocker.patch('fossir.core.settings.proxy.Setting')
    SettingPrincipal = mocker.patch(
        'fossir.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')
Exemplo n.º 2
0
def test_set_multi_propagate(mocker):
    Setting = mocker.patch('fossir.core.settings.proxy.Setting')
    SettingPrincipal = mocker.patch(
        'fossir.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'}})
Exemplo n.º 3
0
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')
Exemplo n.º 4
0
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'}
Exemplo n.º 5
0
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'
Exemplo n.º 6
0
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
Exemplo n.º 7
0
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)
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
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}
Exemplo n.º 10
0
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
Exemplo n.º 11
0
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
    }
Exemplo n.º 12
0
    {
        'lang': None,
        'timezone': None,
        'force_timezone':
        False,  # always use the user's timezone instead of an event's timezone
        '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',
Exemplo n.º 13
0
from __future__ import unicode_literals

from fossir.core.settings import SettingsProxy

core_settings = SettingsProxy('core', {
    'site_title': 'fossir',
    'site_organization': ''
})

social_settings = SettingsProxy('social', {
    'enabled': False,
    'facebook_app_id': ''
})
Exemplo n.º 14
0
def test_proxy_strict_nodefaults():
    with pytest.raises(ValueError):
        SettingsProxy('test', {})
Exemplo n.º 15
0
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')
Exemplo n.º 16
0
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'
Exemplo n.º 17
0
from fossir.modules.rb.models.locations import Location
from fossir.modules.rb.models.reservations import Reservation
from fossir.modules.rb.models.rooms import Room
from fossir.modules.rb.util import rb_is_admin
from fossir.util.i18n import _
from fossir.web.flask.util import url_for
from fossir.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 fossir.modules.rb.tasks


@signals.menu.items.connect_via('admin-sidemenu')
def _extend_admin_menu(sender, **kwargs):
    if not config.ENABLE_ROOMBOOKING:
Exemplo n.º 18
0
from fossir.core import signals
from fossir.core.logger import Logger
from fossir.core.settings import SettingsProxy
from fossir.util.i18n import _
from fossir.web.flask.util import url_for
from fossir.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')
Exemplo n.º 19
0
def test_get_all_acls():
    proxy = SettingsProxy('foo', {'reg': None}, acls={'acl'})
    assert proxy.get_all() == {'reg': None, 'acl': set()}
Exemplo n.º 20
0

from __future__ import unicode_literals

from flask import render_template, session

from fossir.core import signals
from fossir.core.settings import SettingsProxy
from fossir.util.i18n import _
from fossir.web.flask.templating import template_hook
from fossir.web.flask.util import url_for
from fossir.web.menu import SideMenuItem


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:
Exemplo n.º 21
0
from flask import session

from fossir.core import signals
from fossir.core.logger import Logger
from fossir.core.settings import SettingsProxy
from fossir.util.i18n import _
from fossir.web.flask.util import url_for
from fossir.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')
Exemplo n.º 22
0
           '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."
)

payment_settings = SettingsProxy(
    'payment', {
        'currencies': [{
            'code': 'EUR',
            'name': 'Euro'
        }, {
            'code': 'USD',
            'name': 'US Dollar'
        }],
        'currency':
        'EUR',
        'conditions':
        CONDITIONS
    })

payment_event_settings = EventSettingsProxy('payment', {'conditions': None})


@signals.menu.items.connect_via('admin-sidemenu')
def _extend_admin_menu(sender, **kwargs):
    if session.user.is_admin:
        return SideMenuItem('payment',
                            _("Payment"),
Exemplo n.º 23
0
__all__ = ('settings', )


class APIMode(int, fossirEnum):
    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
Exemplo n.º 24
0
from fossir.web.flask.templating import template_hook
from fossir.web.flask.util import url_for
from fossir.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': ''
    })


@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')
def _inject_footer(**kwargs):
Exemplo n.º 25
0
from fossir.core import signals
from fossir.core.logger import Logger
from fossir.core.roles import ManagementRole, check_roles
from fossir.core.settings import SettingsProxy
from fossir.modules.categories.models.categories import Category
from fossir.modules.categories.models.legacy_mapping import LegacyCategoryMapping
from fossir.util.i18n import _
from fossir.web.flask.util import url_for
from fossir.web.menu import SideMenuItem


logger = Logger.get('categories')

upcoming_events_settings = SettingsProxy('upcoming_events', {
    'entries': [],
    'max_entries': 10
})


@signals.import_tasks.connect
def _import_tasks(sender, **kwargs):
    import fossir.modules.categories.tasks


@signals.users.merged.connect
def _merge_users(target, source, **kwargs):
    from fossir.modules.categories.models.principals import CategoryPrincipal
    CategoryPrincipal.merge_users(target, source, 'category')


@signals.menu.items.connect_via('category-management-sidemenu')