Add warnings when a user needs to register or complete a purchase

This commit is contained in:
Michael Ball 2020-07-11 01:50:17 -07:00
parent 5bef4b7004
commit 1964522f49
4 changed files with 41 additions and 1 deletions

View file

@ -27,6 +27,10 @@ class ConferencesController < ApplicationController
redirect_to admin_conference_splashpage_path(@conference.short_title) && return
end
# User messages at the top of the page.
@unpaid_tickets = current_user_has_unpaid_tickets?
@user_needs_to_register = current_user_needs_to_register?
@image_url = "#{request.protocol}#{request.host}#{@conference.picture}"
if splashpage.include_cfp
@ -79,4 +83,17 @@ class ConferencesController < ApplicationController
format.html { head :ok }
end if request.options?
end
def current_user_tickets
@current_user_tickets ||= current_user.ticket_purchases.by_conference(@conference)
end
def current_user_needs_to_register?
current_user && !@conference.user_registered?(current_user) &&
current_user_tickets.where(ticket: @conference.registration_tickets).paid.any?
end
def current_user_has_unpaid_tickets?
current_user && current_user_tickets.unpaid.any?
end
end