From 4300296d4cb3564347aa67617bba6d83e5c950f8 Mon Sep 17 00:00:00 2001 From: Dominic Hollis Date: Mon, 12 Feb 2024 19:56:08 +0100 Subject: [PATCH] Citadel: Improve error message and apply changes from review --- citadel/indico_citadel/plugin.py | 11 +++++++++-- .../templates/event_category_warning.html | 7 ++++--- citadel/indico_citadel/util.py | 11 ----------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/citadel/indico_citadel/plugin.py b/citadel/indico_citadel/plugin.py index 0246ca82..ac7d6aaa 100644 --- a/citadel/indico_citadel/plugin.py +++ b/citadel/indico_citadel/plugin.py @@ -5,6 +5,7 @@ # them and/or modify them under the terms of the MIT License; # see the LICENSE file for more details. +from flask_pluginengine.plugin import render_plugin_template from wtforms.fields import BooleanField, IntegerField, URLField from wtforms.validators import URL, DataRequired, NumberRange @@ -18,7 +19,6 @@ from indico_citadel.backend import LiveSyncCitadelBackend from indico_citadel.cli import cli from indico_livesync import LiveSyncPluginBase -from indico_citadel.util import check_event_categories class CitadelSettingsForm(IndicoForm): @@ -90,7 +90,7 @@ def init(self): super().init() self.connect(signals.core.get_search_providers, self.get_search_providers) self.connect(signals.plugin.cli, self._extend_indico_cli) - self.template_hook('category-protection-page', check_event_categories) + self.template_hook('category-protection-page', self.check_event_categories) def get_search_providers(self, sender, **kwargs): from indico_citadel.search import CitadelProvider @@ -98,3 +98,10 @@ def get_search_providers(self, sender, **kwargs): def _extend_indico_cli(self, sender, **kwargs): return cli + + def check_event_categories(self, category): + threshold = self.settings.get('large_category_warning_threshold') + num_events = category.deep_events_count + + if threshold and num_events > threshold: + return render_plugin_template('event_category_warning.html') diff --git a/citadel/indico_citadel/templates/event_category_warning.html b/citadel/indico_citadel/templates/event_category_warning.html index b70e22a5..95bdc711 100644 --- a/citadel/indico_citadel/templates/event_category_warning.html +++ b/citadel/indico_citadel/templates/event_category_warning.html @@ -1,9 +1,10 @@ {% from 'message_box.html' import message_box %} {% call message_box('warning', large_icon=true, fixed_width=true) %} - {% trans category_title=category.title, max_events_threshold=threshold -%} - The '{{ category_title }}' category contains over {{ max_events_threshold }} events - this may cause performance issues. + {% trans -%} + This category contains a large number of events.
- Please consider using groups instead of individual users to avoid having to re-send large amounts of changes to users individually. + Please consider using groups instead of individual users when granting access or management privileges + since any change to the access control list requires re-synchronizing all events with Indico's search engine. {%- endtrans %} {% endcall %} diff --git a/citadel/indico_citadel/util.py b/citadel/indico_citadel/util.py index fad9e114..d14d97d6 100644 --- a/citadel/indico_citadel/util.py +++ b/citadel/indico_citadel/util.py @@ -13,7 +13,6 @@ from flask import current_app from flask.globals import _cv_app -from flask_pluginengine.plugin import render_plugin_template from indico.core.db import db from indico.core.db.sqlalchemy.principals import PrincipalMixin, PrincipalPermissionsMixin, PrincipalType @@ -216,13 +215,3 @@ def get_user_access(user, admin_override_enabled=False): for x in user.iter_all_multipass_groups()] access += _include_capitalized_groups(multipass_groups) return access - - -def check_event_categories(category): - from indico_citadel.plugin import CitadelPlugin - - threshold = CitadelPlugin.settings.get('large_category_warning_threshold') - num_events = category.deep_events_count - - if threshold and num_events > threshold: - return render_plugin_template('event_category_warning.html', category=category, threshold=threshold)