|
4 | 4 | from django.core.urlresolvers import reverse |
5 | 5 | from django.shortcuts import get_object_or_404, redirect |
6 | 6 | from django.http import HttpResponseRedirect, HttpResponse |
| 7 | +from django.views.decorators.http import require_POST |
7 | 8 |
|
8 | 9 | from dajaxice.decorators import dajaxice_register |
9 | 10 | from ietf.ietfauth.utils import role_required, has_role, user_is_person |
@@ -316,47 +317,34 @@ def agenda_add(request, meeting): |
316 | 317 | else: |
317 | 318 | return redirect(edit_agenda, meeting.number, newagenda.name) |
318 | 319 |
|
319 | | -@role_required('Area Director','Secretariat') |
| 320 | +@require_POST |
320 | 321 | def agenda_update(request, meeting, schedule): |
321 | 322 | # forms are completely useless for update actions that want to |
322 | 323 | # accept a subset of values. (huh? we could use required=False) |
323 | 324 |
|
324 | | - #debug.log("99 meeting.agenda: %s / %s / %s" % |
325 | | - # (schedule, update_dict, request.body)) |
326 | | - |
327 | 325 | user = request.user |
328 | 326 |
|
| 327 | + if not user.is_authenticated(): |
| 328 | + return HttpResponse({'error':'no permission'}, status=403) |
| 329 | + |
329 | 330 | cansee,canedit = agenda_permissions(meeting, schedule, request.user) |
330 | 331 | read_only = not canedit |
331 | 332 |
|
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"]) |
355 | 345 |
|
356 | 346 | 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"] |
360 | 348 |
|
361 | 349 | schedule.save() |
362 | 350 |
|
|
0 commit comments