Author: humbedooh
Date: Sun Mar 27 17:03:19 2016
New Revision: 1736776

URL: http://svn.apache.org/viewvc?rev=1736776&view=rev
Log:
first stab at adding a plugin for determining previous/current ballots based on 
LDAP

Added:
    steve/trunk/pysteve/lib/gateway.py
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=1736776&r1=1736775&r2=1736776&view=diff
==============================================================================
--- steve/trunk/pysteve/lib/backends/es.py (original)
+++ steve/trunk/pysteve/lib/backends/es.py Sun Mar 27 17:03:19 2016
@@ -242,4 +242,30 @@ class ElasticSearchBackend:
         except:
             return False
 
+    def voter_ballots(self, UID):
+        """Find all elections (and ballots) this user has participated in"""
+        
+        # First, get all elections
+        elections = {}
+        
+        res = self.es.search(index="steve", doc_type="elections", sort = "id", 
q = "*", size = 9999)
+        results = len(res['hits']['hits'])
+        if results > 0:
+            for entry in res['hits']['hits']:
+                election  = entry['_source']
+                # Mark election open or closed
+                elections[election['id']] = False if election['closed'] else 
True
+                
+        # Then, get all ballots and note whether they still apply or not
+        ballots = {}
+        res = self.es.search(index="steve", doc_type="voters", q = 
"uid:\"%s\"" % UID, size = 999)
+        results = len(res['hits']['hits'])
+        if results > 0:
+            for entry in res['hits']['hits']:
+                ballot = entry['_source']
+                ballots[ballot['election']] = {
+                    'ballot': entry['_id'],
+                    'open': elections[ballot['election']]
+                }
+        
 constants.appendBackend("elasticsearch", ElasticSearchBackend)
\ No newline at end of file

Added: steve/trunk/pysteve/lib/gateway.py
URL: 
http://svn.apache.org/viewvc/steve/trunk/pysteve/lib/gateway.py?rev=1736776&view=auto
==============================================================================
--- steve/trunk/pysteve/lib/gateway.py (added)
+++ steve/trunk/pysteve/lib/gateway.py Sun Mar 27 17:03:19 2016
@@ -0,0 +1,6 @@
+#!/usr/bin/env python
+
+import os
+
+def uid():
+    return os.environ['REMOTE_USER'] if 'REMOTE_USER' in os.environ else None

Modified: steve/trunk/pysteve/lib/voter.py
URL: 
http://svn.apache.org/viewvc/steve/trunk/pysteve/lib/voter.py?rev=1736776&r1=1736775&r2=1736776&view=diff
==============================================================================
--- steve/trunk/pysteve/lib/voter.py (original)
+++ steve/trunk/pysteve/lib/voter.py Sun Mar 27 17:03:19 2016
@@ -51,6 +51,13 @@ def hasVoted(election, issue, uid):
     issue = issue.strip(".json")
     return backend.voter_has_voted(election, issue, uid)
 
+def ballots():
+    try:
+        from lib import gateway
+        uid = gateway.uid()
+        return backend.voter_ballots(uid) if uid else {}
+    except:
+        return {}
 
 def email(rcpt, subject, message):
     sender = config.get("email", "sender")

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=1736776&r1=1736775&r2=1736776&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:03:19 2016
@@ -112,7 +112,9 @@ if pathinfo:
         else:
             response.respond(404, {'message': 'No election ID supplied'})
             
-            
+    elif action == "ballots":
+        # We defer to the gateway to provide us with UID here
+        response.respond(200, voter.ballots())
             
     elif action == "vote" and electionID and issueID and voterID:
         try:


Reply via email to