diff --git a/Gemfile b/Gemfile index 5effc0a..deadaea 100644 --- a/Gemfile +++ b/Gemfile @@ -76,6 +76,8 @@ 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 @@ -83,5 +85,3 @@ group :production do gem 'rails_12factor' gem 'unicorn', '4.8.3' end - - diff --git a/Gemfile.lock b/Gemfile.lock index e3179d3..1b2720b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -201,6 +202,7 @@ DEPENDENCIES paranoia (~> 2.0) pg possessive + railroady rails (= 4.2.0) rails_12factor sass-rails (~> 5.0) @@ -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 diff --git a/app/assets/stylesheets/custom.css.scss b/app/assets/stylesheets/custom.css.scss index c728cff..9b8c534 100644 --- a/app/assets/stylesheets/custom.css.scss +++ b/app/assets/stylesheets/custom.css.scss @@ -265,5 +265,3 @@ table.header-border { .background-invalid { background-color: LightPink !important; } - - diff --git a/app/controllers/pending_volunteers_controller.rb b/app/controllers/pending_volunteers_controller.rb index 84e3f64..320c446 100644 --- a/app/controllers/pending_volunteers_controller.rb +++ b/app/controllers/pending_volunteers_controller.rb @@ -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 @@ -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] @@ -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?) @@ -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)} @@ -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' @@ -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 diff --git a/app/controllers/volunteers_controller.rb b/app/controllers/volunteers_controller.rb index f4f01cf..79967e2 100644 --- a/app/controllers/volunteers_controller.rb +++ b/app/controllers/volunteers_controller.rb @@ -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" @@ -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 diff --git a/app/controllers/workdays_controller.rb b/app/controllers/workdays_controller.rb index 31960a3..1964da3 100644 --- a/app/controllers/workdays_controller.rb +++ b/app/controllers/workdays_controller.rb @@ -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] @@ -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] diff --git a/app/models/interest.rb b/app/models/interest.rb index a785317..e1a066f 100644 --- a/app/models/interest.rb +++ b/app/models/interest.rb @@ -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"} diff --git a/app/models/pending_volunteer.rb b/app/models/pending_volunteer.rb index 8d8bdf0..0feca98 100644 --- a/app/models/pending_volunteer.rb +++ b/app/models/pending_volunteer.rb @@ -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 diff --git a/app/models/pending_volunteer_interest.rb b/app/models/pending_volunteer_interest.rb index d4c04fc..c4f8058 100644 --- a/app/models/pending_volunteer_interest.rb +++ b/app/models/pending_volunteer_interest.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 399ee03..0022d47 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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. diff --git a/app/models/volunteer.rb b/app/models/volunteer.rb index 44f15c3..a8b7b69 100644 --- a/app/models/volunteer.rb +++ b/app/models/volunteer.rb @@ -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 @@ -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 diff --git a/app/views/pending_volunteers/_edit_form.html.erb b/app/views/pending_volunteers/_edit_form.html.erb index 2edaae7..7a167ea 100644 --- a/app/views/pending_volunteers/_edit_form.html.erb +++ b/app/views/pending_volunteers/_edit_form.html.erb @@ -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' %> @@ -26,7 +26,7 @@ <%= f.text_field field, class: 'form-control' %>
The self tracking functionality allows the volunteers to check themselves in and out. To secure the system your personal account will be logged out.
+ +For <%= @project.name %> - <%= @workday.name %> - <%= @workday.workdate.strftime("%A, %B %-d, %Y") %>
+ +<%= link_to({ :action => "launch_self_tracking" }, :class => "btn btn-primary") do %> + Launch... +<% end %> diff --git a/config/database.yml b/config/database.yml index 0d0affd..bd2c8d4 100644 --- a/config/database.yml +++ b/config/database.yml @@ -16,7 +16,8 @@ development: username: hfh_rol_dev password: ^nHYebFYbsd9 timeout: 5000 - host: postgresql-common + host: localhost + # host: postgresql-common # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". @@ -29,6 +30,7 @@ test: username: hfh_rol_test password: ^nHYebFYbsd9 timeout: 5000 + host: localhost # Production DB on WebFaction (Heroku handles through environment vars I think) diff --git a/config/environments/development.rb b/config/environments/development.rb index b55e214..347db45 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -19,6 +19,9 @@ # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log + #config.assets.js_compressor = :uglifier + config.assets.css_compressor = :sass + # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load diff --git a/config/routes.rb b/config/routes.rb index 41866b0..5913d79 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,6 +9,7 @@ delete 'logout' => 'sessions#destroy' resources :pending_volunteers do + post :edit, :update member do get 'match' end @@ -51,6 +52,8 @@ end member do get 'add_participants' + get 'confirm_launch_self_tracking' + get 'launch_self_tracking' end end diff --git a/db/migrate/20170116001609_add_needs_review_to_volunteer.rb b/db/migrate/20170116001609_add_needs_review_to_volunteer.rb new file mode 100644 index 0000000..564a6b9 --- /dev/null +++ b/db/migrate/20170116001609_add_needs_review_to_volunteer.rb @@ -0,0 +1,5 @@ +class AddNeedsReviewToVolunteer < ActiveRecord::Migration + def change + add_column :volunteers, :needs_review, :boolean, :default => false + end +end diff --git a/db/schema.rb b/db/schema.rb index 86e5cd5..7567ab2 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: 20161108052146) do +ActiveRecord::Schema.define(version: 20170116001609) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -224,6 +224,7 @@ t.integer "pending_volunteer_id" t.datetime "deleted_at" t.string "deleted_reason" + t.boolean "needs_review", default: false end add_index "volunteers", ["church_id"], name: "index_volunteers_on_church_id", using: :btree diff --git a/doc/models_complete.png b/doc/models_complete.png new file mode 100644 index 0000000..d3abd40 Binary files /dev/null and b/doc/models_complete.png differ diff --git a/docker-sync.yml b/docker-sync.yml index cf42c79..b0695c8 100644 --- a/docker-sync.yml +++ b/docker-sync.yml @@ -79,7 +79,7 @@ syncs: # this does not user groupmap but rather configures the server to map # sync_groupid: '6000' - watch_excludes: ['.*/.git', '.*/node_modules', '.*/bower_components', '.*/sass-cache', '.*/.sass-cache', '.*/.sass-cache', '.coffee', '.scss', '.sass', '.gitignore'] + watch_excludes: ['.*/.git', './tmp', '.*/node_modules', '.*/bower_components', '.*/sass-cache', '.*/.sass-cache', '.*/.sass-cache', '.coffee', '.scss', '.sass', '.gitignore'] # optional: use this to switch to fswatch verbose mode watch_args: '-v' diff --git a/farhan_notes.txt b/farhan_notes.txt new file mode 100644 index 0000000..386ccf4 --- /dev/null +++ b/farhan_notes.txt @@ -0,0 +1,17 @@ + +---------------- + +* Continue working on the PendingVolunteer merge. Test the Volunteer--Volunteer merge as well. +* Launch point on the "Add Participant" page on workday. +* Migration for converting the existing pending volunteers. +* Add waiver date to the grid. + + +TODO for later + * How to lookup the password min length from db for User class? See user model. + * Will new volunteers have a different set of interests? + * Is it OK to assume that all pending volunteers will be resolved when the upgrade is done? This way we don't have to worry about conversions. + * Delete Volunteer.pending_volunteer_id + + +* See if there is a different way to label the "use" fields on the merge screens (see resolve_fields_table). diff --git a/test/controllers/pending_volunteers_controller_test.rb b/test/controllers/pending_volunteers_controller_test.rb index 9731119..83e22fa 100644 --- a/test/controllers/pending_volunteers_controller_test.rb +++ b/test/controllers/pending_volunteers_controller_test.rb @@ -4,9 +4,9 @@ class PendingVolunteersControllerTest < ActionController::TestCase def setup @user = users(:one) - @pending_volunteer = pending_volunteers(:one) - @pending_volunteer2 = pending_volunteers(:two) - @pending_volunteer3 = pending_volunteers(:three) + @pending_volunteer = volunteers(:pending_one) + @pending_volunteer2 = volunteers(:pending_two) + @pending_volunteer3 = volunteers(:pending_three) @volunteer = Volunteer.new() @volunteer.first_name = @pending_volunteer.first_name + 'a' @volunteer.last_name = @pending_volunteer.last_name @@ -39,7 +39,7 @@ def teardown log_in_as(@user) get :index assert_template 'shared/simple_index' - pending_volunteers = PendingVolunteer.where(resolved: false) + pending_volunteers = Volunteer.pending.all pending_volunteers.each do |pending_volunteer| assert_select 'div[href=?]', match_pending_volunteer_path(pending_volunteer) end @@ -47,11 +47,11 @@ def teardown test "index display with nobody" do log_in_as(@user) - @pending_volunteer.resolved = true + @pending_volunteer.needs_review = false @pending_volunteer.save! - @pending_volunteer2.resolved = true + @pending_volunteer2.needs_review = false @pending_volunteer2.save! - @pending_volunteer3.resolved = true + @pending_volunteer3.needs_review = false @pending_volunteer3.save! get :index assert_template 'shared/simple_index' diff --git a/test/fixtures/pending_volunteers.yml b/test/fixtures/pending_volunteers.yml deleted file mode 100644 index 8f79e3a..0000000 --- a/test/fixtures/pending_volunteers.yml +++ /dev/null @@ -1,13 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html - -one: - first_name: Tim - last_name: Smith - -two: - first_name: Tom - last_name: Jones - -three: - first_name: Jane - last_name: Smith \ No newline at end of file diff --git a/test/fixtures/volunteers.yml b/test/fixtures/volunteers.yml index 284e769..13d82f4 100644 --- a/test/fixtures/volunteers.yml +++ b/test/fixtures/volunteers.yml @@ -81,3 +81,18 @@ master: work_phone: mobile_phone: notes: A bunch of notes + +pending_one: + first_name: Tim + last_name: Smith + needs_review: true + +pending_two: + first_name: Tom + last_name: Jones + needs_review: true + +pending_three: + first_name: Jane + last_name: Smith + needs_review: true diff --git a/test/integration/volunteers_edit_test.rb b/test/integration/volunteers_edit_test.rb index 44080c2..247cfd6 100644 --- a/test/integration/volunteers_edit_test.rb +++ b/test/integration/volunteers_edit_test.rb @@ -212,7 +212,7 @@ def teardown test "New volunteer from pending volunteer" do log_in_as(@user) - @pending_volunteer = pending_volunteers(:one) + @pending_volunteer = volunteers(:pending_one) get new_volunteer_path(pending_volunteer_id: @pending_volunteer) assert_template 'new' assert_select "[name*=first_name]" do @@ -222,7 +222,9 @@ def teardown post volunteers_path(@volunteer), volunteer: {first_name: @pending_volunteer.first_name, last_name: @pending_volunteer.last_name, pending_volunteer_id: @pending_volunteer.id} @pending_volunteer.reload - assert_equal(@pending_volunteer.resolved, true) + # TODO: I need to understand and fix this logic - Farhan + assert_equal(@pending_volunteer.needs_review, true) + assert_not_equal(@pending_volunteer.deleted_at, nil) end @@ -473,4 +475,4 @@ def teardown end -end \ No newline at end of file +end diff --git a/test/models/pending_volunteer_test.rb b/test/models/pending_volunteer_test.rb index ab4af53..419cc99 100644 --- a/test/models/pending_volunteer_test.rb +++ b/test/models/pending_volunteer_test.rb @@ -6,7 +6,7 @@ def setup end test "first and last name present" do - @pending_volunteer = PendingVolunteer.new + @pending_volunteer = Volunteer.pending.new @pending_volunteer.first_name = " " assert_not @pending_volunteer.valid? @pending_volunteer.first_name = "Example" @@ -14,6 +14,4 @@ def setup assert_not @pending_volunteer.valid? end - - -end \ No newline at end of file +end