Permalink
Browse files

Encrypting ballots upon saving

  • Loading branch information...
1 parent f71de62 commit 3f6bb58dca84620a4d095ca803277b602386c26b @alg alg committed Sep 1, 2010
View
@@ -9,6 +9,7 @@ gem 'mysql'
gem 'hoptoad_notifier'
gem 'simple_form', '1.0.2'
gem 'RedCloth'
+gem 'paperclip'
group :development do
gem 'mongrel'
View
@@ -4,15 +4,15 @@ dependencies:
group:
- :test
version: ">= 0"
- compass-colors:
+ fancy-buttons:
group:
- :default
version: ">= 0"
compass:
group:
- :default
version: ">= 0"
- fancy-buttons:
+ compass-colors:
group:
- :default
version: ">= 0"
@@ -24,11 +24,11 @@ dependencies:
group:
- :default
version: = 2.3.8
- mysql:
+ haml:
group:
- :default
version: ">= 0"
- haml:
+ mysql:
group:
- :default
version: ">= 0"
@@ -52,6 +52,10 @@ dependencies:
group:
- :default
version: = 1.0.2
+ paperclip:
+ group:
+ - :default
+ version: ">= 0"
mocha:
group:
- :test
@@ -86,9 +90,9 @@ specs:
- cgi_multipart_eof_fix:
version: 2.5.0
- haml:
- version: 3.0.17
+ version: 3.0.18
- compass:
- version: 0.10.4
+ version: 0.10.5
- compass-colors:
version: 0.3.1
- daemons:
@@ -104,13 +108,15 @@ specs:
- gem_plugin:
version: 0.2.3
- hoptoad_notifier:
- version: 2.3.5
+ version: 2.3.6
- mocha:
version: 0.9.8
- mongrel:
version: 1.1.5
- mysql:
version: 2.8.1
+- paperclip:
+ version: 2.3.3
- rails:
version: 2.3.8
- rspec:
@@ -121,7 +127,7 @@ specs:
version: 1.0.2
- timecop:
version: 0.3.5
-hash: 219c98b827f6ccb7bd36a569668e4c6b57746561
+hash: 6e649f616b24e51d7c27f62ff1427147b27f2108
sources:
- Rubygems:
uri: http://gemcutter.org
@@ -23,7 +23,11 @@ def complete
end
def return
- redirect_to thanks_url if request.post?
+ if request.post? && save_ballot
+ redirect_to thanks_url
+ else
+ render :return
+ end
end
def thanks
@@ -55,5 +59,9 @@ def load_registration
@registration = Registration.find(session[:rid])
end
end
-
+
+ def save_ballot
+ @ballot = @registration.build_ballot(:pdf => params[:pdf])
+ @ballot.save
+ end
end
View
@@ -4,12 +4,12 @@ class Ballot < ActiveRecord::Base
belongs_to :registration
- has_attached_file :pdf, :path => ':rails_root/ballots/:id',
+ has_attached_file :pdf, :path => ':rails_root/ballots/:id.pdf.gpg',
:url => '/', # Disallow external access
- :styles => { :pdf => {} },
+ :styles => { :encrypt => AppConfig['gpg_recipient'] },
:processors => [ :encrypt ]
- validates :registration_id, :presence => true, :on => :create
+ validates_presence_of :registration_id, :on => :create
validates_attachment_presence :pdf
validates_attachment_content_type :pdf, :content_type => "application/pdf"
@@ -20,7 +20,7 @@ class Ballot < ActiveRecord::Base
def validate_pdf
if registration
filename = registration.blank_ballot.original_filename
- self.errors[:base] << ERROR_NAME if self.pdf.original_filename != filename
+ self.errors.add_to_base(ERROR_NAME) if self.pdf.original_filename != filename
end
end
@@ -4,6 +4,6 @@ class PrecinctSplit < ActiveRecord::Base
has_one :ballot_style
has_many :registrations
- validates :precinct_id, :presence => true
+ validates_presence_of :precinct_id
end
View
@@ -2,7 +2,11 @@
class Registration < ActiveRecord::Base
- validates_presence_of :pin_hash
+ belongs_to :precinct_split
+ has_one :ballot
+
+ validates_presence_of :pin_hash
+ validates_presence_of :precinct_split_id
def self.match(r)
first(:conditions => {
@@ -16,4 +20,9 @@ def pin=(v)
self.pin_hash = Digest::SHA1.hexdigest(v)
end
+ # Returns the blank ballot PDF
+ def blank_ballot
+ precinct_split.try(:ballot_style).try(:pdf)
+ end
+
end
@@ -18,7 +18,7 @@
/[if IE 6]
= javascript_include_tag 'plugins/unitpngfix'
- = javascript_include_tag 'jquery-1.4.2.min', 'plugins/jquery.textPlaceholder', 'plugins/jquery.tipTip.minified', 'application', :cache => true
+ = javascript_include_tag 'jquery-1.4.1.min', 'jquery.rails', 'plugins/jquery.textPlaceholder', 'plugins/jquery.tipTip.minified', 'application', :cache => true
%body{ :class => "#{controller.controller_path.gsub('/', ' ')} #{params[:action]}" }
.container
@@ -7,7 +7,7 @@
= render :partial => "shared/key_dates"
#area.nopadding
- = step_section(:step => 1, :icon => "open_ballot.gif", :icon_link => '#')
+ = step_section(:step => 1, :icon => "open_ballot.gif", :icon_link => @registration.blank_ballot.url)
= step_section(:step => 2, :icon => "mark.gif")
= step_section(:step => 3, :icon => "save.gif")
- if physical?
@@ -25,18 +25,27 @@
.box.wide
- form_tag return_path, :multipart => true, :id => "send_form" do
%h4= tt ".step_1.prompt"
- = file_field_tag "ballot"
+ = file_field_tag "pdf"
+ - if @ballot && !@ballot.valid?
+ .box.wide
+ Unable to save your ballot:
+ %ul
+ - @ballot.errors.full_messages.each do |m|
+ %li= m
#navigation
= link_to "Back", complete_path, :class => "button"
- = link_to_function "Continue", "if ($('#ballot').val() != '') $('#send_form').submit()", :class => "disabled button", :id => "continue"
+ - if physical?
+ = link_to "Continue", thanks_path, :class => "button"
+ - if digital?
+ = link_to_function "Continue", "if ($('#ballot').val() != '') $('#send_form').submit()", :class => "disabled button", :id => "continue"
-:javascript
- $(function() {
- var docs = $("#continue");
- $("#ballot").change(function() {
- if (this.value != '') enableLink(docs); else disableLink(docs);
- });
- disableLink(docs);
- });
+ :javascript
+ $(function() {
+ var docs = $("#continue");
+ $("#pdf").change(function() {
+ if (this.value != '') enableLink(docs); else disableLink(docs);
+ });
+ disableLink(docs);
+ });
View
@@ -2,5 +2,9 @@ app_name: Voter
from_email: support@voter.com
domain: voter.com
+# The name of the GPG encryption recipient
+gpg_recipient:
+
development:
domain: localhost
+ gpg_recipient: spyromus@noizeramp.com
@@ -3,5 +3,5 @@
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
-# You can also remove all the silencers if you're trying do debug a problem that might steem from framework code.
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
# Rails.backtrace_cleaner.remove_silencers!
View
@@ -1,15 +1,47 @@
-# This file is auto-generated from the current state of the database. Instead of editing this file,
-# please use the migrations feature of Active Record to incrementally modify your database, and
-# then regenerate this schema definition.
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
#
-# Note that this schema.rb definition is the authoritative source for your database schema. If you need
-# to create the application database on another system, you should be using db:schema:load, not running
-# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20100826071359) do
+ActiveRecord::Schema.define(:version => 20100830131721) do
+
+ create_table "ballot_styles", :force => true do |t|
+ t.integer "precinct_split_id", :null => false
+ t.string "pdf_file_name"
+ t.string "pdf_content_type"
+ t.integer "pdf_file_size"
+ t.datetime "pdf_updated_at"
+ end
+
+ add_index "ballot_styles", ["precinct_split_id"], :name => "index_ballot_styles_on_precinct_split_id", :unique => true
+
+ create_table "ballots", :force => true do |t|
+ t.integer "registration_id"
+ t.string "pdf_file_name"
+ t.string "pdf_content_type"
+ t.integer "pdf_file_size"
+ t.datetime "pdf_updated_at"
+ end
+
+ add_index "ballots", ["registration_id"], :name => "index_ballots_on_registration_id", :unique => true
+
+ create_table "precinct_splits", :force => true do |t|
+ t.integer "precinct_id"
+ t.string "name"
+ end
+
+ add_index "precinct_splits", ["precinct_id"], :name => "index_precinct_splits_on_precinct_id"
+
+ create_table "precincts", :force => true do |t|
+ t.string "name"
+ end
create_table "registrations", :force => true do |t|
t.string "name"
View
@@ -1,8 +1,23 @@
+# Create a precinct
+Precinct.destroy_all
+precinct = Precinct.create!(:name => "Test Precinct")
+
+# Create a split
+PrecinctSplit.destroy_all
+split = precinct.splits.create(:name => "Test Split")
+
+# Create a split ballot style
+BallotStyle.destroy_all
+ballot_style = split.create_ballot_style(:pdf => File.open("#{Rails.root}/db/fixtures/blank_ballot.pdf", "rb"))
+
+# Create a registration
+Registration.destroy_all
Registration.create!(
- :name => 'Mike',
- :pin => '1234',
- :zip => '24001',
- :voter_id => '1234',
- :address => "142 N Street",
- :city => "Washington",
- :state => "DC")
+ :precinct_split_id => split.id,
+ :name => 'Mike',
+ :pin => '1234',
+ :zip => '24001',
+ :voter_id => '1234',
+ :address => "142 N Street",
+ :city => "Washington",
+ :state => "DC")
@@ -3,14 +3,21 @@ class Encrypt < Processor
def initialize(file, options = {}, attachment = nil)
super
- @file = file
- @options = options
- @attachment = attachment
+ @file = file
+ @recipient = options[:geometry]
+ @attachment = attachment
+ @current_format = File.extname(@file.path)
+ @basename = File.basename(@file.path, @current_format)
end
def make
- # TODO: Use command line to encrypt the ballot
- @file
+ src = @file
+ dst = Tempfile.new([@basename, 'gpg'].compact.join("."))
+ dst.binmode
+
+ `gpg -o "#{File.expand_path(dst.path)}" -e -r "#{@recipient}" "#{File.expand_path(src.path)}"`
+
+ dst
end
end
end
Oops, something went wrong.

0 comments on commit 3f6bb58

Please sign in to comment.