Skip to content

Commit 7cbc702

Browse files
feat: Allow secretariat to request/edit sessions without sending email (ietf-tools#5110)
1 parent 6b8d57e commit 7cbc702

4 files changed

Lines changed: 52 additions & 31 deletions

File tree

ietf/secr/sreq/forms.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,18 @@ class SessionForm(forms.Form):
8080
timeranges = NameModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple, required=False,
8181
queryset=TimerangeName.objects.all())
8282
adjacent_with_wg = forms.ChoiceField(required=False)
83+
send_notifications = forms.BooleanField(label="Send notification emails?", required=False, initial=False)
8384

8485
def __init__(self, group, meeting, data=None, *args, **kwargs):
85-
if 'hidden' in kwargs:
86-
self.hidden = kwargs.pop('hidden')
87-
else:
88-
self.hidden = False
86+
self.hidden = kwargs.pop('hidden', False)
87+
self.notifications_optional = kwargs.pop('notifications_optional', False)
8988

9089
self.group = group
9190
formset_class = sessiondetailsformset_factory(max_num=3 if group.features.acts_like_wg else 50)
9291
self.session_forms = formset_class(group=self.group, meeting=meeting, data=data)
9392
super(SessionForm, self).__init__(data=data, *args, **kwargs)
93+
if not self.notifications_optional:
94+
self.fields['send_notifications'].widget = forms.HiddenInput()
9495

9596
# Allow additional sessions for non-wg-like groups
9697
if not self.group.features.acts_like_wg:
@@ -234,6 +235,9 @@ def clean_joint_with_groups(self):
234235
def clean_comments(self):
235236
return clean_text_field(self.cleaned_data['comments'])
236237

238+
def clean_send_notifications(self):
239+
return True if not self.notifications_optional else self.cleaned_data['send_notifications']
240+
237241
def is_valid(self):
238242
return super().is_valid() and self.session_forms.is_valid()
239243

ietf/secr/sreq/views.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def confirm(request, acronym):
288288
if len(group.features.session_purposes) == 0:
289289
raise Http404(f'Cannot request sessions for group "{acronym}"')
290290
meeting = get_meeting(days=14)
291-
form = SessionForm(group, meeting, request.POST, hidden=True)
291+
form = SessionForm(group, meeting, request.POST, hidden=True, notifications_optional=has_role(request.user, "Secretariat"))
292292
form.is_valid()
293293

294294
login = request.user.person
@@ -366,15 +366,16 @@ def confirm(request, acronym):
366366
add_event_info_to_session_qs(Session.objects.filter(group=group, meeting=meeting)).filter(current_status='notmeet').delete()
367367

368368
# send notification
369-
session_data['outbound_conflicts'] = [f"{d['name']}: {d['groups']}" for d in outbound_conflicts]
370-
send_notification(
371-
group,
372-
meeting,
373-
login,
374-
session_data,
375-
[sf.cleaned_data for sf in form.session_forms[:num_sessions]],
376-
'new',
377-
)
369+
if form.cleaned_data.get("send_notifications"):
370+
session_data['outbound_conflicts'] = [f"{d['name']}: {d['groups']}" for d in outbound_conflicts]
371+
send_notification(
372+
group,
373+
meeting,
374+
login,
375+
session_data,
376+
[sf.cleaned_data for sf in form.session_forms[:num_sessions]],
377+
'new',
378+
)
378379

379380
status_text = 'IETF Agenda to be scheduled'
380381
messages.success(request, 'Your request has been sent to %s' % status_text)
@@ -385,7 +386,6 @@ def confirm(request, acronym):
385386
outbound=outbound_conflicts, # each is a dict with name and groups as keys
386387
inbound=inbound_session_conflicts_as_string(group, meeting),
387388
)
388-
389389
return render(request, 'sreq/confirm.html', {
390390
'form': form,
391391
'session': session_data,
@@ -449,7 +449,7 @@ def edit(request, acronym, num=None):
449449
if button_text == 'Cancel':
450450
return redirect('ietf.secr.sreq.views.view', acronym=acronym)
451451

452-
form = SessionForm(group, meeting, request.POST, initial=initial)
452+
form = SessionForm(group, meeting, request.POST, initial=initial, notifications_optional=has_role(request.user, "Secretariat"))
453453
if form.is_valid():
454454
if form.has_changed():
455455
changed_session_forms = [sf for sf in form.session_forms.forms_to_keep if sf.has_changed()]
@@ -540,17 +540,18 @@ def edit(request, acronym, num=None):
540540
#add_session_activity(group,'Session Request was updated',meeting,user)
541541

542542
# send notification
543-
outbound_conflicts = get_outbound_conflicts(form)
544-
session_data = form.cleaned_data.copy() # do not add things to the original cleaned_data
545-
session_data['outbound_conflicts'] = [f"{d['name']}: {d['groups']}" for d in outbound_conflicts]
546-
send_notification(
547-
group,
548-
meeting,
549-
login,
550-
session_data,
551-
[sf.cleaned_data for sf in form.session_forms.forms_to_keep],
552-
'update',
553-
)
543+
if form.cleaned_data.get("send_notifications"):
544+
outbound_conflicts = get_outbound_conflicts(form)
545+
session_data = form.cleaned_data.copy() # do not add things to the original cleaned_data
546+
session_data['outbound_conflicts'] = [f"{d['name']}: {d['groups']}" for d in outbound_conflicts]
547+
send_notification(
548+
group,
549+
meeting,
550+
login,
551+
session_data,
552+
[sf.cleaned_data for sf in form.session_forms.forms_to_keep],
553+
'update',
554+
)
554555

555556
messages.success(request, 'Session Request updated')
556557
return redirect('ietf.secr.sreq.views.view', acronym=acronym)
@@ -565,7 +566,7 @@ def edit(request, acronym, num=None):
565566

566567
if not sessions:
567568
return redirect('ietf.secr.sreq.views.new', acronym=acronym)
568-
form = SessionForm(group, meeting, initial=initial)
569+
form = SessionForm(group, meeting, initial=initial, notifications_optional=has_role(request.user, "Secretariat"))
569570

570571
return render(request, 'sreq/edit.html', {
571572
'is_locked': is_locked and not has_role(request.user,'Secretariat'),
@@ -665,7 +666,7 @@ def new(request, acronym):
665666
if button_text == 'Cancel':
666667
return redirect('ietf.secr.sreq.views.main')
667668

668-
form = SessionForm(group, meeting, request.POST)
669+
form = SessionForm(group, meeting, request.POST, notifications_optional=has_role(request.user, "Secretariat"))
669670
if form.is_valid():
670671
return confirm(request, acronym)
671672

@@ -689,12 +690,12 @@ def new(request, acronym):
689690
add_essential_people(group,initial)
690691
if 'resources' in initial:
691692
initial['resources'] = [x.pk for x in initial['resources']]
692-
form = SessionForm(group, meeting, initial=initial)
693+
form = SessionForm(group, meeting, initial=initial, notifications_optional=has_role(request.user, "Secretariat"))
693694

694695
else:
695696
initial={}
696697
add_essential_people(group,initial)
697-
form = SessionForm(group, meeting, initial=initial)
698+
form = SessionForm(group, meeting, initial=initial, notifications_optional=has_role(request.user, "Secretariat"))
698699

699700
return render(request, 'sreq/new.html', {
700701
'meeting': meeting,

ietf/secr/templates/includes/sessions_request_form.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@
121121
<td>Special Requests:<br>&nbsp;<br>i.e. restrictions on meeting times / days, etc.<br> (limit 200 characters)</td>
122122
<td>{{ form.comments.errors }}{{ form.comments }}</td>
123123
</tr>
124+
{% if form.notifications_optional %}
125+
<tr class="bg1">
126+
<td>{{ form.send_notifications.label }}</td>
127+
<td>{{ form.send_notifications.errors }}{{ form.send_notifications }}</td>
128+
</tr>
129+
{% endif %}
124130
</tbody>
125131
</table>
126132

ietf/secr/templates/includes/sessions_request_view.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,15 @@
5959
</tr>
6060
{% endif %}
6161
<tr class="row1"><td>Special Requests:</td><td>{{ session.comments }}</td></tr>
62+
{% if form and form.notifications_optional %}
63+
<tr class="row2">
64+
<td>
65+
{{ form.send_notifications.label}}
66+
</td>
67+
<td>
68+
{% if form.cleaned_data.send_notifications %}Yes{% else %}No{% endif %}
69+
</td>
70+
</tr>
71+
{% endif %}
6272
</tbody>
6373
</table>

0 commit comments

Comments
 (0)