Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: first_name and last_name move from questionnaire to user #241

Merged
merged 30 commits into from
Aug 30, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
dd63c2f
Initial move: first/last name; user->quesitonnaire
peterkos May 26, 2020
c8571f3
refactor: Attempt to fix backend params
peterkos May 26, 2020
5032247
refactor: Make HoundBot a little happier
peterkos May 26, 2020
1362047
feat: Admin list shows first/last names
peterkos May 27, 2020
a098e1a
inprog on stats page
peterkos May 29, 2020
8be1aa6
Refactored stats datatable and controller
peterkos May 30, 2020
0f1b0ae
Migration is now backwards compatible with pre-2.0
peterkos May 30, 2020
890a753
4space->2space :rage: #downwith2spaces
peterkos May 30, 2020
ce3ade8
Merge branch '2.0' into issue-222
peterkos Jun 8, 2020
f79be12
Fix various first_name/last_name bugs
peterkos Jun 9, 2020
c2bacfa
Fixed remainder of tests for name refactor
peterkos Jun 9, 2020
334eadc
Fix datatable style and count ranges
peterkos Jun 9, 2020
a25e69c
Fix some more style bugs
peterkos Jun 9, 2020
5be9b1f
Viewing bus list w/ passengers now works
peterkos Jun 18, 2020
7869dfb
Adds Users & Staff support for #222
cbaudouinjr Jun 19, 2020
9b0bc4d
Adds #222 support to stats, fixes stats layout
cbaudouinjr Jun 28, 2020
de98e6f
Fixes Hound issues
cbaudouinjr Jun 28, 2020
4de5632
Removes Hound whitespace issues
cbaudouinjr Jun 28, 2020
d791024
History audit bugfix
peterkos Jun 30, 2020
5350fcb
Add nil check back, whoops. This works better.
peterkos Jun 30, 2020
6556b17
Squashed commit of the following:
peterkos Jul 2, 2020
df42cf6
Merge branch '2.0' into issue-222
cbaudouinjr Jul 2, 2020
2b2cec1
Fix undefined err on bus list info
peterkos Jul 18, 2020
900a0a8
Fix bus captain bug, update schema
peterkos Aug 29, 2020
5c3dff5
Squashed commit of the following:
peterkos Aug 30, 2020
eadaddd
Actually assign current_user
peterkos Aug 30, 2020
6f72d89
mymlh working
peterkos Aug 30, 2020
33e3c65
Refactor questionnnaire new to be nicer to read
peterkos Aug 30, 2020
8012b30
Patch condition error for info refactor
peterkos Aug 30, 2020
8f6e894
Merge branch '2.0' into issue-222
peterkos Aug 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/assets/javascripts/manage/lib/setupDataTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ var setupDataTables = function () {
order: [1, 'asc'],
columns: [
{ orderable: true, data: 'id', visible: false },
{ orderable: true, data: 'first_name' },
{ orderable: true, data: 'last_name' },
{ orderable: true, data: 'email' },
{ orderable: true, data: 'role' },
{ orderable: true, data: 'active' },
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/manage/admins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def destroy

def user_params
params.require(:user).permit(
:email, :password, :password_confirmation, :remember_me, :role, :is_active, :receive_weekly_report
:first_name, :last_name, :email, :password, :password_confirmation, :remember_me, :role, :is_active, :receive_weekly_report
)
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/manage/bus_lists_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def toggle_bus_captain
is_bus_captain = params[:bus_captain] == "1"
@questionnaire.update_attribute(:is_bus_captain, is_bus_captain)
if @questionnaire.reload.is_bus_captain
flash[:notice] = "#{@questionnaire.full_name} has been promoted to a bus captain."
flash[:notice] = "#{@questionnaire.user.full_name} has been promoted to a bus captain."
Message.queue_for_trigger("bus_list.new_captain_confirmation", @questionnaire.user.id)
else
flash[:notice] = "#{@questionnaire.full_name} has been removed as a bus captain."
flash[:notice] = "#{@questionnaire.user.full_name} has been removed as a bus captain."
end
redirect_to [:manage, @bus_list]
end
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/manage/questionnaires_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ def check_in
end
@questionnaire.update_attribute(:checked_in_at, Time.now)
@questionnaire.update_attribute(:checked_in_by_id, current_user.id)
flash[:notice] = "Checked in #{@questionnaire.full_name}."
flash[:notice] = "Checked in #{@questionnaire.user.full_name}."
elsif params[:check_in] == "false"
@questionnaire.update_attribute(:checked_in_at, nil)
@questionnaire.update_attribute(:checked_in_by_id, current_user.id)
flash[:notice] = "#{@questionnaire.full_name} no longer checked in."
flash[:notice] = "#{@questionnaire.user.full_name} no longer checked in."
else
flash[:alert] = "No check-in action provided!"
redirect_to show_redirect_path
Expand Down Expand Up @@ -148,7 +148,7 @@ def message_events

def questionnaire_params
params.require(:questionnaire).permit(
:email, :experience, :first_name, :last_name, :gender,
:email, :experience, :gender,
:date_of_birth, :interest, :school_id, :school_name, :major, :level_of_study,
:shirt_size, :dietary_restrictions, :special_needs, :international,
:portfolio_url, :vcs_url, :agreement_accepted, :bus_captain_interest,
Expand Down
216 changes: 121 additions & 95 deletions app/controllers/manage/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,125 +4,151 @@ def index

def dietary_special_needs
data = Rails.cache.fetch(cache_key_for_questionnaires("dietary_special_needs")) do
select_attributes = [
:first_name,
:last_name,

peterkos marked this conversation as resolved.
Show resolved Hide resolved
# TODO figure this whole thing out
peterkos marked this conversation as resolved.
Show resolved Hide resolved
# Note that comments may misinterpret what is actually happening.

# Attributes for the user to request
u_attributes = [ :first_name, :last_name ]
peterkos marked this conversation as resolved.
Show resolved Hide resolved

# Attributes for the questionnaire to request
q_attributes = [
:phone,
:checked_in_at,
:dietary_restrictions,
:special_needs,
:user_id
]
json_attributes = [
:first_name,
:last_name,

# Condition: only retrieve users that have dietary restrictions or special dietary needs
restrictions = "dietary_restrictions != '' AND acc_status = 'rsvp_confirmed'"\
"OR special_needs != '' AND acc_status = 'rsvp_confirmed'"

# Generate a full "request" (relation) based on this
questionnaire_data = Questionnaire.where(restrictions).select(q_attributes)

# Filter only the values we want to JSON
u_json_attributes = [ :first_name, :last_name ]
q_json_attributes = [
:email,
:phone,
:checked_in_at,
:dietary_restrictions,
:special_needs
]
data = Questionnaire.where("dietary_restrictions != '' AND acc_status = 'rsvp_confirmed' OR special_needs != '' AND acc_status = 'rsvp_confirmed'").select(select_attributes)
to_json_array(data, json_attributes)

# Convert each to a JSON array in-place
to_json_array(user_data, u_json_attributes)
to_json_array(questionnaire_data, q_json_attributes)
end
render json: { data: data }

# Finally, render it out
render json: { data: questionnaire_data }
end

# def sponsor_info
# data = Rails.cache.fetch(cache_key_for_questionnaires("sponsor_info")) do
# select_attributes = [
# :id,
# :first_name,
# :last_name,
# :vcs_url,
# :portfolio_url,
# :user_id,
# :school_id
# ]
# json_attributes = [
# :first_name,
# :last_name,
# :email,
# :school_name,
# :vcs_url,
# :portfolio_url
# ]
# data = Questionnaire.where("can_share_info = '1' AND checked_in_at != 0").joins(:resume_attachment).select(select_attributes)
# json = to_json_array(data, json_attributes)
# json.map.with_index { |item, index| item.insert(6, data[index].resume.attached? ? url_for(data[index].resume) : '') }
# end
# render json: { data: data }
# end

# def alt_travel
# data = Rails.cache.fetch(cache_key_for_questionnaires("alt_travel")) do
# select_attributes = [
# :id,
# :first_name,
# :last_name,
# :travel_location,
# :acc_status,
# :user_id,
# :school_id
# ]
# json_attributes = [
# :id,
# :first_name,
# :last_name,
# :email,
# :travel_location,
# :acc_status
# ]
# data = Questionnaire.where("travel_not_from_school = '1'").select(select_attributes)
# json = to_json_array(data, json_attributes)
# json.each do |e|
# e[0] = view_context.link_to("View »".html_safe, manage_questionnaire_path(e[0]))
# end
# end
# render json: { data: data }
# end

# def mlh_info_applied
# data = Rails.cache.fetch(cache_key_for_questionnaires("mlh_info_applied")) do
# select_attributes = [
# :first_name,
# :last_name,
# :user_id,
# :school_id
# ]
# json_attributes = [
# :first_name,
# :last_name,
# :email,
# :school_name
# ]
# data = Questionnaire.joins(:school).select(select_attributes)
# to_json_array(data, json_attributes)
# end
# render json: { data: data }
# end

# def mlh_info_checked_in
# data = Rails.cache.fetch(cache_key_for_questionnaires("mlh_info_checked_in")) do
# select_attributes = [
# :first_name,
# :last_name,
# :user_id,
# :school_id
# ]
# json_attributes = [
# :first_name,
# :last_name,
# :email,
# :school_name
# ]
# data = Questionnaire.joins(:school).select(select_attributes).where('checked_in_at > 0')
# to_json_array(data, json_attributes)
# end
# render json: { data: data }
# end

peterkos marked this conversation as resolved.
Show resolved Hide resolved
def sponsor_info
peterkos marked this conversation as resolved.
Show resolved Hide resolved
data = Rails.cache.fetch(cache_key_for_questionnaires("sponsor_info")) do
select_attributes = [
:id,
:first_name,
:last_name,
:vcs_url,
:portfolio_url,
:user_id,
:school_id
]
json_attributes = [
:first_name,
:last_name,
:email,
:school_name,
:vcs_url,
:portfolio_url
]
data = Questionnaire.where("can_share_info = '1' AND checked_in_at != 0").joins(:resume_attachment).select(select_attributes)
json = to_json_array(data, json_attributes)
json.map.with_index { |item, index| item.insert(6, data[index].resume.attached? ? url_for(data[index].resume) : '') }
end
render json: { data: data }
end

def alt_travel
data = Rails.cache.fetch(cache_key_for_questionnaires("alt_travel")) do
select_attributes = [
:id,
:first_name,
:last_name,
:travel_location,
:acc_status,
:user_id,
:school_id
]
json_attributes = [
:id,
:first_name,
:last_name,
:email,
:travel_location,
:acc_status
]
data = Questionnaire.where("travel_not_from_school = '1'").select(select_attributes)
json = to_json_array(data, json_attributes)
json.each do |e|
e[0] = view_context.link_to("View »".html_safe, manage_questionnaire_path(e[0]))
end
end
render json: { data: data }
end

def mlh_info_applied
data = Rails.cache.fetch(cache_key_for_questionnaires("mlh_info_applied")) do
select_attributes = [
:first_name,
:last_name,
:user_id,
:school_id
]
json_attributes = [
:first_name,
:last_name,
:email,
:school_name
]
data = Questionnaire.joins(:school).select(select_attributes)
to_json_array(data, json_attributes)
end
render json: { data: data }
end

def mlh_info_checked_in
data = Rails.cache.fetch(cache_key_for_questionnaires("mlh_info_checked_in")) do
select_attributes = [
:first_name,
:last_name,
:user_id,
:school_id
]
json_attributes = [
:first_name,
:last_name,
:email,
:school_name
]
data = Questionnaire.joins(:school).select(select_attributes).where('checked_in_at > 0')
to_json_array(data, json_attributes)
end
render json: { data: data }
end


private

def to_json_array(data, attributes)
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/questionnaires_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ def new
if session["devise.provider_data"] && session["devise.provider_data"]["info"]
@skip_my_mlh_fields = true
@questionnaire.tap do |q|
q.first_name = session["devise.provider_data"]["info"]["first_name"]
q.last_name = session["devise.provider_data"]["info"]["last_name"]
q.phone = session["devise.provider_data"]["info"]["phone_number"]
q.level_of_study = session["devise.provider_data"]["info"]["level_of_study"]
q.major = session["devise.provider_data"]["info"]["major"]
Expand Down Expand Up @@ -119,7 +117,7 @@ def schools

def questionnaire_params
params.require(:questionnaire).permit(
:email, :experience, :first_name, :last_name, :gender,
:email, :experience, :gender,
:date_of_birth, :interest, :school_id, :school_name, :major, :level_of_study,
:shirt_size, :dietary_restrictions, :special_needs, :international,
:portfolio_url, :vcs_url, :agreement_accepted, :bus_captain_interest,
Expand Down
25 changes: 13 additions & 12 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Users::RegistrationsController < Devise::RegistrationsController
# before_action :configure_sign_up_params, only: [:create]
# before_action :configure_account_update_params, only: [:update]
before_action :configure_sign_up_params, only: [:create]
before_action :configure_account_update_params, only: [:update]

# GET /resource/sign_up
def new
Expand Down Expand Up @@ -28,6 +28,17 @@ def destroy
super
end

# Permit adding custom parameters for sign up
# (Devise gives us email and password by default, but we want some more.)
def configure_sign_up_params
devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name])
end

# Permit updating custom parameters for sign up
def configure_account_update_params
devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name])
end

# GET /resource/cancel
# Forces the session data which is usually expired after sign
# in to be expired now. This is useful if the user wants to
Expand All @@ -39,16 +50,6 @@ def destroy

# protected

# You can put the params you want to permit in the empty array.
# def configure_sign_up_params
# devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute])
# end

# You can put the params you want to permit in the empty array.
# def configure_account_update_params
# devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])
# end

# The path used after sign up.
# def after_sign_up_path_for(resource)
# super(resource)
Expand Down
4 changes: 4 additions & 0 deletions app/datatables/admin_datatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class AdminDatatable < ApplicationDatatable
def view_columns
@view_columns ||= {
id: { source: "User.id" },
first_name: { source: "User.first_name" },
last_name: { source: "User.last_name" },
email: { source: "User.email" },
role: { source: "User.role", searchable: false },
active: { source: "User.is_active", searchable: false },
Expand All @@ -23,6 +25,8 @@ def data
records.map do |record|
{
id: record.id,
first_name: record.first_name,
last_name: record.last_name,
email: link_to(bold(record.email), manage_admin_path(record)),
role: record.role.titleize,
active: record.is_active ? '<span class="badge badge-secondary">Active</span>'.html_safe : '<span class="badge badge-danger">Inactive<span>'.html_safe,
Expand Down
4 changes: 2 additions & 2 deletions app/datatables/checkin_datatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ class CheckinDatatable < ApplicationDatatable

def view_columns
@view_columns ||= {
first_name: { source: "Questionnaire.first_name" },
last_name: { source: "Questionnaire.last_name" },
first_name: { source: "User.first_name" },
last_name: { source: "User.last_name" },
checked_in: { source: "Questionnaire.checked_in_at", searchable: false },
}
end
Expand Down
Loading