Skip to content

Commit

Permalink
Citadel: Implement warning threshold
Browse files Browse the repository at this point in the history
Also add error message
  • Loading branch information
GovernmentPlates committed Feb 12, 2024
1 parent a00e1ba commit dc3eb01
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions citadel/indico_citadel/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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):
Expand Down Expand Up @@ -51,6 +52,12 @@ class CitadelSettingsForm(IndicoForm):
'is used, the internal Indico search interface will be used. This may '
'be useful when you are still running a larger initial export and do '
'not want people to get incomplete search results during that time.'))
large_category_warning_threshold = IntegerField(_('Large Category Warning Threshold'),
[NumberRange(min=0)],
description=_('This shows a warning message to admins when '
'the number of events in a category surpasses '
'the threshold set here. You can set the '
'threshold to 0 to suppress this warning.'))


class CitadelPlugin(LiveSyncPluginBase):
Expand All @@ -75,13 +82,15 @@ class CitadelPlugin(LiveSyncPluginBase):
'num_threads_files': 5,
'num_threads_files_initial': 25,
'disable_search': False,
'large_category_warning_threshold': 0,
}
backend_classes = {'citadel': LiveSyncCitadelBackend}

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)

def get_search_providers(self, sender, **kwargs):
from indico_citadel.search import CitadelProvider
Expand Down
9 changes: 9 additions & 0 deletions citadel/indico_citadel/templates/event_category_warning.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% 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 -%}
<b>The '{{ category_title }}' category contains over {{ max_events_threshold }} events - this may cause performance issues.</b>
<br/>
Please consider using groups instead of individual users to avoid having to re-send large amounts of changes to users individually.
{%- endtrans %}
{% endcall %}
10 changes: 10 additions & 0 deletions citadel/indico_citadel/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

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
Expand Down Expand Up @@ -215,3 +216,12 @@ 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):

Check failure on line 220 in citadel/indico_citadel/util.py

View workflow job for this annotation

GitHub Actions / lint

expected 2 blank lines, found 1
from indico_citadel.plugin import CitadelPlugin

Check failure on line 221 in citadel/indico_citadel/util.py

View workflow job for this annotation

GitHub Actions / lint

over-indented

Check failure on line 221 in citadel/indico_citadel/util.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (E117)

citadel/indico_citadel/util.py:221:1: E117 Over-indented

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)

0 comments on commit dc3eb01

Please sign in to comment.