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/72f9ebdf809bab527233cd1e8c34=
be878f989b04
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 =3D f.read.chomp.to_s
if not results.has_key?(value)
- results[value] =3D 1
+ results[value] =3D { "votes" =3D> 1, "hashes" =3D> [file=
name] }
else
- results[value] =3D results[value] + 1
+ results[value]["votes"] =3D results[value]["votes"] + 1
+ results[value]["hashes"] =3D results[value]["hashes"] <<=
filename
end
}
}
@@ -311,7 +312,6 @@ class Ballot < Sinatra::Base
end
end
=
- puts "mail will be sent to #{mailaddrs}"
mailtext =3D ""
subject =3D ""
if type.to_s =3D=3D "invite"
@@ -332,6 +332,17 @@ class Ballot < Sinatra::Base
mailtext =3D mailtext.sub("__VOTEURL__", $siteurl)
mailtext =3D mailtext.sub("__VOTEEXPIRATION__", Time.at($votedata=
[votename]["expiration"]).to_s)
=
+ if type.to_s =3D=3D "results" and $votedata[votename].has_key?("e=
xtra-result-mails")
+ extramailaddrs =3D []
+ $votedata[votename]["extra-result-mails"].each { |addr|
+ extramailaddrs << addr
+ mailaddrs << addr
+ }
+ mailtext =3D mailtext.sub("__VOTEEXTRAMAILS__", "\nThis vote r=
esult is also being sent to #{extramailaddrs.to_s} for record-keeping purpo=
ses.\n")
+ else
+ mailtext =3D mailtext.sub("__VOTEEXTRAMAILS__", "\n")
+ end
+
if type.to_s =3D=3D "results" and $votedata[votename]["votetype"]=
=3D=3D "ev-membership"
resultstext =3D ""
# check yes, no, abstain, and quorum
@@ -342,10 +353,11 @@ class Ballot < Sinatra::Base
return
end
}
+
availablevotes =3D mailaddrs.size
- yes =3D (results.has_key?("yes") && results["yes"]) || 0
- no =3D (results.has_key?("no") && results["no"]) || 0
- abstain =3D (results.has_key?("abstain") && results["abstain"]=
) || 0
+ yes =3D (results.has_key?("yes") && results["yes"]["votes"]) |=
| 0
+ no =3D (results.has_key?("no") && results["no"]["votes"]) || 0
+ abstain =3D (results.has_key?("abstain") && results["abstain"]=
["votes"]) || 0
totalvotes =3D yes + no + abstain
quorum =3D (availablevotes*0.2).floor
resultstext +=3D "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 +=3D "Number of \"No\" votes: " + no.to_s + " (#{(=
no * 100 / (totalvotes*1.0)).round(2)}%)\n"
resultstext +=3D "Number of \"Abstain\" votes: " + abstain.to_=
s + " (#{(abstain * 100 / (totalvotes*1.0)).round(2)}%)\n"
resultstext +=3D "Yes/No votes needed for quorum: " + quorum.t=
o_s + " (got #{yes + no})\n"
- resultstext +=3D "Vote valid: " + ((((yes + no) > quorum) && "=
Yes") || "No")
+ resultstext +=3D "Vote valid: " + ((((yes + no) > quorum) && "=
Yes") || "No") + "\n"
+
mailtext =3D mailtext.sub("__VOTERESULTS__", resultstext)
+
+ hashestext =3D "\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 +=3D " and your secret key.\n\n"
+ else
+ hashestext +=3D ", your secret key, and the vote salt, whic=
h is (without the quotes, and without any newlines): \"#{$votedata[votename=
]["votehashsalt"]}\".\n\n"
+ end
+
+ results.keys.sort.each { |key|
+ hashestext +=3D "\n"
+ hashestext +=3D "#{key} (#{results[key]["votes"].to_s}):\n"
+ results[key]["hashes"].sort.each { |hash|
+ hashestext +=3D "\t#{hash}\n"
+ }
+ }
+
+ mailtext =3D 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 =3D Digest::SHA2.new(256)
usersha << givenname
- usersha << @votedata["userhashkey"]
+ usersha << @votedata["userhashsalt"]
if File.exists?(usersdir + "/users/" + usersha.to_s)
@status =3D "returnvoter"
end
@@ -801,10 +832,12 @@ class Ballot < Sinatra::Base
# otherwise their given key must match the current filename in or=
der to change it
usersha =3D Digest::SHA2.new(256)
usersha << givenname
- usersha << @votedata["userhashkey"]
+ usersha << @votedata["userhashsalt"]
votesha =3D Digest::SHA2.new(256)
votesha << givenname
votesha << @userkey
+ votesha << @votedata["votehashsalt"]
+ @uservotesha =3D votesha.to_s
if not File.exists?(usersdir + "/users/" + usersha.to_s)
userfile =3D 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: <%=3D@votedata["description"]%>
<% elsif @status =3D=3D "voted" and @scramblevalues =3D=3D nil %>
You selected <%=3D@votedata["choices"][@votevalue]=
%>.
You can change your vote. Once you exit this page you will have to provide your exact unique=
key to change your vote!
<% elsif @status =3D=3D "voted" %>
- This vote has scrambling enabled for extra securit=
y; your vote has been recorded but cannot be displayed back to you.<=
br />
You can change your vote. Once you =
exit this page you will have to provide your exact unique key to cha=
nge your vote!
+ This vote has scrambling enabled for extra securit=
y; your vote has been recorded but cannot be displayed back to you.<=
br />
You can change your vote. Once you =
exit this page you will have to provide your exact unique key to cha=
nge your vote!
Your ticket is: <%=3D@uservot=
esha%>. You can use this to verify your choice in the results. You c=
an also peform manual verification by creating a SHA256 sum of your usernam=
e, your secret key, and this vote's salt, which is (without the quotes): "<=
font color=3D"red"><%=3D@votedata["votehashsalt"]%>"
<% elsif @status =3D=3D "failedchange" %>
Could not change your vote; the unique key was not =
correct.
<% elsif @status =3D=3D "newvoter" %>