From 1d07bbc2e47310ac1a377740947318648618293d Mon Sep 17 00:00:00 2001 From: Marco Ciotola <848222@stud.unive.it> Date: Thu, 7 Mar 2019 19:36:22 +0100 Subject: [PATCH] Make stats_url_names and election_url_names visible from url_names --- helios/stats_views.py | 5 ++-- helios/url_names.py | 11 ++++++++ helios/views.py | 63 +++++++++++++++++++++---------------------- 3 files changed, 44 insertions(+), 35 deletions(-) diff --git a/helios/stats_views.py b/helios/stats_views.py index 5fc07e6..9d19dd6 100644 --- a/helios/stats_views.py +++ b/helios/stats_views.py @@ -9,9 +9,8 @@ from django.core.urlresolvers import reverse from django.db.models import Max, Count from django.http import HttpResponseRedirect -from helios import tasks +from helios import tasks, url_names from helios.models import CastVote, Election -from helios.stats_url_names import STATS_HOME from helios_auth.security import get_user from security import PermissionDenied from view_utils import render_template @@ -35,7 +34,7 @@ def force_queue(request): for cv in votes_in_queue: tasks.cast_vote_verify_and_store.delay(cv.id) - return HttpResponseRedirect(reverse(STATS_HOME)) + return HttpResponseRedirect(reverse(url_names.stats.STATS_HOME)) def elections(request): user = require_admin(request) diff --git a/helios/url_names.py b/helios/url_names.py index 96b0eb1..319a9be 100644 --- a/helios/url_names.py +++ b/helios/url_names.py @@ -1,3 +1,14 @@ +from helios import election_url_names as election, stats_url_names as stats + +__all__ = [ + "election", "stats", + "COOKIE_TEST", "COOKIE_TEST_2", "COOKIE_NO", + "ELECTION_SHORTCUT", "ELECTION_SHORTCUT_VOTE", "CAST_VOTE_SHORTCUT", + "TRUSTEE_LOGIN", + "ELECTIONS_PARAMS", "ELECTIONS_VERIFIER", "ELECTIONS_VERIFIER_SINGLE_BALLOT", + "ELECTIONS_NEW", "ELECTIONS_ADMINISTERED", "ELECTIONS_VOTED", +] + COOKIE_TEST="cookie@test" COOKIE_TEST_2="cookie@test2" COOKIE_NO="cookie@no" diff --git a/helios/views.py b/helios/views.py index 1dfe9c7..bb7d640 100644 --- a/helios/views.py +++ b/helios/views.py @@ -15,7 +15,6 @@ from validate_email import validate_email import urllib, os, base64 -import election_url_names as election_names from crypto import algs, electionalgs, elgamal from crypto import utils as cryptoutils from workflows import homomorphic @@ -61,7 +60,7 @@ def get_election_url(election): return settings.URL_HOST + reverse(url_names.ELECTION_SHORTCUT, args=[election.short_name]) def get_election_badge_url(election): - return settings.URL_HOST + reverse(election_names.ELECTION_BADGE, args=[election.uuid]) + return settings.URL_HOST + reverse(url_names.election.ELECTION_BADGE, args=[election.uuid]) def get_election_govote_url(election): return settings.URL_HOST + reverse(url_names.ELECTION_SHORTCUT_VOTE, args=[election.short_name]) @@ -117,14 +116,14 @@ def election_single_ballot_verifier(request): def election_shortcut(request, election_short_name): election = Election.get_by_short_name(election_short_name) if election: - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW, args=[election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW, args=[election.uuid])) else: raise Http404 # a hidden view behind the shortcut that performs the actual perm check @election_view() def _election_vote_shortcut(request, election): - vote_url = "%s/booth/vote.html?%s" % (settings.SECURE_URL_HOST, urllib.urlencode({'election_url' : reverse(election_names.ELECTION_HOME, args=[election.uuid])})) + vote_url = "%s/booth/vote.html?%s" % (settings.SECURE_URL_HOST, urllib.urlencode({'election_url' : reverse(url_names.election.ELECTION_HOME, args=[election.uuid])})) test_cookie_url = "%s?%s" % (reverse(url_names.COOKIE_TEST), urllib.urlencode({'continue_url' : vote_url})) @@ -209,7 +208,7 @@ def election_new(request): try: election = Election.objects.create(**election_params) election.generate_trustee(ELGAMAL_PARAMS) - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW, args=[election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW, args=[election.uuid])) except IntegrityError: error = "An election with short name %s already exists" % election_params['short_name'] else: @@ -242,7 +241,7 @@ def one_election_edit(request, election): setattr(election, attr_name, clean_data[attr_name]) try: election.save() - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW, args=[election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW, args=[election.uuid])) except IntegrityError: error = "An election with short name %s already exists" % clean_data['short_name'] @@ -265,7 +264,7 @@ def one_election_extend(request, election): election.voting_extended_until = clean_data['voting_extended_until'] election.save() - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW, args=[election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW, args=[election.uuid])) return render_template(request, "election_extend", {'election_form' : election_form, 'election' : election}) @@ -304,7 +303,7 @@ def one_election_view(request, election): election_badge_url = get_election_badge_url(election) status_update_message = None - vote_url = "%s/booth/vote.html?%s" % (settings.SECURE_URL_HOST, urllib.urlencode({'election_url' : reverse(election_names.ELECTION_HOME, args=[election.uuid])})) + vote_url = "%s/booth/vote.html?%s" % (settings.SECURE_URL_HOST, urllib.urlencode({'election_url' : reverse(url_names.election.ELECTION_HOME, args=[election.uuid])})) test_cookie_url = "%s?%s" % (reverse(url_names.COOKIE_TEST), urllib.urlencode({'continue_url' : vote_url})) @@ -400,7 +399,7 @@ def new_trustee(request, election): trustee = Trustee(uuid = str(uuid.uuid1()), election = election, name=name, email=email) trustee.save() - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_TRUSTEES_VIEW, args=[election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_TRUSTEES_VIEW, args=[election.uuid])) @election_admin(frozen=False) def new_trustee_helios(request, election): @@ -408,13 +407,13 @@ def new_trustee_helios(request, election): Make Helios a trustee of the election """ election.generate_trustee(ELGAMAL_PARAMS) - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_TRUSTEES_VIEW, args=[election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_TRUSTEES_VIEW, args=[election.uuid])) @election_admin(frozen=False) def delete_trustee(request, election): trustee = Trustee.get_by_election_and_uuid(election, request.GET['uuid']) trustee.delete() - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_TRUSTEES_VIEW, args=[election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_TRUSTEES_VIEW, args=[election.uuid])) def trustee_login(request, election_short_name, trustee_email, trustee_secret): election = Election.get_by_short_name(election_short_name) @@ -424,7 +423,7 @@ def trustee_login(request, election_short_name, trustee_email, trustee_secret): if trustee: if trustee.secret == trustee_secret: set_logged_in_trustee(request, trustee) - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_TRUSTEE_HOME, args=[election.uuid, trustee.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_TRUSTEE_HOME, args=[election.uuid, trustee.uuid])) else: # bad secret, we'll let that redirect to the front page pass @@ -455,7 +454,7 @@ Helios utils.send_email(settings.SERVER_EMAIL, ["%s <%s>" % (trustee.name, trustee.email)], 'your trustee homepage for %s' % election.name, body) logging.info("URL %s " % url) - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_TRUSTEES_VIEW, args = [election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_TRUSTEES_VIEW, args = [election.uuid])) @trustee_check def trustee_home(request, election, trustee): @@ -488,7 +487,7 @@ def trustee_upload_pk(request, election, trustee): # oh well, no message sent pass - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_TRUSTEE_HOME, args=[election.uuid, trustee.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_TRUSTEE_HOME, args=[election.uuid, trustee.uuid])) ## ## Ballot Management @@ -536,7 +535,7 @@ def one_election_cast(request, election): on a GET, this is a cancellation, on a POST it's a cast """ if request.method == "GET": - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW, args = [election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW, args = [election.uuid])) user = get_user(request) encrypted_vote = request.POST['encrypted_vote'] @@ -565,7 +564,7 @@ def password_voter_login(request, election): # if user logged in somehow in the interim, e.g. using the login link for administration, # then go! if user_can_see_election(request, election): - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW, args = [election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW, args = [election.uuid])) password_login_form = forms.VoterPasswordForm() return render_template(request, 'password_voter_login', @@ -580,7 +579,7 @@ def password_voter_login(request, election): # login depending on whether this is a private election # cause if it's private the login is happening on the front page if election.private_p: - login_url = reverse(election_names.ELECTION_PASSWORD_VOTER_LOGIN, args=[election.uuid]) + login_url = reverse(url_names.election.ELECTION_PASSWORD_VOTER_LOGIN, args=[election.uuid]) else: login_url = reverse(one_election_cast_confirm, args=[election.uuid]) @@ -936,7 +935,7 @@ def one_election_set_featured(request, election): election.featured_p = featured_p election.save() - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW, args=[election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW, args=[election.uuid])) @election_admin() def one_election_archive(request, election): @@ -950,7 +949,7 @@ def one_election_archive(request, election): election.save() - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW, args=[election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW, args=[election.uuid])) @election_admin() def one_election_copy(request, election): @@ -984,7 +983,7 @@ def one_election_copy(request, election): new_election.generate_trustee(ELGAMAL_PARAMS) - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW, args=[new_election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW, args=[new_election.uuid])) # changed from admin to view because # anyone can see the questions, the administration aspect is now @@ -1023,7 +1022,7 @@ def one_election_register(request, election): if not voter: voter = _register_voter(election, user) - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW, args=[election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW, args=[election.uuid])) @election_admin(frozen=False) def one_election_save_questions(request, election): @@ -1052,7 +1051,7 @@ def one_election_freeze(request, election): election.freeze() if get_user(request): - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW, args=[election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW, args=[election.uuid])) else: return SUCCESS @@ -1068,7 +1067,7 @@ def one_election_compute_tally(request, election): tallying is done all at a time now """ if not _check_election_tally_type(election): - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW,args=[election.election_id])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW,args=[election.election_id])) if request.method == "GET": return render_template(request, 'election_compute_tally', {'election': election}) @@ -1083,12 +1082,12 @@ def one_election_compute_tally(request, election): tasks.election_compute_tally.delay(election_id = election.id) - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW,args=[election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW,args=[election.uuid])) @trustee_check def trustee_decrypt_and_prove(request, election, trustee): if not _check_election_tally_type(election) or election.encrypted_tally == None: - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW,args=[election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW,args=[election.uuid])) return render_template(request, 'trustee_decrypt_and_prove', {'election': election, 'trustee': trustee}) @@ -1137,7 +1136,7 @@ def release_result(request, election): if request.POST.get('send_email', ''): return HttpResponseRedirect("%s?%s" % (settings.SECURE_URL_HOST + reverse(voters_email, args=[election.uuid]),urllib.urlencode({'template': 'result'}))) else: - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW, args=[election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW, args=[election.uuid])) # if just viewing the form or the form is not valid return render_template(request, 'release_result', {'election': election}) @@ -1156,7 +1155,7 @@ def combine_decryptions(request, election): election.combine_decryptions() election.save() - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW, args=[election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW, args=[election.uuid])) # if just viewing the form or the form is not valid return render_template(request, 'combine_decryptions', {'election': election}) @@ -1164,7 +1163,7 @@ def combine_decryptions(request, election): @election_admin(frozen=True) def one_election_set_result_and_proof(request, election): if election.tally_type != "homomorphic" or election.encrypted_tally == None: - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW, args=[election.election_id])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW, args=[election.election_id])) # FIXME: check csrf @@ -1173,7 +1172,7 @@ def one_election_set_result_and_proof(request, election): election.save() if get_user(request): - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW, args=[election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW, args=[election.uuid])) else: return SUCCESS @@ -1332,12 +1331,12 @@ def voters_upload_cancel(request, election): vf.delete() del request.session['voter_file_id'] - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW, args=[election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW, args=[election.uuid])) @election_admin(frozen=True) def voters_email(request, election): if not VOTERS_EMAIL: - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW, args=[election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW, args=[election.uuid])) TEMPLATES = [ ('vote', 'Time to Vote'), ('simple', 'Simple'), @@ -1414,7 +1413,7 @@ def voters_email(request, election): tasks.voters_email.delay(election_id = election.id, subject_template = subject_template, body_template = body_template, extra_vars = extra_vars, voter_constraints_include = voter_constraints_include, voter_constraints_exclude = voter_constraints_exclude) # this batch process is all async, so we can return a nice note - return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(election_names.ELECTION_VIEW, args=[election.uuid])) + return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(url_names.election.ELECTION_VIEW, args=[election.uuid])) return render_template(request, "voters_email", { 'email_form': email_form, 'election': election, -- GitLab