Skip to content

Commit f9d6145

Browse files
committed
fixes Ticket ietf-tools#1443. Do not allow editing or submitting new session requests when the tool is locked. Commit ready for merge.
- Legacy-Id: 8156
1 parent c046739 commit f9d6145

4 files changed

Lines changed: 79 additions & 7 deletions

File tree

ietf/secr/sreq/tests.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
import os
2+
import shutil
3+
14
from django.core.urlresolvers import reverse
5+
from django.conf import settings
26

37
from ietf.utils.test_utils import TestCase
48
from ietf.group.models import Group
9+
#from ietf.meeting.models import Session
510
#from ietf.utils.test_data import make_test_data
611
from ietf.meeting.test_data import make_meeting_test_data as make_test_data
712

8-
#from pyquery import PyQuery
13+
from pyquery import PyQuery
914

1015
SECR_USER='secretary'
1116

@@ -59,6 +64,47 @@ def test_submit_request(self):
5964
r = self.client.get(url)
6065
assert False, r.content
6166
"""
67+
68+
class LockAppTestCase(TestCase):
69+
def setUp(self):
70+
self.agenda_dir = os.path.abspath("tmp-agenda-dir")
71+
os.mkdir(self.agenda_dir)
72+
settings.AGENDA_PATH = self.agenda_dir
73+
path = os.path.join(self.agenda_dir,'session_request.lock')
74+
with open(path, 'w') as f:
75+
f.write('App is locked')
76+
77+
def tearDown(self):
78+
shutil.rmtree(self.agenda_dir)
79+
80+
def test_edit_request(self):
81+
make_test_data()
82+
group = Group.objects.get(acronym='mars')
83+
url = reverse('sessions_edit',kwargs={'acronym':group.acronym})
84+
self.client.login(username="secretary", password="secretary+password")
85+
r = self.client.get(url)
86+
self.assertEqual(r.status_code, 200)
87+
q = PyQuery(r.content)
88+
self.assertEqual(len(q(':disabled[name="submit"]')), 1)
89+
90+
def test_view_request(self):
91+
make_test_data()
92+
group = Group.objects.get(acronym='mars')
93+
url = reverse('sessions_view',kwargs={'acronym':group.acronym})
94+
self.client.login(username="secretary", password="secretary+password")
95+
r = self.client.get(url,follow=True)
96+
self.assertEqual(r.status_code, 200)
97+
q = PyQuery(r.content)
98+
self.assertEqual(len(q(':disabled[name="edit"]')), 1)
99+
100+
def test_new_request(self):
101+
make_test_data()
102+
group = Group.objects.get(acronym='mars')
103+
url = reverse('sessions_new',kwargs={'acronym':group.acronym})
104+
self.client.login(username="secretary", password="secretary+password")
105+
r = self.client.get(url)
106+
self.assertEqual(r.status_code, 302)
107+
62108
class EditRequestCase(TestCase):
63109
pass
64110

@@ -73,4 +119,4 @@ class RetrievePreviousCase(TestCase):
73119
# test error if already scheduled
74120
# test get previous exists/doesn't exist
75121
# test that groups scheduled and unscheduled add up to total groups
76-
# test locking function, access by unauthorized
122+
# test access by unauthorized

ietf/secr/sreq/views.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# Globals
2525
# -------------------------------------------------
2626
SESSION_REQUEST_EMAIL = 'session-request@ietf.org'
27-
LOCKFILE = os.path.join(settings.SECR_PROCEEDINGS_DIR,'session_request.lock')
27+
LOCKFILE = os.path.join(settings.AGENDA_PATH,'session_request.lock')
2828
# -------------------------------------------------
2929
# Helper Functions
3030
# -------------------------------------------------
@@ -355,6 +355,11 @@ def edit_mtg(request, num, acronym):
355355
if 'resources' in initial:
356356
initial['resources'] = [x.pk for x in initial['resources']]
357357

358+
# check if app is locked
359+
is_locked = check_app_locked()
360+
if is_locked:
361+
messages.warning(request, "The Session Request Tool is closed")
362+
358363
session_conflicts = session_conflicts_as_string(group, meeting)
359364
login = request.user.person
360365

@@ -467,6 +472,7 @@ def edit_mtg(request, num, acronym):
467472
form = SessionForm(initial=initial)
468473

469474
return render_to_response('sreq/edit.html', {
475+
'is_locked': is_locked,
470476
'meeting': meeting,
471477
'form': form,
472478
'group': group,
@@ -541,11 +547,16 @@ def new(request, acronym):
541547
This view gathers details for a new session request. The user proceeds to confirm()
542548
to create the request.
543549
'''
544-
545550
group = get_object_or_404(Group, acronym=acronym)
546551
meeting = get_meeting()
547552
session_conflicts = session_conflicts_as_string(group, meeting)
548553

554+
# check if app is locked
555+
is_locked = check_app_locked()
556+
if is_locked:
557+
messages.warning(request, "The Session Request Tool is closed")
558+
return redirect('sessions')
559+
549560
if request.method == 'POST':
550561
button_text = request.POST.get('submit', '')
551562
if button_text == 'Cancel':
@@ -689,9 +700,17 @@ def view(request, acronym, num = None):
689700
group = get_object_or_404(Group, acronym=acronym)
690701
sessions = Session.objects.filter(~Q(status__in=('canceled','notmeet','deleted')),meeting=meeting,group=group).order_by('id')
691702

703+
# check if app is locked
704+
is_locked = check_app_locked()
705+
if is_locked:
706+
messages.warning(request, "The Session Request Tool is closed")
707+
692708
# if there are no session requests yet, redirect to new session request page
693709
if not sessions:
694-
return redirect('sessions_new', acronym=acronym)
710+
if is_locked:
711+
return redirect('sessions')
712+
else:
713+
return redirect('sessions_new', acronym=acronym)
695714

696715
# TODO simulate activity records
697716
activities = [{'act_date':sessions[0].requested.strftime('%b %d, %Y'),
@@ -718,6 +737,7 @@ def view(request, acronym, num = None):
718737
session = get_initial_session(sessions)
719738

720739
return render_to_response('sreq/view.html', {
740+
'is_locked': is_locked,
721741
'session': session,
722742
'activities': activities,
723743
'meeting': meeting,

ietf/secr/templates/includes/sessions_request_form.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@
6262
</tr>
6363
</table>
6464

65-
{% include "includes/buttons_save_cancel.html" %}
65+
<div class="button-group">
66+
<ul>
67+
<li><button type="submit" name="submit" value="Save"{% if is_locked %} disabled{% endif %}>Save</button></li>
68+
<li><button type="submit" name="submit" value="Cancel">Cancel</button></li>
69+
</ul>
70+
</div> <!-- button-group -->
71+
6672

6773
</form>

ietf/secr/templates/sreq/view.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ <h2>Sessions - View (meeting: {{ meeting.number }})</h2>
2828

2929
<div class="button-group">
3030
<ul>
31-
<li><button onclick="window.location='edit/'">Edit</button></li>
31+
<li><button name="edit" onclick="window.location='edit/'"{% if is_locked %} disabled{% endif %}>Edit</button></li>
3232
{% if show_approve_button %}
3333
<li><button onclick="window.location='approve/'">Approve Third Session</button></li>
3434
{% endif %}

0 commit comments

Comments
 (0)