Пример #1
0
def _apply_changes(sender, **kwargs):
    excluded_categories = get_excluded_categories()

    if not hasattr(g, 'livesync_changes'):
        return
    for ref, changes in g.livesync_changes.iteritems():
        LiveSyncQueueEntry.create(changes, ref, excluded_categories=excluded_categories)
Пример #2
0
def _apply_changes(sender, **kwargs):
    if not hasattr(g, 'livesync_changes'):
        return
    for ref, changes in g.livesync_changes.iteritems():
        if is_ref_excluded(ref):
            continue
        LiveSyncQueueEntry.create(changes, ref)
Пример #3
0
def test_excluded_categories(mocker, monkeypatch, db, create_category):
    """Test if category exclusions work."""
    plugin = mocker.patch('indico_livesync.plugin.LiveSyncPlugin')
    plugin.settings.get.return_value = [{'id': 2}, {'id': 3}]

    categories = {}
    with db.session.no_autoflush:
        for cat_id in xrange(6):
            category = (create_category(
                cat_id,
                title=str(cat_id),
                protection_mode=0,
                parent=categories[CATEGORY_PARENTS[cat_id]])
                        if cat_id else Category.get_root())
            categories[cat_id] = category
            db.session.add(category)
            db.session.flush()

    db.session.flush()

    for cat in categories.viewvalues():
        db = mocker.patch('indico_livesync.models.queue.db')
        LiveSyncQueueEntry.create(
            {ChangeType.created},
            obj_ref(cat),
            excluded_categories=get_excluded_categories())
        assert db.session.add.called == (cat.id not in {2, 3, 4, 5})
Пример #4
0
def enqueue(type, change, ids):
    """Adds the given objects to the LiveSync queues.

    This is intended to be used if a change was not recorded by LiveSync
    for some reason and you want to manually force an update. Note that
    enqueuing a deletion for something that is not deleted may be
    dangerous and can cause agent runs to fail.

    By default this util uses the `protection_changed` change type since
    that way it cascades to all child objects when used on anything except
    categories.
    """

    model = {
        EntryType.category: db.m.Category,
        EntryType.event: db.m.Event,
        EntryType.contribution: db.m.Contribution,
        EntryType.subcontribution: db.m.SubContribution,
        EntryType.session: db.m.Session,
        EntryType.note: db.m.EventNote,
        EntryType.attachment: db.m.Attachment,
    }[type]

    objs = model.query.filter(model.id.in_(ids)).all()
    excluded_categories = get_excluded_categories()
    for obj in objs:
        click.echo(f'Enqueuing {obj}')
        LiveSyncQueueEntry.create({change}, obj_ref(obj), excluded_categories=excluded_categories)
    db.session.commit()
Пример #5
0
def test_excluded_categories(mocker, monkeypatch, db, create_category):
    """Test if category exclusions work."""
    plugin = mocker.patch('indico_livesync.plugin.LiveSyncPlugin')
    plugin.settings.get.return_value = [{'id': 2}, {'id': 3}]

    categories = {}
    with db.session.no_autoflush:
        for cat_id in xrange(6):
            category = (create_category(cat_id, title=str(cat_id), protection_mode=0,
                                        parent=categories[CATEGORY_PARENTS[cat_id]])
                        if cat_id else Category.get_root())
            categories[cat_id] = category
            db.session.add(category)
            db.session.flush()

    db.session.flush()

    for cat in categories.viewvalues():
        db = mocker.patch('indico_livesync.models.queue.db')
        LiveSyncQueueEntry.create({ChangeType.created}, obj_ref(cat), excluded_categories=get_excluded_categories())
        assert db.session.add.called == (cat.id not in {2, 3, 4, 5})
Пример #6
0
def _apply_changes(sender, **kwargs):
    if not hasattr(g, 'livesync_changes'):
        return
    excluded_categories = get_excluded_categories()
    for ref, changes in g.livesync_changes.iteritems():
        LiveSyncQueueEntry.create(changes, ref, excluded_categories=excluded_categories)