Skip to content

Commit

Permalink
Improve regform action logging
Browse files Browse the repository at this point in the history
- Add regform id metadata
- Log regform deletions
  • Loading branch information
ThiefMaster committed Nov 10, 2022
1 parent cb29b2a commit 87f7dbb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ def _process(self):
db.session.add(regform)
db.session.flush()
signals.event.registration_form_created.send(regform)
self.event.log(EventLogRealm.management, LogKind.positive, 'Registration',
f'Registration form "{regform.title}" has been created', session.user,
data=_get_regform_creation_log_data(regform))
regform.log(EventLogRealm.management, LogKind.positive, 'Registration',
f'Registration form "{regform.title}" has been created', session.user,
data=_get_regform_creation_log_data(regform))
return redirect(url_for('event_registration.manage_regform', regform))

if not regform or not registration_enabled:
Expand Down Expand Up @@ -201,9 +201,9 @@ def _process(self):
db.session.flush()
signals.event.registration_form_created.send(regform)
flash(_('Registration form has been successfully created'), 'success')
self.event.log(EventLogRealm.management, LogKind.positive, 'Registration',
f'Registration form "{regform.title}" has been created', session.user,
data=_get_regform_creation_log_data(regform))
regform.log(EventLogRealm.management, LogKind.positive, 'Registration',
f'Registration form "{regform.title}" has been created', session.user,
data=_get_regform_creation_log_data(regform))
return redirect(url_for('.manage_regform', regform))
return WPManageRegistration.render_template('management/regform_create.html', self.event,
form=form, regform=None)
Expand Down Expand Up @@ -246,6 +246,8 @@ def _process(self):
signals.event.registration_form_deleted.send(self.regform)
flash(_('Registration form deleted'), 'success')
logger.info('Registration form %s deleted by %s', self.regform, session.user)
self.regform.log(EventLogRealm.management, LogKind.negative, 'Registration',
f'Registration form "{self.regform.title}" was deleted', session.user)
return redirect(url_for('.manage_regform_list', self.event))


Expand All @@ -266,7 +268,7 @@ def _process(self):
log_text = f'Registration form "{self.regform.title}" was opened'
else:
log_text = f'Registration form "{self.regform.title}" was reopened'
self.event.log(EventLogRealm.event, LogKind.change, 'Registration', log_text, session.user)
self.regform.log(EventLogRealm.event, LogKind.change, 'Registration', log_text, session.user)
return redirect(url_for('.manage_regform', self.regform))


Expand All @@ -278,7 +280,7 @@ def _process(self):
flash(_('Registrations for {} are now closed').format(self.regform.title), 'success')
logger.info('Registrations for %s closed by %s', self.regform, session.user)
log_text = f'Registration form "{self.regform.title}" was closed'
self.event.log(EventLogRealm.event, LogKind.change, 'Registration', log_text, session.user)
self.regform.log(EventLogRealm.event, LogKind.change, 'Registration', log_text, session.user)
return redirect(url_for('.manage_regform', self.regform))


Expand All @@ -293,6 +295,14 @@ def _process(self):
self.regform.modification_end_dt = form.modification_end_dt.data
flash(_('Registrations for {} have been scheduled').format(self.regform.title), 'success')
logger.info('Registrations for %s scheduled by %s', self.regform, session.user)
log_data = {
'Start': self.regform.start_dt.isoformat() if self.regform.start_dt else None,
'End': self.regform.end_dt.isoformat() if self.regform.end_dt else None,
'Modification End': (self.regform.modification_end_dt.isoformat()
if self.regform.modification_end_dt else None),
}
self.regform.log(EventLogRealm.management, LogKind.change, 'Registration',
f'Registration form "{self.regform.title}" scheduled', session.user, data=log_data)
return jsonify_data(flash=False)
return jsonify_form(form, submit=_('Schedule'))

Expand Down
4 changes: 4 additions & 0 deletions indico/modules/events/registration/models/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ def get_personal_data_field_id(self, personal_data_type):
field.personal_data_type == personal_data_type):
return field.id

def log(self, *args, **kwargs):
"""Log with prefilled metadata for the regform."""
return self.event.log(*args, meta={'registration_form_id': self.id}, **kwargs)


@listens_for(orm.mapper, 'after_configured', once=True)
def _mappers_configured():
Expand Down

0 comments on commit 87f7dbb

Please sign in to comment.