Skip to content

Commit ec4065e

Browse files
committed
Merged in [19922] from jennifer@painless-security.com:
Fix scoping of session loop variables in sreq edit view. Improve tests that should have caught this. - Legacy-Id: 19931 Note: SVN reference [19922] has been migrated to Git commit f3eb1ae
1 parent e88aa3c commit ec4065e

2 files changed

Lines changed: 101 additions & 14 deletions

File tree

ietf/secr/sreq/tests.py

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def test_edit(self):
104104
'joint_with_groups': group3.acronym + ' ' + group4.acronym,
105105
'joint_for_session': '2',
106106
'timeranges': ['thursday-afternoon-early', 'thursday-afternoon-late'],
107-
'session_set-TOTAL_FORMS': '2',
107+
'session_set-TOTAL_FORMS': '3', # matches what view actually sends, even with only 2 filled in
108108
'session_set-INITIAL_FORMS': '1',
109109
'session_set-MIN_NUM_FORMS': '1',
110110
'session_set-MAX_NUM_FORMS': '3',
@@ -130,6 +130,16 @@ def test_edit(self):
130130
'session_set-1-attendees': attendees,
131131
'session_set-1-comments': comments,
132132
'session_set-1-DELETE': '',
133+
'session_set-2-id': '',
134+
'session_set-2-name': '',
135+
'session_set-2-short': '',
136+
'session_set-2-purpose': 'regular',
137+
'session_set-2-type': 'regular',
138+
'session_set-2-requested_duration': '',
139+
'session_set-2-on_agenda': 'True',
140+
'session_set-2-attendees': attendees,
141+
'session_set-2-comments': '',
142+
'session_set-2-DELETE': 'on',
133143
'submit': 'Continue'}
134144
r = self.client.post(url, post_data, HTTP_HOST='example.com')
135145
redirect_url = reverse('ietf.secr.sreq.views.view', kwargs={'acronym': 'mars'})
@@ -172,7 +182,7 @@ def test_edit(self):
172182
'comments':'need lights',
173183
'joint_with_groups': group2.acronym,
174184
'joint_for_session': '1',
175-
'session_set-TOTAL_FORMS': '2',
185+
'session_set-TOTAL_FORMS': '3', # matches what view actually sends, even with only 2 filled in
176186
'session_set-INITIAL_FORMS': '2',
177187
'session_set-MIN_NUM_FORMS': '1',
178188
'session_set-MAX_NUM_FORMS': '3',
@@ -198,6 +208,16 @@ def test_edit(self):
198208
'session_set-1-attendees': sessions[1].attendees,
199209
'session_set-1-comments': sessions[1].comments,
200210
'session_set-1-DELETE': '',
211+
'session_set-2-id': '',
212+
'session_set-2-name': '',
213+
'session_set-2-short': '',
214+
'session_set-2-purpose': 'regular',
215+
'session_set-2-type': 'regular',
216+
'session_set-2-requested_duration': '',
217+
'session_set-2-on_agenda': 'True',
218+
'session_set-2-attendees': attendees,
219+
'session_set-2-comments': '',
220+
'session_set-2-DELETE': 'on',
201221
'submit': 'Continue'}
202222
r = self.client.post(url, post_data, HTTP_HOST='example.com')
203223
self.assertRedirects(r, redirect_url)
@@ -222,6 +242,74 @@ def test_edit(self):
222242
r = self.client.get(redirect_url)
223243
self.assertContains(r, 'First session with: {}'.format(group2.acronym))
224244

245+
246+
@override_settings(SECR_VIRTUAL_MEETINGS=tuple()) # ensure not unexpectedly testing a virtual meeting session
247+
def test_edit_constraint_bethere(self):
248+
meeting = MeetingFactory(type_id='ietf', date=datetime.date.today())
249+
mars = RoleFactory(name_id='chair', person__user__username='marschairman', group__acronym='mars').group
250+
session = SessionFactory(meeting=meeting, group=mars, status_id='sched')
251+
Constraint.objects.create(
252+
meeting=meeting,
253+
source=mars,
254+
person=Person.objects.get(user__username='marschairman'),
255+
name_id='bethere',
256+
)
257+
self.assertEqual(session.people_constraints.count(), 1)
258+
url = reverse('ietf.secr.sreq.views.edit', kwargs=dict(acronym='mars'))
259+
self.client.login(username='marschairman', password='marschairman+password')
260+
attendees = '10'
261+
ad = Person.objects.get(user__username='ad')
262+
post_data = {
263+
'num_session': '1',
264+
'attendees': attendees,
265+
'bethere': str(ad.pk),
266+
'constraint_chair_conflict':'',
267+
'comments':'',
268+
'joint_with_groups': '',
269+
'joint_for_session': '',
270+
'delete_conflict': 'on',
271+
'session_set-TOTAL_FORMS': '3', # matches what view actually sends, even with only 2 filled in
272+
'session_set-INITIAL_FORMS': '1',
273+
'session_set-MIN_NUM_FORMS': '1',
274+
'session_set-MAX_NUM_FORMS': '3',
275+
'session_set-0-id':session.pk,
276+
'session_set-0-name': session.name,
277+
'session_set-0-short': session.short,
278+
'session_set-0-purpose': session.purpose_id,
279+
'session_set-0-type': session.type_id,
280+
'session_set-0-requested_duration': '3600',
281+
'session_set-0-on_agenda': session.on_agenda,
282+
'session_set-0-remote_instructions': session.remote_instructions,
283+
'session_set-0-attendees': attendees,
284+
'session_set-0-comments': '',
285+
'session_set-0-DELETE': '',
286+
'session_set-1-id': '',
287+
'session_set-1-name': '',
288+
'session_set-1-short': '',
289+
'session_set-1-purpose':'regular',
290+
'session_set-1-type':'regular',
291+
'session_set-1-requested_duration': '',
292+
'session_set-1-on_agenda': 'True',
293+
'session_set-1-attendees': attendees,
294+
'session_set-1-comments': '',
295+
'session_set-1-DELETE': 'on',
296+
'session_set-2-id': '',
297+
'session_set-2-name': '',
298+
'session_set-2-short': '',
299+
'session_set-2-purpose': 'regular',
300+
'session_set-2-type': 'regular',
301+
'session_set-2-requested_duration': '',
302+
'session_set-2-on_agenda': 'True',
303+
'session_set-2-attendees': attendees,
304+
'session_set-2-comments': '',
305+
'session_set-2-DELETE': 'on',
306+
'submit': 'Save',
307+
}
308+
r = self.client.post(url, post_data, HTTP_HOST='example.com')
309+
redirect_url = reverse('ietf.secr.sreq.views.view', kwargs={'acronym': 'mars'})
310+
self.assertRedirects(r, redirect_url)
311+
self.assertEqual([pc.person for pc in session.people_constraints.all()], [ad])
312+
225313
def test_edit_inactive_conflicts(self):
226314
"""Inactive conflicts should be displayed and removable"""
227315
meeting = MeetingFactory(type_id='ietf', date=datetime.date.today(), group_conflicts=['chair_conflict'])

ietf/secr/sreq/views.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,9 @@ def edit(request, acronym, num=None):
446446
)
447447
login = request.user.person
448448

449-
session = Session()
449+
first_session = Session()
450450
if(len(sessions) > 0):
451-
session = sessions[0]
451+
first_session = sessions[0]
452452

453453
if request.method == 'POST':
454454
button_text = request.POST.get('submit', '')
@@ -461,11 +461,10 @@ def edit(request, acronym, num=None):
461461
changed_session_forms = [sf for sf in form.session_forms.forms_to_keep if sf.has_changed()]
462462
form.session_forms.save()
463463
for n, subform in enumerate(form.session_forms):
464-
session = subform.instance
465-
if session in form.session_forms.new_objects:
464+
if subform.instance in form.session_forms.new_objects:
466465
SchedulingEvent.objects.create(
467-
session=session,
468-
status_id=status_slug_for_new_session(session, n),
466+
session=subform.instance,
467+
status_id=status_slug_for_new_session(subform.instance, n),
469468
by=request.user.person,
470469
)
471470
for sf in changed_session_forms:
@@ -483,10 +482,10 @@ def edit(request, acronym, num=None):
483482
new_joint_for_session_idx = int(form.data.get('joint_for_session', '-1')) - 1
484483
current_joint_for_session_idx = None
485484
current_joint_with_groups = None
486-
for idx, session in enumerate(sessions):
487-
if session.joint_with_groups.count():
485+
for idx, sess in enumerate(sessions):
486+
if sess.joint_with_groups.count():
488487
current_joint_for_session_idx = idx
489-
current_joint_with_groups = session.joint_with_groups.all()
488+
current_joint_with_groups = sess.joint_with_groups.all()
490489

491490
if current_joint_with_groups != new_joint_with_groups or current_joint_for_session_idx != new_joint_for_session_idx:
492491
if current_joint_for_session_idx is not None:
@@ -520,13 +519,13 @@ def edit(request, acronym, num=None):
520519
new_resource_ids = form.cleaned_data['resources']
521520
new_resources = [ ResourceAssociation.objects.get(pk=a)
522521
for a in new_resource_ids]
523-
session.resources = new_resources
522+
first_session.resources = new_resources
524523

525524
if 'bethere' in form.changed_data and set(form.cleaned_data['bethere'])!=set(initial['bethere']):
526-
session.constraints().filter(name='bethere').delete()
525+
first_session.constraints().filter(name='bethere').delete()
527526
bethere_cn = ConstraintName.objects.get(slug='bethere')
528527
for p in form.cleaned_data['bethere']:
529-
Constraint.objects.create(name=bethere_cn, source=group, person=p, meeting=session.meeting)
528+
Constraint.objects.create(name=bethere_cn, source=group, person=p, meeting=first_session.meeting)
530529

531530
if 'session_time_relation' in form.changed_data:
532531
Constraint.objects.filter(meeting=meeting, source=group, name='time_relation').delete()

0 commit comments

Comments
 (0)