Skip to content
Snippets Groups Projects
Commit 4597e7d1 authored by Ben Adida's avatar Ben Adida
Browse files

ensured links for private elections work, with proper return_url

parent a77e9730
No related branches found
No related tags found
No related merge requests found
deploy-latest.sh
app.yaml app.yaml
settings.py settings.py
initialization.py initialization.py
......
...@@ -41,7 +41,7 @@ PRODUCTION_SETUPS = [ ...@@ -41,7 +41,7 @@ PRODUCTION_SETUPS = [
'root' : "/web/princeton/helios-server", 'root' : "/web/princeton/helios-server",
'celery' : "/etc/init.d/princeton-celeryd", 'celery' : "/etc/init.d/princeton-celeryd",
'dbname' : "princeton-helios" 'dbname' : "princeton-helios"
}, }
] ]
def run_tests(): def run_tests():
...@@ -101,13 +101,11 @@ def restart_apache(): ...@@ -101,13 +101,11 @@ def restart_apache():
abort("could not restart apache") abort("could not restart apache")
def restart_celeryd(path): def restart_celeryd(path):
result = sudo('%s restart' % celery_path) result = sudo('%s restart' % path)
if result.failed: if result.failed:
abort("could not restart celeryd - %s " % celery_path) abort("could not restart celeryd - %s " % path)
def deploy(tag, path): def deploy(tag, path):
confirm("Ready to deploy %s to %s?" % (tag,path))
run_tests()
if tag == 'latest': if tag == 'latest':
get_latest(path=path) get_latest(path=path)
else: else:
...@@ -120,6 +118,10 @@ def staging_deploy(tag): ...@@ -120,6 +118,10 @@ def staging_deploy(tag):
deploy(tag, path=STAGING_SETUP['root']) deploy(tag, path=STAGING_SETUP['root'])
def production_deploy(tag): def production_deploy(tag):
production_roots = ",".join([p['root'] for p in PRODUCTION_SETUPS])
if not confirm("Ready to deploy %s to %s?" % (tag, production_roots)):
return
run_tests()
for prod_setup in PRODUCTION_SETUPS: for prod_setup in PRODUCTION_SETUPS:
deploy(tag, path = prod_setup['root']) deploy(tag, path = prod_setup['root'])
restart_celeryd(path = prod_setup['celery']) restart_celeryd(path = prod_setup['celery'])
...@@ -15,6 +15,7 @@ from models import * ...@@ -15,6 +15,7 @@ from models import *
from auth.security import get_user from auth.security import get_user
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
import urllib
import helios import helios
...@@ -82,8 +83,10 @@ def election_view(**checks): ...@@ -82,8 +83,10 @@ def election_view(**checks):
from views import get_voter, get_user, password_voter_login from views import get_voter, get_user, password_voter_login
user = get_user(request) user = get_user(request)
if not user_can_admin_election(user, election) and not get_voter(request, user, election): if not user_can_admin_election(user, election) and not get_voter(request, user, election):
# FIXME: should be a nice redirect return_url = request.get_full_path()
return HttpResponseRedirect(reverse(password_voter_login, args=[election.uuid])) return HttpResponseRedirect("%s?%s" % (reverse(password_voter_login, args=[election.uuid]), urllib.urlencode({
'return_url' : return_url
})))
return func(request, election, *args, **kw) return func(request, election, *args, **kw)
......
Please provide the voter ID and password you received by email.<br /><br /> Please provide the voter ID and password you received by email.<br /><br />
<form method="post" action="{% url helios.views.password_voter_login election.uuid %}"> <form method="post" action="{% url helios.views.password_voter_login election.uuid %}">
<input type="hidden" name="csrf_token" value="{{csrf_token}}" /> <input type="hidden" name="csrf_token" value="{{csrf_token}}" />
<input type="hidden" name="return_url" value="{{return_url}}" />
<table> <table>
{{password_login_form.as_table}} {{password_login_form.as_table}}
</table> </table>
......
...@@ -155,14 +155,19 @@ def election_shortcut(request, election_short_name): ...@@ -155,14 +155,19 @@ def election_shortcut(request, election_short_name):
else: else:
raise Http404 raise Http404
def election_vote_shortcut(request, election_short_name): # a hidden view behind the shortcut that performs the actual perm check
election = Election.get_by_short_name(election_short_name) @election_view()
if election: def _election_vote_shortcut(request, election):
vote_url = "%s/booth/vote.html?%s" % (settings.SECURE_URL_HOST, urllib.urlencode({'election_url' : reverse(one_election, args=[election.uuid])})) vote_url = "%s/booth/vote.html?%s" % (settings.SECURE_URL_HOST, urllib.urlencode({'election_url' : reverse(one_election, args=[election.uuid])}))
test_cookie_url = "%s?%s" % (reverse(test_cookie), urllib.urlencode({'continue_url' : vote_url})) test_cookie_url = "%s?%s" % (reverse(test_cookie), urllib.urlencode({'continue_url' : vote_url}))
return HttpResponseRedirect(test_cookie_url) return HttpResponseRedirect(test_cookie_url)
def election_vote_shortcut(request, election_short_name):
election = Election.get_by_short_name(election_short_name)
if election:
return _election_vote_shortcut(request, election_uuid=election.uuid)
else: else:
raise Http404 raise Http404
...@@ -542,18 +547,25 @@ def password_voter_login(request, election): ...@@ -542,18 +547,25 @@ def password_voter_login(request, election):
This is used to log in as a voter for a particular election This is used to log in as a voter for a particular election
""" """
# the URL to send the user to after they've logged in
return_url = request.REQUEST.get('return_url', reverse(one_election_cast_confirm, args=[election.uuid]))
if request.method == "GET": if request.method == "GET":
password_login_form = forms.VoterPasswordForm() password_login_form = forms.VoterPasswordForm()
return render_template(request, 'password_voter_login', {'election': election, 'password_login_form': password_login_form}) return render_template(request, 'password_voter_login', {'election': election,
'return_url' : return_url,
'password_login_form': password_login_form})
password_login_form = forms.VoterPasswordForm(request.POST) login_url = request.REQUEST.get('login_url', None)
# redirect base depending on whether this is a private election if not login_url:
# login depending on whether this is a private election
# cause if it's private the login is happening on the front page # cause if it's private the login is happening on the front page
if election.private_p: if election.private_p:
redirect_base = reverse(one_election_view, args=[election.uuid]) login_url = reverse(one_election_view, args=[election.uuid])
else: else:
redirect_base = reverse(one_election_cast_confirm, args=[election.uuid]) login_url = reverse(one_election_cast_confirm, args=[election.uuid])
password_login_form = forms.VoterPasswordForm(request.POST)
if password_login_form.is_valid(): if password_login_form.is_valid():
try: try:
...@@ -562,9 +574,9 @@ def password_voter_login(request, election): ...@@ -562,9 +574,9 @@ def password_voter_login(request, election):
request.session['CURRENT_VOTER'] = voter request.session['CURRENT_VOTER'] = voter
except Voter.DoesNotExist: except Voter.DoesNotExist:
return HttpResponseRedirect(redirect_base + "?bad_voter_login=1") return HttpResponseRedirect(login_url + "?bad_voter_login=1")
return HttpResponseRedirect(redirect_base) return HttpResponseRedirect(return_url)
@election_view(frozen=True) @election_view(frozen=True)
def one_election_cast_confirm(request, election): def one_election_cast_confirm(request, election):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment