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 2015/03/19 13:08:13 UTC

svn commit: r1667716 - in /steve/trunk/pytest/www/cgi-bin: rest_admin.py rest_voter.py

Author: humbedooh
Date: Thu Mar 19 12:08:13 2015
New Revision: 1667716

URL: http://svn.apache.org/r1667716
Log:
admin additions:
 - Add secret hash (salt) for each new issue created
 - Allow issues to be deleted, via /steve/admin/delete/$election/$issue

voter additions:
 - Don't display the above-mentioned secret hash when displaying election data

Modified:
    steve/trunk/pytest/www/cgi-bin/rest_admin.py
    steve/trunk/pytest/www/cgi-bin/rest_voter.py

Modified: steve/trunk/pytest/www/cgi-bin/rest_admin.py
URL: http://svn.apache.org/viewvc/steve/trunk/pytest/www/cgi-bin/rest_admin.py?rev=1667716&r1=1667715&r2=1667716&view=diff
==============================================================================
--- steve/trunk/pytest/www/cgi-bin/rest_admin.py (original)
+++ steve/trunk/pytest/www/cgi-bin/rest_admin.py Thu Mar 19 12:08:13 2015
@@ -32,7 +32,6 @@ if 'SCRIPT_FILENAME' in os.environ:
     
 from lib import response
 
-
 # Fetch config (hack, hack, hack)
 config = configparser.RawConfigParser()
 config.read(path + '/../../steve.cfg')
@@ -79,10 +78,11 @@ if pathinfo:
                                 'owner': form.getvalue('owner'),
                                 'monitors': form.getvalue('monitors').split(","),
                                 'starts': form.getvalue('starts'),
-                                'ends': form.getvalue('ends')
+                                'ends': form.getvalue('ends'),
+                                'hash': hashlib.sha512("%f-stv-%s" % (time.time(), os.environ['REMOTE_ADDR'])).hexdigest()
                             }))
                             f.close()
-                        response.respond(201, {'message': 'Created!'})
+                        response.respond(201, {'message': 'Created!', 'id': election})
                     except Exception as err:
                         response.respond(500, {'message': "Could not create election: %s" % err})
             else:
@@ -127,7 +127,7 @@ if pathinfo:
                                     'nominatedby': form.getvalue('nominatedby')
                                 }))
                                 f.close()
-                            response.respond(201, {'message': 'Created!'})
+                            response.respond(201, {'message': 'Created!', 'id': issue})
                         except Exception as err:
                             response.respond(500, {'message': "Could not create issue: %s" % err})
             else:
@@ -135,6 +135,30 @@ if pathinfo:
         else:
             response.respond(403, {'message': 'You do not have enough karma for this'})
     
+    # Delete an issue in an election
+    elif action == "delete":
+        if karma >= 4: # karma of 4 required to set up an issue for the election
+            if election:
+                issue = l[2] if len(l) > 2 else None
+                if not issue:
+                    response.respond(400, {'message': 'No issue ID specified'})
+                else:
+                    issuepath = os.path.join(homedir, "issues", election, issue)
+                    if os.path.isfile(issuepath + ".json"):
+                        try:
+                            os.unlink(issuepath + ".json")
+                            response.respond(200, {'message': "Issue deleted"})
+                        except Exception as err:
+                            response.respond(500, {'message': 'Could not delete issue: %s' % err})
+                    else:
+                        response.respond(404, {'message': "No such issue!"})
+            else:
+                response.respond(400, {'message': "No election specified!"})
+        else:
+            response.respond(403, {'message': 'You do not have enough karma for this'})
+    
+    
+    
     # Edit an issue or election
     elif action == "edit":
         issue = l[2] if len(l) > 2 else None

Modified: steve/trunk/pytest/www/cgi-bin/rest_voter.py
URL: http://svn.apache.org/viewvc/steve/trunk/pytest/www/cgi-bin/rest_voter.py?rev=1667716&r1=1667715&r2=1667716&view=diff
==============================================================================
--- steve/trunk/pytest/www/cgi-bin/rest_voter.py (original)
+++ steve/trunk/pytest/www/cgi-bin/rest_voter.py Thu Mar 19 12:08:13 2015
@@ -68,6 +68,8 @@ if pathinfo:
                 try:
                     with open(elpath + "/basedata.json", "r") as f:
                         basedata = json.loads(f.read())
+                        if 'hash' in basedata:
+                            del basedata['hash']
                         f.close()
                     issues = [ f for f in listdir(elpath) if os.path.isfile(os.path.join(elpath,f)) and f != "basedata.json" ]
                     for issue in issues: