Skip to content

Commit

Permalink
New features branch (#252)
Browse files Browse the repository at this point in the history
* Prevent participants from skipping saftey video

* Added user certifications

* Add certification check to tools checkout

* Only show certifications required by tool type if they exist

* Added cancan checks around certification creation and deletion

* Added wristband field to participant view to help with wristband distribution #220

* Added digital signature to waiver #173

* Cleaned waiver code

* Changed store items price datatype to support fractional prices #168

* Added rake db:migrate to travis script so it can build with migrations

* Added rake db:migrate to travis script so it can build with migrations

* Fixing style on PR #248

* Removing nil check for PR #248

* Changed error message after skipping the saftey video

* Using migration technique from http://stackoverflow.com/questions/17150529

* Reverting to previous 9V battery price

* Fixing spelling of 'safety'

* Define wristband colors as constants

* Added load_and_authorize_resource to CertificationsController

* Changed building_status to is_building in db seeds file

* Fixed waiver playing in bg for admin and allow admin to skip video

* Added scissor lift wristband color

* Updated safety video

* Cleaned up waiver code and let user skip waiver on error from previous error

* Fixed ForbiddenAttribute error on certification creation

* Fixed messed up sidebar on SCC member new waiver
  • Loading branch information
sclark authored and blinblinblin committed Apr 10, 2017
1 parent 8dc4dc7 commit 0e283d1
Show file tree
Hide file tree
Showing 34 changed files with 450 additions and 115 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ rvm:
bundler_args: --without development staging production
sudo: false
before_script:
- bundle exec rake db:test:prepare
- bundle exec rake test:prepare
- bundle exec rake db:migrate
- export TZ='America/New_York'
44 changes: 44 additions & 0 deletions app/controllers/certifications_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class CertificationsController < ApplicationController
load_and_authorize_resource

before_action :set_participant, only: [:new, :create]
before_action :set_certification, only: [:destroy]
before_action :check_all_certifications, except: [:destroy]

def new
@certification = Certification.new(:participant => @participant)
respond_with @certification
end

def create
@certification = Certification.new(certification_params)
@certification.participant = @participant
@certification.save
respond_with @certification, location: -> { @certification.participant }
end

def destroy
@certification.destroy
respond_with @certification, location: -> { @certification.participant }
end

private
def set_participant
@participant = Participant.find(params[:participant_id])
end

def set_certification
@certification = Certification.find(params[:id])
end

def check_all_certifications
if @participant.certifications.size == CertificationType.all.size
redirect_to (participant_path @participant), :flash => { :error => @participant.name + " has already gotten all certifications." }
end
end

def certification_params
params.require(:certification).permit(:participant_id, :certification_type_id)
end

end
25 changes: 23 additions & 2 deletions app/controllers/participants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# **`phone_number`** | `string(255)` |
# **`updated_at`** | `datetime` |
# **`user_id`** | `integer` |
# **`waiver_start`** | `datetime` |
#
# ### Indexes
#
Expand All @@ -31,7 +32,8 @@
class ParticipantsController < ApplicationController
load_and_authorize_resource skip_load_resource only: [:create]
before_action :set_participant, only: [:show, :edit, :update, :destroy]

before_action :set_wristband_colors

# GET /participants
# GET /participants.json
def index
Expand Down Expand Up @@ -64,6 +66,22 @@ def lookup
# GET /participants/1.json
def show
@memberships = @participant.memberships.all

building_statuses = @memberships.map { |m| m.organization.organization_category.is_building }
is_building = building_statuses.include?(true)
if @memberships.empty?
@wristband = "None - No organizations"
elsif !@participant.has_signed_waiver
@wristband = "None - No waiver signature"
elsif is_building
@wristband = @wristband_colors[:building]
else
@wristband = @wristband_colors[:nonbuilding]
end

if @participant.certs.include?(CertificationType.find_by_name("Scissor Lift"))
@wristband += " and Green"
end
end

# GET /participants/new
Expand Down Expand Up @@ -110,5 +128,8 @@ def participant_create_params
def participant_update_params
params.require(:participant).permit(:phone_number, :has_signed_waiver, :has_signed_hardhat_waiver)
end
end

def set_wristband_colors
@wristband_colors = { :building => "Red", :nonbuilding => "Blue" }
end
end
12 changes: 12 additions & 0 deletions app/controllers/tool_cart_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ def checkout
locals: {message: "Invalid organization"}
end

participant_certs = participant.certifications.map { |cert| cert.certification_type.name }
session[:tool_cart].each do |tool|
tool = Tool.find_by_barcode(tool)
required_certs = tool.tool_type.tool_type_certifications.map { |cert| cert.certification_type.name }
required_certs.each do |required_cert|
if !participant_certs.include?(required_cert)
return render action: 'tool_cart_error',
locals: {message: "#{required_cert} certification required for #{tool.name} tool!"}
end
end
end

# Add membership
if params[:add_membership]
Membership.create({participant_id: params[:participant_id], organization_id: params[:organization_id]})
Expand Down
23 changes: 16 additions & 7 deletions app/controllers/waivers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
class WaiversController < ApplicationController
before_filter :require_authenticated_user

def new
if params[:participant_id].nil? or !current_user.participant.is_scc?
@user = current_user.participant
else
@user = Participant.find params[:participant_id]
end

if @user.has_signed_waiver
flash[:notice] = "You have already agreed to the release."
elsif !flash[:error]
@user.start_waiver_timer
end


@should_see_video = !flash[:error] && cannot?(:skip_video, WaiversController)

end


Expand All @@ -21,16 +25,21 @@ def create
else
@participant = Participant.find params[:participant_id]
end


if params[:adult].blank?

if @participant.is_waiver_cheater? && cannot?(:skip_video, WaiversController)
@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 (<a target='_blank' href='mailto:[email protected]'>[email protected]</a>)."
redirect_to action: :new
elsif params[:agree].blank?
flash[:error] = "You must agree to the terms of the release."
redirect_to action: :new
elsif params[:phone_number] == ""
flash[:error] = "You must provide a mobile phone number"
flash[:error] = "You must provide a mobile phone number."
redirect_to action: :new
elsif params[:signature] != @participant.name
flash[:error] = "You must electronically sign the waiver with your full name as it appears on the waiver."
redirect_to action: :new
else
@participant.phone_number = params[:phone_number]
Expand Down
6 changes: 4 additions & 2 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ def initialize(user)
user ||= User.new # guest user (not logged in)

cannot :manage, :all

if (user.participant.blank?)
return
end

can :read, [OrganizationAlias, OrganizationCategory, Organization, Participant,
can :read, [OrganizationAlias, OrganizationCategory, Organization, Participant,
ShiftType, Tool, ToolWaitlist, Membership]

can :search
Expand Down Expand Up @@ -90,10 +90,12 @@ def initialize(user)
can [:create, :update], Tool
can [:create, :update], ToolType
can [:create, :update , :destroy], ToolWaitlist
can [:create, :destroy], Certification
end

if user.has_role? :admin
can :manage, :all
can :skip_video, WaiversController
end
end
end
4 changes: 4 additions & 0 deletions app/models/certification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Certification < ActiveRecord::Base
belongs_to :certification_type
belongs_to :participant
end
3 changes: 3 additions & 0 deletions app/models/certification_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class CertificationType < ActiveRecord::Base
validates :name, :presence => true, :uniqueness => true
end
13 changes: 7 additions & 6 deletions app/models/organization_category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#
# ### Columns
#
# Name | Type | Attributes
# ----------------- | ------------------ | ---------------------------
# **`created_at`** | `datetime` |
# **`id`** | `integer` | `not null, primary key`
# **`name`** | `string(255)` |
# **`updated_at`** | `datetime` |
# Name | Type | Attributes
# ---------------------- | ------------------ | ---------------------------
# **`building_status`** | `boolean` |
# **`created_at`** | `datetime` |
# **`id`** | `integer` | `not null, primary key`
# **`name`** | `string(255)` |
# **`updated_at`** | `datetime` |
#

class OrganizationCategory < ActiveRecord::Base
Expand Down
14 changes: 13 additions & 1 deletion app/models/participant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# **`phone_number`** | `string(255)` |
# **`updated_at`** | `datetime` |
# **`user_id`** | `integer` |
# **`waiver_start`** | `datetime` |
#
# ### Indexes
#
Expand All @@ -30,17 +31,19 @@

class Participant < ActiveRecord::Base
before_save :reformat_phone

validates :andrewid, :presence => true, :uniqueness => true
# validates :has_signed_waiver, :acceptance => {:accept => true}
validates_format_of :phone_number, :with => /\A\(?\d{3}\)?[-. ]?\d{3}[-.]?\d{4}\Z/, :message => "should be 10 digits (area code needed) and delimited with dashes only", :allow_blank => true

has_many :organizations, :through => :memberships
has_many :shifts, :through => :shift_participants
has_many :certs, :through => :certifications, source: :participant
has_many :checkouts, dependent: :destroy
has_many :tools, :through => :checkouts
has_many :memberships, dependent: :destroy
has_many :shift_participants, dependent: :destroy
has_many :certifications, dependent: :destroy
has_many :organization_statuses, dependent: :destroy
has_many :events
belongs_to :phone_carrier
Expand All @@ -51,6 +54,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) > DateTime.now
end

def is_booth_chair?
!memberships.booth_chairs.blank?
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/store_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# **`created_at`** | `datetime` | `not null`
# **`id`** | `integer` | `not null, primary key`
# **`name`** | `string(255)` |
# **`price`** | `decimal(10, )` |
# **`price`** | `decimal(8, 2)` |
# **`quantity`** | `integer` |
# **`updated_at`** | `datetime` | `not null`
#
Expand Down
2 changes: 1 addition & 1 deletion app/models/store_purchase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# **`charge_id`** | `integer` |
# **`created_at`** | `datetime` | `not null`
# **`id`** | `integer` | `not null, primary key`
# **`price_at_purchase`** | `decimal(10, )` |
# **`price_at_purchase`** | `decimal(8, 2)` |
# **`quantity_purchased`** | `integer` |
# **`store_item_id`** | `integer` |
# **`updated_at`** | `datetime` | `not null`
Expand Down
2 changes: 2 additions & 0 deletions app/models/tool_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
class ToolType < ActiveRecord::Base
has_many :tools
has_many :tool_waitlists, dependent: :destroy
has_many :certs, :through => :tool_type_certifications, source: :tool_type
has_many :tool_type_certifications, dependent: :destroy
validates :name, presence: true, uniqueness: true

default_scope {order(:name)}
Expand Down
26 changes: 26 additions & 0 deletions app/models/tool_type_certification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ## Schema Information
#
# Table name: `tool_type_certifications`
#
# ### Columns
#
# Name | Type | Attributes
# ---------------------------- | ------------------ | ---------------------------
# **`certification_type_id`** | `integer` |
# **`created_at`** | `datetime` | `not null`
# **`id`** | `integer` | `not null, primary key`
# **`tool_type_id`** | `integer` |
# **`updated_at`** | `datetime` | `not null`
#
# ### Indexes
#
# * `index_tool_type_certifications_on_certification_type_id`:
# * **`certification_type_id`**
# * `index_tool_type_certifications_on_tool_type_id`:
# * **`tool_type_id`**
#

class ToolTypeCertification < ActiveRecord::Base
belongs_to :tool_type
belongs_to :certification_type
end
18 changes: 18 additions & 0 deletions app/views/certifications/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<% current_certs = @participant.certifications.map { |cert| cert.certification_type.name } %>

<%= simple_form_for [@participant, @certification], :html => { :class => 'form-horizontal' } do |f| %>
<div class="form-inputs">
<div class = "row">
<div class = "col-md-8" style="margin-left:73px">
</div>
</div>
<%= f.association :certification_type, collection: CertificationType.all.select { |c| !current_certs.include?(c.name) }, style: "margin-left:80px" %>
<%= f.input :participant_id, :as => :hidden %>
</div>

<div class="form-actions">
<%= f.button :submit, :class => 'btn-primary' %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
@participant, :class => 'btn btn-default' %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/certifications/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%- model_class = Certification -%>
<div class="page-header">
<h1>Add Certification for <%= @participant.name %></h1>
</div>

<%= render 'form' %>
Loading

0 comments on commit 0e283d1

Please sign in to comment.