Skip to content

Commit 1ef73b5

Browse files
committed
Reworked the worst of the conflicting permissions policies
- Legacy-Id: 7458
1 parent f4a72ff commit 1ef73b5

4 files changed

Lines changed: 36 additions & 45 deletions

File tree

ietf/meeting/ajax.py

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.core.urlresolvers import reverse
55
from django.shortcuts import get_object_or_404, redirect
66
from django.http import HttpResponseRedirect, HttpResponse
7+
from django.views.decorators.http import require_POST
78

89
from dajaxice.decorators import dajaxice_register
910
from ietf.ietfauth.utils import role_required, has_role, user_is_person
@@ -316,47 +317,34 @@ def agenda_add(request, meeting):
316317
else:
317318
return redirect(edit_agenda, meeting.number, newagenda.name)
318319

319-
@role_required('Area Director','Secretariat')
320+
@require_POST
320321
def agenda_update(request, meeting, schedule):
321322
# forms are completely useless for update actions that want to
322323
# accept a subset of values. (huh? we could use required=False)
323324

324-
#debug.log("99 meeting.agenda: %s / %s / %s" %
325-
# (schedule, update_dict, request.body))
326-
327325
user = request.user
328326

327+
if not user.is_authenticated():
328+
return HttpResponse({'error':'no permission'}, status=403)
329+
329330
cansee,canedit = agenda_permissions(meeting, schedule, request.user)
330331
read_only = not canedit
331332

332-
if has_role(user, "Secretariat"):
333-
if "public" in request.POST:
334-
value1 = True
335-
value = request.POST["public"]
336-
if value == "0" or value == 0 or value=="false":
337-
value1 = False
338-
#debug.log("setting public for %s to %s" % (schedule, value1))
339-
schedule.public = value1
340-
341-
if "visible" in request.POST and cansee:
342-
value1 = True
343-
value = request.POST["visible"]
344-
if value == "0" or value == 0 or value=="false":
345-
value1 = False
346-
#debug.log("setting visible for %s to %s" % (schedule, value1))
347-
schedule.visible = value1
348-
if has_role(user, "Secretariat") and canedit:
349-
if "name" in request.POST:
350-
value = request.POST["name"]
351-
#log.debug("setting name for %s to %s" % (schedule, value))
352-
schedule.name = value
353-
else:
354-
return HttpResponse({'error':'no permission'}, status=401)
333+
def is_truthy_enough(value):
334+
return not (value == "0" or value == 0 or value=="false")
335+
336+
# TODO: Secretariat should always get canedit
337+
if not (canedit or has_role(user, "Secretariat")):
338+
return HttpResponse({'error':'no permission'}, status=403)
339+
340+
if "public" in request.POST:
341+
schedule.public = is_truthy_enough(request.POST["public"])
342+
343+
if "visible" in request.POST:
344+
schedule.visible = is_truthy_enough(request.POST["visible"])
355345

356346
if "name" in request.POST:
357-
value = request.POST["name"]
358-
#debug.log("setting name for %s to %s" % (schedule, value))
359-
schedule.name = value
347+
schedule.name = request.POST["name"]
360348

361349
schedule.save()
362350

ietf/meeting/tests_api.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,16 +294,13 @@ def test_update_schedule(self):
294294
'name': 'new-test-name',
295295
}
296296

297-
# unauthorized post
298-
self.client.login(remote_user="plain")
297+
# unauthorized posts
298+
self.client.logout()
299+
r = self.client.post(url, post_data)
300+
self.assertEqual(r.status_code, 403)
301+
self.client.login(remote_user="ad")
299302
r = self.client.post(url, post_data)
300303
self.assertEqual(r.status_code, 403)
301-
302-
# TODO - permission protection on this function are not right
303-
# Normal users are prevented from changing public/private on their own schedule
304-
# The secretariat can't change normal user's agendas settings for them, and the
305-
# page at /meeting/<num>/schedule/<name>/details behaves badly for the secretariat
306-
# (pushing save seems to do nothing as the POST 401s in the background)
307304

308305
# change agenda
309306
self.client.login(remote_user="secretary")

ietf/meeting/views.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from django import forms
1414
from django.shortcuts import render_to_response, get_object_or_404, redirect
15-
from django.http import HttpResponse, Http404
15+
from django.http import HttpResponse, HttpResponseForbidden, Http404
1616
from django.core.urlresolvers import reverse
1717
from django.db.models import Q
1818
from django.template import RequestContext
@@ -322,11 +322,16 @@ def edit_agenda_properties(request, num=None, name=None):
322322
schedule = get_schedule(meeting, name)
323323
form = AgendaPropertiesForm(instance=schedule)
324324

325-
return HttpResponse(render_to_string("meeting/properties_edit.html",
326-
{"schedule":schedule,
327-
"form":form,
328-
"meeting":meeting},
329-
RequestContext(request)), content_type="text/html")
325+
cansee, canedit = agenda_permissions(meeting, schedule, request.user)
326+
327+
if not (canedit or has_role(request.user,'Secretariat')):
328+
return HttpResponseForbidden("You may not edit this agenda")
329+
else:
330+
return HttpResponse(render_to_string("meeting/properties_edit.html",
331+
{"schedule":schedule,
332+
"form":form,
333+
"meeting":meeting},
334+
RequestContext(request)), content_type="text/html")
330335

331336
##############################################################################
332337
# show list of agendas.

ietf/secr/meetings/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ def add(request):
278278
owner = Person.objects.get(name='(System)'),
279279
visible = True,
280280
public = True)
281-
meeting.set_official_agenda(schedule)
281+
meeting.agenda = schedule
282+
meeting.save()
282283

283284
#Create Physical new meeting directory and subdirectories
284285
make_directories(meeting)

0 commit comments

Comments
 (0)