manager: add role info to select options for notifications (#46455)
This commit is contained in:
parent
f380c419db
commit
36f35eefcd
|
@ -1645,8 +1645,12 @@ class AgendaNotificationsSettings(models.Model):
|
|||
def get_email_field_names(cls):
|
||||
return [field.name for field in cls._meta.get_fields() if isinstance(field, ArrayField)]
|
||||
|
||||
@staticmethod
|
||||
def get_role_field_names():
|
||||
return ['almost_full_event', 'full_event', 'cancelled_event']
|
||||
|
||||
def get_notification_types(self):
|
||||
for field in ['almost_full_event', 'full_event', 'cancelled_event']:
|
||||
for field in self.get_role_field_names():
|
||||
notification_type = NotificationType(
|
||||
name=field, related_field=field.replace('_event', ''), settings=self
|
||||
)
|
||||
|
|
|
@ -519,6 +519,16 @@ class AgendaNotificationsForm(forms.ModelForm):
|
|||
'agenda': forms.HiddenInput(),
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def update_choices(choices, settings):
|
||||
new_choices = []
|
||||
for choice in choices:
|
||||
if choice[0] in (settings.EDIT_ROLE, settings.VIEW_ROLE):
|
||||
role = settings.get_role_from_choice(choice[0]) or _('undefined')
|
||||
choice = (choice[0], '%s (%s)' % (choice[1], role))
|
||||
new_choices.append(choice)
|
||||
return new_choices
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
@ -526,3 +536,8 @@ class AgendaNotificationsForm(forms.ModelForm):
|
|||
self.fields[email_field].widget.attrs['size'] = 80
|
||||
self.fields[email_field].label = ''
|
||||
self.fields[email_field].help_text = _('Enter a comma separated list of email addresses.')
|
||||
|
||||
settings = kwargs['instance']
|
||||
for role_field in AgendaNotificationsSettings.get_role_field_names():
|
||||
field = self.fields[role_field]
|
||||
field.choices = self.update_choices(field.choices, settings)
|
||||
|
|
|
@ -3919,10 +3919,17 @@ def test_agenda_notifications(app, admin_user, managers_group):
|
|||
resp = resp.form.submit().follow()
|
||||
assert 'Notifications are disabled' in resp.text
|
||||
|
||||
agenda.view_role = managers_group
|
||||
agenda.save()
|
||||
|
||||
resp = resp.click('Configure')
|
||||
resp.form['cancelled_event_emails'] = 'hop@entrouvert.com, top@entrouvert.com'
|
||||
resp.form['almost_full_event'] = 'edit-role'
|
||||
option = resp.form['almost_full_event'].selectedIndex
|
||||
assert resp.form['almost_full_event'].options[option][2] == 'Edit Role (undefined)'
|
||||
resp.form['full_event'] = 'view-role'
|
||||
option = resp.form['full_event'].selectedIndex
|
||||
assert resp.form['full_event'].options[option][2] == 'View Role (Managers)'
|
||||
resp = resp.form.submit().follow()
|
||||
|
||||
settings = agenda.notifications_settings
|
||||
|
@ -3933,15 +3940,13 @@ def test_agenda_notifications(app, admin_user, managers_group):
|
|||
|
||||
assert 'Cancelled event: hop@entrouvert.com, top@entrouvert.com will be notified' in resp.text
|
||||
assert 'Almost full event (90%): Edit Role (undefined) will be notified' in resp.text
|
||||
assert 'Full event: View Role (undefined) will be notified' in resp.text
|
||||
assert 'Full event: View Role (Managers) will be notified' in resp.text
|
||||
|
||||
agenda.view_role = managers_group
|
||||
agenda.edit_role = Group.objects.create(name='hop')
|
||||
agenda.save()
|
||||
|
||||
resp = app.get('/manage/agendas/%s/settings' % agenda.id)
|
||||
assert 'Almost full event (90%): Edit Role (hop) will be notified' in resp.text
|
||||
assert 'Full event: View Role (Managers) will be notified' in resp.text
|
||||
|
||||
|
||||
def test_agenda_notifications_no_old_events(app, admin_user, mailoutbox):
|
||||
|
|
Loading…
Reference in New Issue