Allow administrators to view talk voting page without throwing exception
authorMagnus Hagander <magnus@hagander.net>
Mon, 13 Aug 2018 20:36:25 +0000 (22:36 +0200)
committerMagnus Hagander <magnus@hagander.net>
Mon, 13 Aug 2018 20:36:25 +0000 (22:36 +0200)
They can of course not vote (and this was already protected for at the
actual endpoints), just view the overview without throwing.

postgresqleu/confreg/views.py
template/confreg/sessionvotes.html

index 950fb53115e04205734ea7001a93985a3c4dcffb..2f7fbe719e8e69357c53a575753feb90017feafe 100644 (file)
@@ -2081,9 +2081,10 @@ def bulkpay_view(request, confname, bulkpayid):
 @transaction.atomic
 def talkvote(request, confname):
        conference = get_object_or_404(Conference, urlname=confname)
-       if not conference.talkvoters.filter(pk=request.user.id):
+       if not conference.talkvoters.filter(pk=request.user.id) and not conference.administrators.filter(pk=request.user.id):
                return HttpResponse('You are not a talk voter for this conference!')
 
+       isvoter = conference.talkvoters.filter(pk=request.user.id).exists()
        isadmin = conference.administrators.filter(pk=request.user.id).exists()
 
        alltracks = [{'id': t.id, 'trackname': t.trackname} for t in Track.objects.filter(conference=conference)]
@@ -2165,6 +2166,7 @@ def talkvote(request, confname):
                        'users': getusernames(all),
                        'sessionvotes': transform(all),
                        'conference': conference,
+                       'isvoter': isvoter,
                        'isadmin': isadmin,
                    'status_choices': STATUS_CHOICES,
                    'tracks': alltracks,
index c07c32e7d96669b3d862610ee05252fa09128bd2..ed9d0b75357fa0e9091e935cab3d028c91cf887d 100644 (file)
@@ -245,7 +245,7 @@ width: 100%;
    <td>{{s.status}}</td>
 {%endif%}
    {%for u in s.users%}
-   <td{%if u|default_if_none:0 == 0%} style="background-color:red"{%endif%}>{%if forloop.first %}
+   <td{%if u|default_if_none:0 == 0%} style="background-color:red"{%endif%}>{%if forloop.first and isvoter %}
      <select id="sv_{{s.id}}" onChange="castVote({{s.id}})">
        {%for opt in "0123456789"|make_list%}
        <option value="{{opt}}"{%if opt|add:0 == u|add:0%} SELECTED{%endif%}>{{opt}}</option>
@@ -258,9 +258,11 @@ width: 100%;
    {%endfor%}
    <td class="avgbox">{{s.avg|default_if_none:''}}</td>
    <td>
+{%if isvoter%}
      <div style="margin-right: 0.5em; float:left;">
        <a class="btn btn-default btn-xs" href="javascript:editComment({{s.id}})"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a>
      </div>
+{%endif%}
      <div style="display:inline-block;">
        <span id="owncommentwrap_{{s.id}}" style="display:{%if s.owncomment%}block{%else%}none{%endif%}">{{user.username}}: <span id="owncomment_{{s.id}}">{{s.owncomment}}</span></span>{{s.comments|safe}}
      </div>