diff --git a/app/controllers/waivers_controller.rb b/app/controllers/waivers_controller.rb index cc3eff5b..6fbf4f0a 100644 --- a/app/controllers/waivers_controller.rb +++ b/app/controllers/waivers_controller.rb @@ -10,6 +10,8 @@ def new if @user.has_signed_waiver flash[:notice] = "You have already agreed to the release." + else + @user.start_waiver_timer end end @@ -21,9 +23,11 @@ def create else @participant = Participant.find params[:participant_id] end - - - if params[:adult].blank? + + if @participant.is_waiver_cheater? + @participant.start_waiver_timer + redirect_to '/cheating.html' + elsif params[:adult].blank? flash[:error] = "You must be 18 or older to sign the electronic waiver. Please contact Andrew Greenwald (asgreen@andrew.cmu.edu)." redirect_to action: :new elsif params[:agree].blank? diff --git a/app/models/participant.rb b/app/models/participant.rb index bdc4d3f5..92a3c77f 100644 --- a/app/models/participant.rb +++ b/app/models/participant.rb @@ -21,6 +21,7 @@ # **`phone_number`** | `string(255)` | # **`updated_at`** | `datetime` | # **`user_id`** | `integer` | +# **`waiver_start`** | `datetime` | # # ### Indexes # @@ -49,6 +50,15 @@ class Participant < ActiveRecord::Base scope :search, lambda { |term| where('lower(andrewid) LIKE lower(?) OR lower(cached_name) LIKE lower(?)', "%#{term}%", "%#{term}%") } scope :scc, -> { joins(:organizations).where(organizations: {name: 'Spring Carnival Committee'}) } + def start_waiver_timer + self.waiver_start = DateTime.now + self.save + end + + def is_waiver_cheater? + (self.waiver_start + 3.minutes + 37.seconds) > DateTime.now + end + def is_booth_chair? !memberships.booth_chairs.blank? end diff --git a/db/migrate/20170305040259_add_waiver_start_to_participant.rb b/db/migrate/20170305040259_add_waiver_start_to_participant.rb new file mode 100644 index 00000000..46f785d0 --- /dev/null +++ b/db/migrate/20170305040259_add_waiver_start_to_participant.rb @@ -0,0 +1,5 @@ +class AddWaiverStartToParticipant < ActiveRecord::Migration + def change + add_column :participants, :waiver_start, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 7746d390..d1008223 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160404161512) do +ActiveRecord::Schema.define(version: 20170305040259) do create_table "charge_types", force: :cascade do |t| t.string "name" @@ -196,6 +196,7 @@ t.string "cached_department" t.string "cached_student_class" t.datetime "cache_updated" + t.datetime "waiver_start" t.integer "phone_carrier_id" end diff --git a/public/cheating.html b/public/cheating.html new file mode 100644 index 00000000..4142d913 --- /dev/null +++ b/public/cheating.html @@ -0,0 +1,34 @@ + + + + You tried to do something suspicious + + + + + +
+

You tried to do skip the safety videos

+

Please watch the entire safety video before completing the waiver!

+
+
+ +
+ + diff --git a/public/images/spy.jpg b/public/images/spy.jpg new file mode 100644 index 00000000..ddac8118 Binary files /dev/null and b/public/images/spy.jpg differ diff --git a/test/factories.rb b/test/factories.rb index 344b61f2..bb376658 100644 --- a/test/factories.rb +++ b/test/factories.rb @@ -108,6 +108,7 @@ # participant factory :participant, :aliases => [:completed_by, :issuing_participant, :receiving_participant] do andrewid { generate(:random_string) } + waiver_start DateTime.now end # shift diff --git a/test/unit/participant_test.rb b/test/unit/participant_test.rb index d472dcb0..6e605545 100644 --- a/test/unit/participant_test.rb +++ b/test/unit/participant_test.rb @@ -21,6 +21,7 @@ # **`phone_number`** | `string(255)` | # **`updated_at`** | `datetime` | # **`user_id`** | `integer` | +# **`waiver_start`** | `datetime` | # # ### Indexes # @@ -45,7 +46,7 @@ class ParticipantTest < ActiveSupport::TestCase context "With a proper context, " do setup do - @participant = FactoryGirl.create(:participant, :phone_number => 1234567890, :andrewid => "agoradia", :cached_name => "Akshay Goradia",) + @participant = FactoryGirl.create(:participant, :phone_number => 1234567890, :andrewid => "agoradia", :cached_name => "Akshay Goradia", :waiver_start => DateTime.now - 10.minutes) @organization_category = FactoryGirl.create(:organization_category) @organization = FactoryGirl.create(:organization, :name => "Spring Carnival Committee", :organization_category => @organization_category) @temp_participant = FactoryGirl.create(:participant) @@ -111,6 +112,12 @@ class ParticipantTest < ActiveSupport::TestCase assert_equal "N/A", @temp_participant.formatted_phone_number end + should "correctly determine if participant skipped video" do + assert_equal false, @participant.is_waiver_cheater? + + assert_equal true, @temp_participant.is_waiver_cheater? + end + should "show that is_booth_chair method works correctly" do assert_equal true, @participant.is_booth_chair? end