Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Metrics/AbcSize:
- 'lib/services/event_calendar.rb'
- 'lib/tasks/setup.rake'
- 'spec/support/select_from_tom_select.rb'
- 'app/services/check_in_pdf.rb'
- 'app/controllers/check_ins_controller.rb'

# Offense count: 8
# Configuration parameters: CountComments, Max, CountAsOne.
Expand All @@ -49,6 +51,7 @@ Metrics/ClassLength:
- 'app/services/invitation_manager.rb'
- 'lib/omniauth/strategies/codebar.rb'
- 'lib/tasks/setup.rake'
- 'app/controllers/check_ins_controller.rb'

# Offense count: 8
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
Expand All @@ -61,6 +64,8 @@ Metrics/CyclomaticComplexity:
- 'app/services/invitation_manager.rb'
- 'lib/flodesk.rb'
- 'lib/omniauth/strategies/codebar.rb'
- 'app/services/check_in_pdf.rb'
- 'app/controllers/check_ins_controller.rb'

# Offense count: 40
# Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns.
Expand Down Expand Up @@ -91,6 +96,9 @@ Metrics/MethodLength:
- 'lib/flodesk.rb'
- 'lib/omniauth/strategies/codebar.rb'
- 'lib/tasks/setup.rake'
- 'app/controllers/admin/check_ins_controller.rb'
- 'app/services/check_in_pdf.rb'
- 'app/controllers/check_ins_controller.rb'

# Offense count: 7
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
Expand All @@ -102,6 +110,7 @@ Metrics/PerceivedComplexity:
- 'app/controllers/workshop_invitation_controller.rb'
- 'app/services/invitation_manager.rb'
- 'lib/omniauth/strategies/codebar.rb'
- 'app/controllers/check_ins_controller.rb'

# Offense count: 5
Rails/HasAndBelongsToMany:
Expand All @@ -124,3 +133,8 @@ Rails/HasManyOrHasOneDependent:
- 'app/models/sponsor.rb'
- 'app/models/workshop.rb'
- 'app/models/workshop_invitation.rb'

# Offense count: 1
Metrics/BlockLength:
Exclude:
- 'app/services/check_in_pdf.rb'
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ end

gem 'rollbar'
gem 'scout_apm'
gem 'rqrcode'
gem 'prawn'
gem 'prawn-svg', '~> 0.35'

gem 'carrierwave-aws', '~> 1.6'
gem 'sitemap_generator', '~> 7.1'
Expand Down
92 changes: 58 additions & 34 deletions Gemfile.lock

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions app/assets/images/check_in/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions app/controllers/admin/check_ins_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

class Admin::CheckInsController < Admin::ApplicationController
before_action :load_check_in_target

def show
authorize @check_in_target
@check_in_target.with_lock { @check_in_target.generate_check_in_code! if @check_in_target.check_in_code.blank? }

respond_to do |format|
format.html
format.pdf do
pdf = CheckInPdf.new(@check_in_target).render
send_data pdf,
filename: "check-in-#{@check_in_target.to_param}.pdf",
type: 'application/pdf',
disposition: 'attachment'
end
end
end

private

def load_check_in_target
if params[:event_id]
@check_in_target = Event.find_by!(slug: params[:event_id])
elsif params[:workshop_id]
@check_in_target = Workshop.find(params[:workshop_id])
end
end
end
4 changes: 2 additions & 2 deletions app/controllers/admin/invitation_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Admin::InvitationController < Admin::ApplicationController

def update
invitation = Invitation.find_by(token: params[:invitation][:id])
invitation.update(attending: true, verified: true, verified_by: current_user)
invitation.update(attending: true, verified: true, verified_by: current_user, source: Invitation::SOURCE_ADMIN)

EventInvitationMailer.attending(invitation.event, invitation.member, invitation).deliver_now

Expand All @@ -17,7 +17,7 @@ def update

def verify
invitation = Invitation.find_by(token: params[:invitation_id])
invitation.update(verified: true, verified_by_id: current_user.id)
invitation.update(verified: true, verified_by_id: current_user.id, source: Invitation::SOURCE_ADMIN)

EventInvitationMailer.attending(invitation.event, invitation.member, invitation).deliver_now

Expand Down
5 changes: 3 additions & 2 deletions app/controllers/admin/invitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def update_attendance(attending:, attended:)
end

def update_to_attended
@invitation.update(attended: true)
@invitation.update(attended: true, source: Invitation::SOURCE_ADMIN)
end

def update_to_unattended
Expand All @@ -51,7 +51,8 @@ def update_to_attending
attending: true,
rsvp_time: Time.zone.now,
automated_rsvp: true,
last_overridden_by_id: current_user.id
last_overridden_by_id: current_user.id,
source: Invitation::SOURCE_ADMIN
)

{
Expand Down
142 changes: 142 additions & 0 deletions app/controllers/check_ins_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# frozen_string_literal: true

class CheckInsController < ApplicationController
before_action :load_check_in_target
before_action :store_referer_path, only: [:new]
before_action :authenticate_member!, only: %i[new create confirm]

def new
@invitation = find_invitation
@suggested_role = infer_role
@already_checked_in = already_checked_in?(@invitation)
end

def create
role = permitted_role
existing = find_invitation

if existing
return redirect_to check_in_confirm_path if already_checked_in?(existing)
return redirect_to check_in_new_path, alert: mismatch_role_message(existing.role) if existing.role != role
end

unless @check_in_target.check_in_open?
return redirect_to check_in_new_path, alert: 'Check-in is not currently open.'
end

if @check_in_target.respond_to?(:waitlisted?) && @check_in_target.waitlisted?(current_user)
return redirect_to check_in_new_path, alert: 'You are on the waiting list and cannot check in.'
end

invitation = existing || find_or_create_invitation(role)

unless @check_in_target.spaces_available_for?(role) || invitation.attending?
return redirect_to check_in_new_path, alert: "There are no #{role} spaces left."
end

mark_attended(invitation)
redirect_to check_in_confirm_path
rescue ActionController::ParameterMissing
redirect_to check_in_new_path, alert: 'Please select a valid role (Student or Coach).'
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique => e
redirect_to check_in_new_path, alert: e.message
end

def confirm
@invitation = find_invitation
end

private

def load_check_in_target
@check_in_target = Event.find_by(check_in_code: params[:code]) ||
Workshop.find_by(check_in_code: params[:code])
raise ActiveRecord::RecordNotFound unless @check_in_target
end

helper_method :check_in_new_path, :check_in_confirm_path

def check_in_new_path
code = @check_in_target.check_in_code
if @check_in_target.is_a?(Event)
check_in_e_path(code:)
else
check_in_w_path(code:)
end
end

def check_in_confirm_path
code = @check_in_target.check_in_code
if @check_in_target.is_a?(Event)
check_in_e_confirm_path(code:)
else
check_in_w_confirm_path(code:)
end
end

def store_referer_path
session[:referer_path] = request.path unless logged_in?
end

def already_checked_in?(invitation)
return false unless invitation

if @check_in_target.is_a?(Event)
invitation.verified?
else
invitation.attended?
end
end

def mismatch_role_message(role)
"You are already registered as a #{role}. Please select that role."
end

def find_invitation
if @check_in_target.is_a?(Event)
Invitation.find_by(event: @check_in_target, member: current_user)
else
WorkshopInvitation.find_by(workshop: @check_in_target, member: current_user)
end
end

def find_or_create_invitation(role)
if @check_in_target.is_a?(Event)
Invitation.create_or_find_by(event: @check_in_target, member: current_user, role: role)
else
WorkshopInvitation.create_or_find_by(workshop: @check_in_target, member: current_user, role: role)
end
end

def mark_attended(invitation)
attrs = { attending: true, source: InvitationConcerns::SOURCE_CHECK_IN }
if @check_in_target.is_a?(Event)
attrs[:verified] = true
else
attrs[:attended] = true
attrs[:automated_rsvp] = true
end
invitation.update!(attrs)
end

def permitted_role
role = params.expect(:role)
return role if %w[Student Coach].include?(role)

raise ActionController::ParameterMissing, :role
end

def infer_role
return @invitation.role if @invitation.present?

groups = current_user.groups
student = groups.students.any?
coach = groups.coaches.any?

if student && !coach
'Student'
elsif coach && !student
'Coach'
end
end
end
Loading
Loading