From cf8cd5eb41d86f43677fd533fa1c6655e7e654b5 Mon Sep 17 00:00:00 2001 From: Javier Ferrer Date: Fri, 24 Sep 2021 15:44:54 +0200 Subject: [PATCH] LiveSync: Correctly handle unlisted events (#156) --- livesync/indico_livesync/handler.py | 18 +++++++++++------- livesync/indico_livesync/models/queue.py | 2 ++ livesync/setup.cfg | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/livesync/indico_livesync/handler.py b/livesync/indico_livesync/handler.py index ec01e67..7892b07 100644 --- a/livesync/indico_livesync/handler.py +++ b/livesync/indico_livesync/handler.py @@ -91,17 +91,21 @@ def _is_category_excluded(category): def _moved(obj, old_parent, **kwargs): - _register_change(obj, ChangeType.moved) + # if an unlisted event is moved, it triggers a creation instead + if isinstance(obj, Event) and old_parent is None: + _register_change(obj, ChangeType.created) + else: + _register_change(obj, ChangeType.moved) - new_category = obj if isinstance(obj, Category) else obj.category - old_excluded = _is_category_excluded(old_parent) - new_excluded = _is_category_excluded(new_category) - if old_excluded != new_excluded: - _register_change(obj, ChangeType.unpublished if new_excluded else ChangeType.published) + new_category = obj if isinstance(obj, Category) else obj.category + old_excluded = _is_category_excluded(old_parent) if old_parent else False + new_excluded = _is_category_excluded(new_category) + if old_excluded != new_excluded: + _register_change(obj, ChangeType.unpublished if new_excluded else ChangeType.published) if obj.is_inheriting: # If protection is inherited, check whether it changed - category_protection = old_parent.effective_protection_mode + category_protection = old_parent.effective_protection_mode if old_parent else None new_category_protection = obj.protection_parent.effective_protection_mode # Protection of new parent is different if category_protection != new_category_protection: diff --git a/livesync/indico_livesync/models/queue.py b/livesync/indico_livesync/models/queue.py index 7ebbd46..8dfc40d 100644 --- a/livesync/indico_livesync/models/queue.py +++ b/livesync/indico_livesync/models/queue.py @@ -286,6 +286,8 @@ class LiveSyncQueueEntry(db.Model): return else: event = obj.folder.event if isinstance(obj, Attachment) else obj.event + if event.is_unlisted: + return if event.category not in g.setdefault('livesync_excluded_categories_checked', {}): g.livesync_excluded_categories_checked[event.category] = \ excluded_categories & set(event.category_chain) diff --git a/livesync/setup.cfg b/livesync/setup.cfg index 8001de9..08e7246 100644 --- a/livesync/setup.cfg +++ b/livesync/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = indico-plugin-livesync -version = 3.0.1 +version = 3.1-dev description = Framework for pushing Indico event data to external services long_description = file: README.md long_description_content_type = text/markdown; charset=UTF-8; variant=GFM @@ -20,7 +20,7 @@ zip_safe = false include_package_data = true python_requires = ~=3.9.0 install_requires = - indico>=3.0 + indico>=3.1.dev0 [options.entry_points] indico.plugins =