Exemple #1
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})
Exemple #2
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()
Exemple #3
0
    def iter_subentries(self):
        """Iterates through all children

        The only field of the yielded items that should be used are
        `type`, `object` and `object_ref`.
        """
        if self.type not in {EntryType.category, EntryType.event, EntryType.contribution}:
            return
        if self.type == EntryType.category:
            for event in self.object.iterAllConferences():
                yield LiveSyncQueueEntry(change=self.change, **obj_ref(event))
        elif self.type == EntryType.event:
            for contrib in self.object.contributions:
                yield LiveSyncQueueEntry(change=self.change, **obj_ref(contrib))
        elif self.type == EntryType.contribution:
            for subcontrib in self.object.subcontributions:
                yield LiveSyncQueueEntry(change=self.change, **obj_ref(subcontrib))
Exemple #4
0
def _register_change(obj, action):
    if not isinstance(obj, Category):
        event = obj.event
        if event is None or event.is_deleted:
            # When deleting an event we get data change signals afterwards. We can simple ignore them.
            # Also, ACL changes during user merges might involve deleted objects which we also don't care about
            return
    _init_livesync_g()
    g.livesync_changes[obj_ref(obj)].add(action)
Exemple #5
0
def _register_change(obj, action):
    if not isinstance(obj, Category):
        event = obj.event
        if event is None or event.is_deleted:
            # When deleting an event we get data change signals afterwards. We can simple ignore them.
            # Also, ACL changes during user merges might involve deleted objects which we also don't care about
            return
    _init_livesync_g()
    g.livesync_changes[obj_ref(obj)].add(action)
Exemple #6
0
def _register_change(obj, action):
    if not isinstance(obj, Category):
        event = obj.event_new
        if event is None or event.is_deleted or event.as_legacy is None or event.as_legacy.getOwner() is None:
            # When deleting an event we get data change signals afterwards. We can simple ignore them.
            # When moving an event it's even worse, we get a data change notification in the middle of the move while
            # the event has no category...
            # Also, ACL changes during user merges might involve deleted objects which we also don't care about
            return
    _init_livesync_g()
    g.livesync_changes[obj_ref(obj)].add(action)
Exemple #7
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})
Exemple #8
0
def _register_deletion(obj):
    _init_livesync_g()
    g.livesync_changes[obj_ref(obj)].add(ChangeType.deleted)
Exemple #9
0
 def objects_to_xml(cls, objs, change_type=SimpleChange.created):
     mg = MARCXMLGenerator()
     for obj in objs:
         mg.safe_add_object(obj_ref(obj),
                            bool(change_type & SimpleChange.deleted))
     return mg.get_xml()
Exemple #10
0
def _register_deletion(obj):
    _init_livesync_g()
    g.livesync_changes[obj_ref(obj)].add(ChangeType.deleted)
Exemple #11
0
 def objects_to_xml(cls, objs, change_type=SimpleChange.created):
     mg = MARCXMLGenerator()
     for obj in objs:
         mg.safe_add_object(obj_ref(obj), bool(change_type & SimpleChange.deleted))
     return mg.get_xml()