From 12344a26cac7aca841056f7b0b6311be90020d4a Mon Sep 17 00:00:00 2001 From: Ben Adida <ben@adida.net> Date: Sun, 27 Oct 2013 11:00:18 -0700 Subject: [PATCH] added election metadata API endpoint and call from client to get things like help email address --- helios/election_urls.py | 4 ++++ .../legacy-election-metadata-expected.json | 1 + helios/models.py | 8 ++++++++ helios/tests.py | 5 +++++ helios/views.py | 7 +++++++ heliosbooth/templates/footer.html | 2 +- heliosbooth/vote.html | 14 +++++++++----- 7 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 helios/fixtures/legacy-election-metadata-expected.json diff --git a/helios/election_urls.py b/helios/election_urls.py index 323c2b0..459e131 100644 --- a/helios/election_urls.py +++ b/helios/election_urls.py @@ -9,7 +9,11 @@ from django.conf.urls.defaults import * from helios.views import * urlpatterns = patterns('', + # election data that is cryptographically verified (r'^$', one_election), + + # metadata that need not be verified + (r'^/meta$', one_election_meta), # edit election params (r'^/edit$', one_election_edit), diff --git a/helios/fixtures/legacy-election-metadata-expected.json b/helios/fixtures/legacy-election-metadata-expected.json new file mode 100644 index 0000000..5356f38 --- /dev/null +++ b/helios/fixtures/legacy-election-metadata-expected.json @@ -0,0 +1 @@ +{"help_email": "help@heliosvoting.org", "use_advanced_audit_features": true} \ No newline at end of file diff --git a/helios/models.py b/helios/models.py index 284d1a2..1d8f131 100644 --- a/helios/models.py +++ b/helios/models.py @@ -133,6 +133,14 @@ class Election(HeliosModel): # help email help_email = models.EmailField(null=True) + # metadata for the election + @property + def metadata(self): + return { + 'help_email': self.help_email or 'help@heliosvoting.org', + 'use_advanced_audit_features': self.use_advanced_audit_features + } + @property def pretty_type(self): return dict(self.ELECTION_TYPES)[self.election_type] diff --git a/helios/tests.py b/helios/tests.py index 626c540..e8e7fb2 100644 --- a/helios/tests.py +++ b/helios/tests.py @@ -312,6 +312,10 @@ class DataFormatBlackboxTests(object): response = self.client.get("/helios/elections/%s" % self.election.uuid, follow=False) self.assertEqualsToFile(response, self.EXPECTED_ELECTION_FILE) + def test_election_metadata(self): + response = self.client.get("/helios/elections/%s/meta" % self.election.uuid, follow=False) + self.assertEqualsToFile(response, self.EXPECTED_ELECTION_METADATA_FILE) + def test_voters_list(self): response = self.client.get("/helios/elections/%s/voters/" % self.election.uuid, follow=False) self.assertEqualsToFile(response, self.EXPECTED_VOTERS_FILE) @@ -331,6 +335,7 @@ class DataFormatBlackboxTests(object): class LegacyElectionBlackboxTests(DataFormatBlackboxTests, TestCase): fixtures = ['legacy-data.json'] EXPECTED_ELECTION_FILE = 'helios/fixtures/legacy-election-expected.json' + EXPECTED_ELECTION_METADATA_FILE = 'helios/fixtures/legacy-election-metadata-expected.json' EXPECTED_VOTERS_FILE = 'helios/fixtures/legacy-election-voters-expected.json' EXPECTED_TRUSTEES_FILE = 'helios/fixtures/legacy-trustees-expected.json' EXPECTED_BALLOTS_FILE = 'helios/fixtures/legacy-ballots-expected.json' diff --git a/helios/views.py b/helios/views.py index 54faf88..45b1c8a 100644 --- a/helios/views.py +++ b/helios/views.py @@ -290,6 +290,13 @@ def one_election(request, election): raise Http404 return election.toJSONDict(complete=True) +@election_view() +@json +def one_election_meta(request, election): + if not election: + raise Http404 + return election.metadata + @election_view() def election_badge(request, election): election_url = get_election_url(election) diff --git a/heliosbooth/templates/footer.html b/heliosbooth/templates/footer.html index e064204..750fa43 100644 --- a/heliosbooth/templates/footer.html +++ b/heliosbooth/templates/footer.html @@ -1,5 +1,5 @@ <span style="float:right; padding-right:20px;"> -<a target="_new" href="mailto:help@heliosvoting.org?subject=help%20with%20election%20{$T.election.name}&body=I%20need%20help%20with%20election%20{$T.election.uuid}">help!</a> +<a target="_new" href="mailto:{$T.election_metadata.help_email}?subject=help%20with%20election%20{$T.election.name}&body=I%20need%20help%20with%20election%20{$T.election.uuid}">help!</a> </span> {#if $T.election.BOGUS_P} The public key for this election is not yet ready. This election is in preview mode only. diff --git a/heliosbooth/vote.html b/heliosbooth/vote.html index 803a917..7ab271f 100644 --- a/heliosbooth/vote.html +++ b/heliosbooth/vote.html @@ -182,8 +182,8 @@ BOOTH.setup_election = function(raw_json) { BOOTH.election[field] = escape_html(BOOTH.election[field]); }); - $('#header').processTemplate({'election' : BOOTH.election}); - $('#footer').processTemplate({'election' : BOOTH.election}); + $('#header').processTemplate({'election' : BOOTH.election, 'election_metadata': BOOTH.election_metadata}); + $('#footer').processTemplate({'election' : BOOTH.election, 'election_metadata': BOOTH.election_metadata}); BOOTH.setup_ballot(); }; @@ -326,9 +326,13 @@ BOOTH.show_encryption_message_before = function(func_to_execute) { BOOTH.load_and_setup_election = function(election_url) { // the hash will be computed within the setup function call now $.get(election_url, function(raw_json) { - BOOTH.setup_election(raw_json); - BOOTH.show_election(); - BOOTH.election_url = election_url; + // let's also get the metadata + $.getJSON(election_url + "/meta", {}, function(election_metadata) { + BOOTH.election_metadata = election_metadata; + BOOTH.setup_election(raw_json); + BOOTH.show_election(); + BOOTH.election_url = election_url; + }); }); -- GitLab