Skip to content

Commit

Permalink
Started merging PendingVolunteer to Volunteer as Volunteer.needs_revi…
Browse files Browse the repository at this point in the history
…ew=true

 * Added Volunteer.needs_review
 * Updated the pending volunteer controller and the accompanying tests accordingly.  One test still failing.
 * Commented out the Pending* classes to find all relevant code that needs to be updated. This should leave the tables in the db.
  • Loading branch information
thebitguru committed Jan 16, 2017
1 parent ccd5d1a commit 799f890
Show file tree
Hide file tree
Showing 28 changed files with 210 additions and 105 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ group :development do

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'

gem 'railroady'
end

group :production do
gem 'heroku-deflater'
gem 'rails_12factor'
gem 'unicorn', '4.8.3'
end


8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ GEM
rack (1.6.5)
rack-test (0.6.3)
rack (>= 1.0)
railroady (1.5.2)
rails (4.2.0)
actionmailer (= 4.2.0)
actionpack (= 4.2.0)
Expand Down Expand Up @@ -201,6 +202,7 @@ DEPENDENCIES
paranoia (~> 2.0)
pg
possessive
railroady
rails (= 4.2.0)
rails_12factor
sass-rails (~> 5.0)
Expand All @@ -210,3 +212,9 @@ DEPENDENCIES
unicorn (= 4.8.3)
web-console (~> 2.0)
will_paginate (= 3.0.7)

RUBY VERSION
ruby 2.1.5p273

BUNDLED WITH
1.13.6
2 changes: 0 additions & 2 deletions app/assets/stylesheets/custom.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,3 @@ table.header-border {
.background-invalid {
background-color: LightPink !important;
}


42 changes: 26 additions & 16 deletions app/controllers/pending_volunteers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ class PendingVolunteersController < ApplicationController
before_action :logged_in_user, only: [:index, :update, :match, :edit, :destroy]

def new
@object = PendingVolunteer.new
@object = Volunteer.pending.new()
session[:referer] = request.referer
@submit_name = "Submit"
render 'new'
end

def edit
@object = PendingVolunteer.find(params[:id])
@object = Volunteer.pending.find(params[:id])
if params[:matching_id].blank?
redirect_to root_path
else
Expand All @@ -23,16 +23,19 @@ def edit
end

def update
@object = PendingVolunteer.find(params[:id])
@object = Volunteer.pending.find(params[:id])
if params[:matching_id].blank?
redirect_to root_path
else
# Lookup the actual matching volunteer
@volunteer = Volunteer.find(params[:matching_id])
volunteer_params = {}

params[:pv_use_fields].each do |findex|
item = PendingVolunteer.resolve_fields_table.key(findex.to_i)
item = Volunteer.pending_volunteer_merge_fields_table.key(findex.to_i)
volunteer_params[item] = pending_volunteer_params[item]
end

if (params[:use_notes].downcase != "ignore")
if @volunteer.notes.blank? || (params[:use_notes].downcase == "replace")
volunteer_params[:notes] = pending_volunteer_params[:notes]
Expand All @@ -48,6 +51,7 @@ def update
end
end
end

interests = []
if (pending_volunteer_params[:interest_ids].length > 0) && (params[:use_interests].downcase != "ignore")
if (params[:use_interests].downcase == "add") && (!params[:volunteer_interest_ids].nil?)
Expand All @@ -59,9 +63,10 @@ def update

if @volunteer.update_attributes(volunteer_params)
flash[:success] = "Volunteer updated"
@object.resolved = true
@object.volunteer_id = @volunteer.id
@object.save!
@object.destroy
# @object.needs_review = false
# @object.volunteer_id = @volunteer.id
# @object.save!
redirect_to pending_volunteers_path
else
@volunteer.errors.each {|attr, error| @object.errors.add(attr, error)}
Expand All @@ -74,22 +79,24 @@ def update


def index
standard_index(PendingVolunteer.where(resolved: false), params[:page], false, "", nil, true)
standard_index(Volunteer.pending.all, params[:page], false, "", nil, true)
end

def match
@pending_volunteer = PendingVolunteer.find(params[:id])
@pending_volunteer = Volunteer.pending.find(params[:id])
@matched_volunteers = find_matching_volunteers(@pending_volunteer)
end

def destroy
PendingVolunteer.find(params[:id]).destroy
Volunteer.pending.find(params[:id]).really_destroy!
flash[:success] = "Pending Volunteer discarded"
redirect_to pending_volunteers_path
end

def create
@object = PendingVolunteer.new(pending_volunteer_params)
@object = Volunteer.pending.new(pending_volunteer_params)
@object.needs_review = true
@object.work_phone = @object.mobile_phone = @object.home_phone
status = verify_google_recptcha(GOOGLE_SECRET_KEY,params["g-recaptcha-response"])
if status && @object.save # Order is important here!
render 'success'
Expand All @@ -109,12 +116,15 @@ def show
private

def pending_volunteer_params
modified_params = params.require(:pending_volunteer).permit(:first_name, :last_name, :address, :city, :state, :zip, :phone, :home_phone, :work_phone, :mobile_phone, :email, :notes, pv_int_ids: [], interest_ids: [] )
if (!modified_params[:pv_int_ids].nil?)
modified_params[:interest_ids] = modified_params[:pv_int_ids].dup
modified_params.delete(:pv_int_ids)
modified_params = params.require(:volunteer).permit(
:first_name, :last_name, :address, :city, :state, :zip, :home_phone, :work_phone,
:mobile_phone, :email, :notes, int_ids: [], interest_ids: []
)
if (!modified_params[:int_ids].nil?)
modified_params[:interest_ids] = modified_params[:int_ids].dup
modified_params.delete(:int_ids)
end
puts modified_params
# puts modified_params
modified_params
end

Expand Down
9 changes: 5 additions & 4 deletions app/controllers/volunteers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def new
@allow_stay = true
session[:volunteer_id] = @volunteer.id
if params[:pending_volunteer_id]
@pending_volunteer = PendingVolunteer.find(params[:pending_volunteer_id])
@pending_volunteer = Volunteer.pending.find(params[:pending_volunteer_id])
@volunteer.pending_volunteer_id = @pending_volunteer.id
["first_name", "last_name", "address", "city", "state", "zip", "phone", "notes", "interests"].each do |column|
if column == "phone"
Expand All @@ -251,11 +251,12 @@ def create
if @volunteer.save # Save successful
from_pending_volunteers = false
if @volunteer.pending_volunteer_id
pending_volunteer = PendingVolunteer.find(@volunteer.pending_volunteer_id)
if !pending_volunteer.resolved
pending_volunteer = Volunteer.pending.find(@volunteer.pending_volunteer_id)
# TODO: Confirm and test.
if !pending_volunteer.needs_review
from_pending_volunteers = true #If coming from an unresolved pending volunteer, need to go back to list
end
pending_volunteer.resolved = true
pending_volunteer.needs_review = true
pending_volunteer.save
end
session[:volunteer_id] = @volunteer.id
Expand Down
26 changes: 25 additions & 1 deletion app/controllers/workdays_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include ApplicationHelper

class WorkdaysController < ApplicationController
before_action :logged_in_user, only: [:index, :new, :edit, :update, :destroy, :search, :report, :add_participants, :workday_summary, :participant_report]
before_action :logged_in_user, only: [:index, :new, :edit, :update, :destroy, :search, :report, :add_participants, :confirm_launch_self_tracking, :launch_self_tracking, :workday_summary, :participant_report]
before_action :admin_user, only: [:import, :import_form]


Expand Down Expand Up @@ -279,6 +279,30 @@ def add_participants
@project = Project.find(@workday.project_id)
end

def confirm_launch_self_tracking
@workday = Workday.find(params[:id])
session[:workday_id] = @workday.id
@project = Project.find(@workday.project_id)
end

def launch_self_tracking
@workday = Workday.find(params[:id])
session[:workday_id] = @workday.id
@project = Project.find(@workday.project_id)

# Create a token for this session
new_token = "create_here"

# Logout the user
log_out

# Save the token in the session
session[:self_tracking_token] = new_token

# Redirect to the new self_tracking view
redirect_to("/")
end

def workday_summary
@objectName = params[:object_name].downcase
@objectId = params[:id]
Expand Down
2 changes: 0 additions & 2 deletions app/models/interest.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
class Interest < ActiveRecord::Base
has_many :volunteer_interests, dependent: :restrict_with_exception
has_many :volunteers, through: :volunteer_interests, dependent: :restrict_with_exception
has_many :pending_volunteer_interests, dependent: :restrict_with_exception
has_many :pending_volunteers, through: :pending_volunteer_interests, dependent: :restrict_with_exception
belongs_to :interest_category

validates :name, presence: true, uniqueness: {scope: :interest_category_id, message: "Duplicate name and category with another interest"}
Expand Down
72 changes: 36 additions & 36 deletions app/models/pending_volunteer.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
class PendingVolunteer < ActiveRecord::Base
has_many :pending_volunteer_interests, dependent: :destroy
has_many :interests, through: :pending_volunteer_interests
belongs_to :volunteers
has_one :volunteer

before_save :save_phone

validates :first_name, presence: true
validates :last_name, presence: true

def name
[first_name, last_name].join(' ')
end

def self.resolve_fields_table
resolve_fields = {}
index = 0
[:first_name, :last_name, :address, :city, :state, :zip, :email, :home_phone, :work_phone, :mobile_phone].each do |f|
resolve_fields[f] = index
index += 1
end
resolve_fields
end

private

def save_phone
if self.phone
self.home_phone = self.phone
self.work_phone = self.phone
self.mobile_phone = self.phone
end
end

end
# class PendingVolunteer < ActiveRecord::Base
# has_many :pending_volunteer_interests, dependent: :destroy
# has_many :interests, through: :pending_volunteer_interests
# belongs_to :volunteers
# has_one :volunteer
#
# before_save :save_phone
#
# validates :first_name, presence: true
# validates :last_name, presence: true
#
# def name
# [first_name, last_name].join(' ')
# end
#
# def self.resolve_fields_table
# resolve_fields = {}
# index = 0
# [:first_name, :last_name, :address, :city, :state, :zip, :email, :home_phone, :work_phone, :mobile_phone].each do |f|
# resolve_fields[f] = index
# index += 1
# end
# resolve_fields
# end
#
# private
#
# def save_phone
# if self.phone
# self.home_phone = self.phone
# self.work_phone = self.phone
# self.mobile_phone = self.phone
# end
# end
#
# end
8 changes: 4 additions & 4 deletions app/models/pending_volunteer_interest.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class PendingVolunteerInterest < ActiveRecord::Base
belongs_to :pending_volunteer
belongs_to :interest
end
# class PendingVolunteerInterest < ActiveRecord::Base
# belongs_to :pending_volunteer
# belongs_to :interest
# end
5 changes: 4 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ class User < ActiveRecord::Base
validates :name, presence: true
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false }
has_secure_password
validates :password, length: { minimum: Utilities::Utilities.system_setting(:min_password_length) }, allow_blank: true
# TODO: Hard coding this for now. Will have to figure out how to properly dynamiccally get this from the database.
# validates :password, length: { minimum: Utilities::Utilities.system_setting(:min_password_length) }, allow_blank: true
validates :password, length: { minimum: 6 }, allow_blank: true
# validates :password, length: { minimum: Utilities::Utilities.system_setting(:min_password_length) }, allow_blank: true
validate :only_one_donation_security_type

# Returns the hash digest of the given string.
Expand Down
19 changes: 17 additions & 2 deletions app/models/volunteer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ class Volunteer < ActiveRecord::Base
has_many :workday_volunteers, dependent: :destroy
has_many :workdays, through: :workday_volunteers
has_many :donations, dependent: :destroy
has_one :pending_volunteer
belongs_to :pending_volunteer
belongs_to :church, -> { where(:organization_type => 1) }, class_name: "Organization", foreign_key: :church_id
belongs_to :employer, class_name: "Organization", foreign_key: :employer_id
belongs_to :first_contact_type, class_name: "ContactType", foreign_key: :first_contact_type_id
has_many :volunteer_category_volunteers, dependent: :destroy
has_many :volunteer_categories, through: :volunteer_category_volunteers

default_scope { where(needs_review: false) }

def self.pending
Volunteer.unscoped.where(needs_review: true, deleted_at: nil)
end

accepts_nested_attributes_for :donations, :allow_destroy => true

Expand Down Expand Up @@ -50,4 +53,16 @@ def self.merge_fields_table
merge_fields
end

def self.pending_volunteer_merge_fields_table
resolve_fields = {}
index = 0
[:first_name, :last_name, :address, :city, :state, :zip, :email, :home_phone, :work_phone, :mobile_phone].each do |f|
resolve_fields[f] = index
index += 1
end
resolve_fields
end



end
4 changes: 2 additions & 2 deletions app/views/pending_volunteers/_edit_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_for(@object) do |f| %>
<%= form_for(@object, :url => pending_volunteer_path(@object)) do |f| %>
<%= @object = f.object
render 'shared/error_messages' %>

Expand Down Expand Up @@ -26,7 +26,7 @@
<%= f.text_field field, class: 'form-control' %>
</div>
<div class="col-xs-2">
<%= check_box_tag("pv_use_fields[]", PendingVolunteer.resolve_fields_table[field], !check_exceptions.include?(field) && !@object.send(field).blank?, {id: "use_#{field}", class: "form-control"}) %>
<%= check_box_tag("pv_use_fields[]", Volunteer.pending_volunteer_merge_fields_table[field], !check_exceptions.include?(field) && !@object.send(field).blank?, {id: "use_#{field}", class: "form-control"}) %>
</div>
<div class="col-xs-1">
<%= label_tag field %>
Expand Down
Loading

0 comments on commit 799f890

Please sign in to comment.