[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [websites/ballot-kde-org] /: Update results emails
From:       Jeff Mitchell <mitchell () kde ! org>
Date:       2011-10-31 20:59:19
Message-ID: 20111031205919.722A4A60A6 () git ! kde ! org
[Download RAW message or body]

Git commit 72f9ebdf809bab527233cd1e8c34be878f989b04 by Jeff Mitchell.
Committed on 31/10/2011 at 21:59.
Pushed by mitchell into branch 'master'.

Update results emails

M  +42   -9    ballot.rb
M  +1    -1    views/vote.erb

http://commits.kde.org/websites/ballot-kde-org/72f9ebdf809bab527233cd1e8c34be878f989b04


diff --git a/ballot.rb b/ballot.rb
index a1ffc3b..49fd02b 100755
--- a/ballot.rb
+++ b/ballot.rb
@@ -268,9 +268,10 @@ class Ballot < Sinatra::Base
             File.open("#{votedir}/#{filename}", "r") { |f|
                value = f.read.chomp.to_s
                if not results.has_key?(value)
-                  results[value] = 1
+                  results[value] = { "votes" => 1, "hashes" => [filename] \
}  else
-                  results[value] = results[value] + 1
+                  results[value]["votes"] = results[value]["votes"] + 1
+                  results[value]["hashes"] = results[value]["hashes"] << \
filename  end
             }
          }
@@ -311,7 +312,6 @@ class Ballot < Sinatra::Base
             end
          end
 
-         puts "mail will be sent to #{mailaddrs}"
          mailtext = ""
          subject = ""
          if type.to_s == "invite"
@@ -332,6 +332,17 @@ class Ballot < Sinatra::Base
          mailtext = mailtext.sub("__VOTEURL__", $siteurl)
          mailtext = mailtext.sub("__VOTEEXPIRATION__", \
Time.at($votedata[votename]["expiration"]).to_s)  
+         if type.to_s == "results" and \
$votedata[votename].has_key?("extra-result-mails") +            \
extramailaddrs = [] +            \
$votedata[votename]["extra-result-mails"].each { |addr| +               \
extramailaddrs << addr +               mailaddrs << addr
+            }
+            mailtext = mailtext.sub("__VOTEEXTRAMAILS__", "\nThis vote \
result is also being sent to #{extramailaddrs.to_s} for record-keeping \
purposes.\n") +         else
+            mailtext = mailtext.sub("__VOTEEXTRAMAILS__", "\n")
+         end
+
          if type.to_s == "results" and $votedata[votename]["votetype"] == \
"ev-membership"  resultstext = ""
             # check yes, no, abstain, and quorum
@@ -342,10 +353,11 @@ class Ballot < Sinatra::Base
                   return
                end
             }
+
             availablevotes = mailaddrs.size
-            yes = (results.has_key?("yes") && results["yes"]) || 0
-            no = (results.has_key?("no") && results["no"]) || 0
-            abstain = (results.has_key?("abstain") && results["abstain"]) \
|| 0 +            yes = (results.has_key?("yes") && \
results["yes"]["votes"]) || 0 +            no = (results.has_key?("no") && \
results["no"]["votes"]) || 0 +            abstain = \
(results.has_key?("abstain") && results["abstain"]["votes"]) || 0  \
totalvotes = yes + no + abstain  quorum = (availablevotes*0.2).floor
             resultstext += "Number of active members: " + \
availablevotes.to_s + " (#{totalvotes} voted, #{(totalvotes * 100 / \
(availablevotes*1.0)).round(2)}%)\n" @@ -353,10 +365,29 @@ class Ballot < \
                Sinatra::Base
             resultstext += "Number of \"No\" votes: " + no.to_s + " (#{(no \
                * 100 / (totalvotes*1.0)).round(2)}%)\n"
             resultstext += "Number of \"Abstain\" votes: " + abstain.to_s \
                + " (#{(abstain * 100 / (totalvotes*1.0)).round(2)}%)\n"
             resultstext += "Yes/No votes needed for quorum: " + \
                quorum.to_s + " (got #{yes + no})\n"
-            resultstext += "Vote valid: " + ((((yes + no) > quorum) && \
"Yes") || "No") +            resultstext += "Vote valid: " + ((((yes + no) \
> quorum) && "Yes") || "No") + "\n" +
             mailtext = mailtext.sub("__VOTERESULTS__", resultstext)
+
+            hashestext = "\nFollowing are the counted votes. If you did \
not mark down your ticket when you voted, you can recreate it by creating a \
SHA256 sum of your username" +            if \
$votedata[votename]["votehashsalt"].empty? +               hashestext += " \
and your secret key.\n\n" +            else
+               hashestext += ", your secret key, and the vote salt, which \
is (without the quotes, and without any newlines): \
\"#{$votedata[votename]["votehashsalt"]}\".\n\n" +            end
+
+            results.keys.sort.each { |key|
+               hashestext += "\n"
+               hashestext += "#{key} (#{results[key]["votes"].to_s}):\n"
+               results[key]["hashes"].sort.each { |hash|
+                  hashestext += "\t#{hash}\n"
+               }
+            }
+
+            mailtext = mailtext.sub("__VOTEHASHES__", hashestext)
          end
 
+         puts "mail will be sent to #{mailaddrs}"
          puts mailtext
 
          mailaddrs.each do |addr|
@@ -668,7 +699,7 @@ class Ballot < Sinatra::Base
 
       usersha = Digest::SHA2.new(256)
       usersha << givenname
-      usersha << @votedata["userhashkey"]
+      usersha << @votedata["userhashsalt"]
       if File.exists?(usersdir + "/users/" + usersha.to_s)
          @status = "returnvoter"
       end
@@ -801,10 +832,12 @@ class Ballot < Sinatra::Base
          # otherwise their given key must match the current filename in \
order to change it  usersha = Digest::SHA2.new(256)
          usersha << givenname
-         usersha << @votedata["userhashkey"]
+         usersha << @votedata["userhashsalt"]
          votesha = Digest::SHA2.new(256)
          votesha << givenname
          votesha << @userkey
+         votesha << @votedata["votehashsalt"]
+         @uservotesha = votesha.to_s
          if not File.exists?(usersdir + "/users/" + usersha.to_s)
             userfile = File.new(usersdir + "/users/" + usersha.to_s, "w", \
0600)  userfile.close
diff --git a/views/vote.erb b/views/vote.erb
index 974096a..7d8e96b 100644
--- a/views/vote.erb
+++ b/views/vote.erb
@@ -28,7 +28,7 @@ Vote Name: <%=@votedata["description"]%><br />
 <% elsif @status == "voted" and @scramblevalues == nil %>
    <font color="blue">You selected \
<%=@votedata["choices"][@votevalue]%>.</font><br /><br /><font \
color="green">You can change your vote.</font> Once you exit this page you \
will have to provide your <b>exact</b> unique key to change your vote!  <% \
                elsif @status == "voted" %>
-   <font color="blue">This vote has scrambling enabled for extra security; \
your vote has been recorded but cannot be displayed back to you.</font><br \
/><br /><font color="green">You can change your vote.</font> Once you exit \
this page you will have to provide your <b>exact</b> unique key to change \
your vote! +   <font color="blue">This vote has scrambling enabled for \
extra security; your vote has been recorded but cannot be displayed back to \
you.</font><br /><br /><font color="green">You can change your vote.</font> \
Once you exit this page you will have to provide your <b>exact</b> unique \
key to change your vote!<br /><br />Your ticket is: <font \
color="red"><%=@uservotesha%></font>. You can use this to verify your \
choice in the results. You can also peform manual verification by creating \
a SHA256 sum of your username, your secret key, and this vote's salt, which \
is (without the quotes): "<font \
color="red"><%=@votedata["votehashsalt"]%></font>"  <% elsif @status == \
"failedchange" %>  <font color="red">Could not change your vote; the unique \
key was not correct.</font>  <% elsif @status == "newvoter" %>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic