Skip to content

Commit

Permalink
Log regform settings changes (indico#6544)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtran99 committed Sep 23, 2024
1 parent 860bb35 commit 93c9a25
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Improvements
^^^^^^^^^^^^

- Nothing so far :(
- Allow specifying "prev" and "next" as the date param on the category overview
page to show the previous or next period relative to the current date (:pr:`6537`)
- Add caching and rate-limiting (configurable via :data:`LATEX_RATE_LIMIT`, and only applied
to unauthenticated users) for endpoints that trigger LaTeX PDF generation (:pr:`6526`)
- Log changes to registration form settings in the event log (:pr:`6544`, thanks :user:`vtran99`)

Bugfixes
^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from indico.modules.events.registration.models.forms import RegistrationForm
from indico.modules.events.registration.models.items import PersonalDataType
from indico.modules.events.registration.models.registrations import PublishRegistrationsMode
from indico.modules.events.registration.operations import update_registration_form_settings
from indico.modules.events.registration.stats import AccommodationStats, OverviewStats
from indico.modules.events.registration.util import (close_registration, create_personal_data_fields,
get_flat_section_setup_data)
Expand Down Expand Up @@ -244,9 +245,7 @@ def _get_form_defaults(self):
def _process(self):
form = RegistrationFormEditForm(obj=self._get_form_defaults(), event=self.event, regform=self.regform)
if form.validate_on_submit():
form.populate_obj(self.regform)
db.session.flush()
signals.event.registration_form_edited.send(self.regform)
update_registration_form_settings(self.regform, form.data, skip={'limit_registrations'})
flash(_('Registration form has been successfully modified'), 'success')
return redirect(url_for('.manage_regform', self.regform))
return WPManageRegistration.render_template('management/regform_edit.html', self.event, form=form,
Expand Down
53 changes: 53 additions & 0 deletions indico/modules/events/registration/operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This file is part of Indico.
# Copyright (C) 2002 - 2024 CERN
#
# Indico is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see the
# LICENSE file for more details.

from flask import session

from indico.core import signals
from indico.core.db import db
from indico.modules.events import logger
from indico.modules.logs import EventLogRealm, LogKind
from indico.modules.logs.util import make_diff_log
from indico.util.signals import make_interceptable


def _log_registration_form_update(regform, changes, extra_log_fields):
log_fields = {
'title': {'title': 'Title', 'type': 'string'},
'introduction': 'Introduction',
'contact_info': {'title': 'Contact info', 'type': 'string'},
'moderation_enabled': 'Moderated',
'private': 'Private',
'require_login': 'Only logged-in users',
'require_user': 'Registrant must have account',
'require_captcha': 'Require CAPTCHA',
'registration_limit': 'Limit',
'modification_mode': 'Modification allowed',
'publish_registration_count': 'Publish registration count',
'publish_checkin_enabled': 'Publish check-in status',
'notification_sender_address': {'title': 'Notification sender address', 'type': 'string'},
'message_pending': 'Message for pending',
'message_unpaid': 'Message for unpaid',
'message_complete': 'Message for complete',
'attach_ical': 'Attach iCalendar file',
'manager_notifications_enabled': 'Notify managers',
'manager_notification_recipients': 'Notification recipients',
**(extra_log_fields or {})
}
regform.log(EventLogRealm.management, LogKind.change, 'Registration',
f'Registration form "{regform.title}" has been updated', session.user,
data={'Changes': make_diff_log(changes, log_fields)})


@make_interceptable
def update_registration_form_settings(regform, data, *, skip=(), _extra_log_fields=None):
changes = regform.populate_from_dict(data, skip=skip)
db.session.flush()
signals.event.registration_form_edited.send(regform)
logger.info('Registration form %r updated with %r by %r', regform, data, session.user)
if changes:
_log_registration_form_update(regform, changes, _extra_log_fields)
2 changes: 1 addition & 1 deletion indico/modules/logs/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def make_diff_log(changes, fields):
for x in change]
elif all(isinstance(x, bool) for x in change):
type_ = 'bool'
elif all(isinstance(x, (int, float)) for x in change):
elif all(isinstance(x, (int, float)) for x in not_none_change):
type_ = 'number'
elif all(isinstance(x, (list, tuple)) for x in change):
type_ = 'list'
Expand Down

0 comments on commit 93c9a25

Please sign in to comment.