You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@steve.apache.org by hu...@apache.org on 2016/03/27 19:52:20 UTC

svn commit: r1736793 - in /steve/trunk/pysteve: lib/backends/es.py lib/voter.py www/cgi-bin/rest_voter.py

Author: humbedooh
Date: Sun Mar 27 17:52:20 2016
New Revision: 1736793

URL: http://svn.apache.org/viewvc?rev=1736793&view=rev
Log:
weave in a regeneration function that:
- scrubs the votes of the old ballot
- regenerates the ballot ID (voiding the previous ID)
- returns election and new ballot ID

This is part of STEVE-38

Modified:
    steve/trunk/pysteve/lib/backends/es.py
    steve/trunk/pysteve/lib/voter.py
    steve/trunk/pysteve/www/cgi-bin/rest_voter.py

Modified: steve/trunk/pysteve/lib/backends/es.py
URL: http://svn.apache.org/viewvc/steve/trunk/pysteve/lib/backends/es.py?rev=1736793&r1=1736792&r2=1736793&view=diff
==============================================================================
--- steve/trunk/pysteve/lib/backends/es.py (original)
+++ steve/trunk/pysteve/lib/backends/es.py Sun Mar 27 17:52:20 2016
@@ -229,6 +229,24 @@ class ElasticSearchBackend:
             }
         )
         
+    def ballot_scrub(self,election, xhash, uid = None):
+        "Scrub a ballot"
+        if uid:
+            xhash = hashlib.sha224(election + ":" + uid).hexdigest()
+            
+        # Find ballots and votes matching
+        res = self.es.search(index="steve", doc_type="votes", body = {
+            "query": {
+                "match": {
+                    "key": xhash
+                }
+            }
+        }, size = 999)
+        results = len(res['hits']['hits'])
+        if results > 0:
+            for entry in res['hits']['hits']:
+                self.es.delete(index="steve", doc_type="votes", id=entry['_id']);
+        
     def voter_remove(self,election, UID):
         "Remove the voter with the given UID"
         votehash = hashlib.sha224(election + ":" + UID).hexdigest()

Modified: steve/trunk/pysteve/lib/voter.py
URL: http://svn.apache.org/viewvc/steve/trunk/pysteve/lib/voter.py?rev=1736793&r1=1736792&r2=1736793&view=diff
==============================================================================
--- steve/trunk/pysteve/lib/voter.py (original)
+++ steve/trunk/pysteve/lib/voter.py Sun Mar 27 17:52:20 2016
@@ -59,6 +59,19 @@ def ballots():
     except:
         return {}
 
+def regenerate(election, basedata, xhash):
+    try:
+        from lib import gateway
+        uid = gateway.uid()
+        backend.ballot_scrub(election, xhash)
+        ballot = add(election, basedata, uid)
+        return {
+            'election': election,
+            'ballot': ballot
+        }
+    except:
+        return {'error': "No suitable gateway mechanism found"}
+    
 def email(rcpt, subject, message):
     sender = config.get("email", "sender")
     signature = config.get("email", "signature")

Modified: steve/trunk/pysteve/www/cgi-bin/rest_voter.py
URL: http://svn.apache.org/viewvc/steve/trunk/pysteve/www/cgi-bin/rest_voter.py?rev=1736793&r1=1736792&r2=1736793&view=diff
==============================================================================
--- steve/trunk/pysteve/www/cgi-bin/rest_voter.py (original)
+++ steve/trunk/pysteve/www/cgi-bin/rest_voter.py Sun Mar 27 17:52:20 2016
@@ -115,6 +115,15 @@ if pathinfo:
     elif action == "ballots":
         # We defer to the gateway to provide us with UID here
         response.respond(200, voter.ballots())
+        
+    elif action == "regenerate" and electionID and issueID:
+        # Regenerate a ballot, scrub all votes.
+        xhash = issueID
+        basedata = election.getBasedata(electionID)
+        if basedata:
+            response.respond(200, voter.regenerate(electionID, basedata, xhash))
+        else:
+            response.respond(404, {'message': "No such election"})
             
     elif action == "vote" and electionID and issueID and voterID:
         try: