temp
This commit is contained in:
parent
8c230352f9
commit
c1fe73df03
3 changed files with 38 additions and 14 deletions
|
|
@ -11,6 +11,7 @@ class TicketPurchasesController < ApplicationController
|
||||||
|
|
||||||
# Create a ticket purchase which can be paid or unpaid
|
# Create a ticket purchase which can be paid or unpaid
|
||||||
message = TicketPurchase.purchase(@conference, current_user, params[:tickets].try(:first))
|
message = TicketPurchase.purchase(@conference, current_user, params[:tickets].try(:first))
|
||||||
|
current_ticket_purchase = ?
|
||||||
|
|
||||||
# Failed to create ticket purchase
|
# Failed to create ticket purchase
|
||||||
if !message.blank?
|
if !message.blank?
|
||||||
|
|
@ -32,7 +33,14 @@ class TicketPurchasesController < ApplicationController
|
||||||
# this works? maybe
|
# this works? maybe
|
||||||
|
|
||||||
# TODO: Need to check
|
# TODO: Need to check
|
||||||
|
|
||||||
|
# user has a registration ticket
|
||||||
|
# current_user.tickets.for_registration(@conference).present?
|
||||||
|
|
||||||
|
# current ticket purchase
|
||||||
if current_user.ticket_purchases.by_conference(@conference).paid.any?
|
if current_user.ticket_purchases.by_conference(@conference).paid.any?
|
||||||
|
&& current_user.has_registration_ticket_for?(@conference) == true
|
||||||
|
end
|
||||||
for ticket_purchase in current_user.ticket_purchases.by_conference(@conference)
|
for ticket_purchase in current_user.ticket_purchases.by_conference(@conference)
|
||||||
if ticket_purchase.paid?
|
if ticket_purchase.paid?
|
||||||
for physical_ticket in ticket_purchase.physical_tickets
|
for physical_ticket in ticket_purchase.physical_tickets
|
||||||
|
|
@ -48,16 +56,7 @@ class TicketPurchasesController < ApplicationController
|
||||||
# TODO: User wants to purchase a non-registration ticket but does not have a registration ticket but conference requires one
|
# TODO: User wants to purchase a non-registration ticket but does not have a registration ticket but conference requires one
|
||||||
# BUG: When the user only purchases a non-registration ticket,
|
# BUG: When the user only purchases a non-registration ticket,
|
||||||
if @conference.registration_ticket_required?
|
if @conference.registration_ticket_required?
|
||||||
seen_registration = false
|
&& current_user.has_registration_ticket_for?(@conference) == false
|
||||||
for ticket_purchase in current_user.ticket_purchases.by_conference(@conference)
|
|
||||||
for physical_ticket in ticket_purchase.physical_tickets
|
|
||||||
if physical_ticket.ticket.registration_ticket
|
|
||||||
seen = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if !seen
|
|
||||||
redirect_to conference_tickets_path(@conference.short_title),
|
redirect_to conference_tickets_path(@conference.short_title),
|
||||||
error: 'Please get at least one registration ticket to continue.'
|
error: 'Please get at least one registration ticket to continue.'
|
||||||
return
|
return
|
||||||
|
|
@ -65,9 +64,15 @@ class TicketPurchasesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Need to check if the current user didn't have a registration ticket and is purchasing one
|
# TODO: Need to check if the current user didn't have a registration ticket and is purchasing one
|
||||||
redirect_to new_conference_conference_registration_path(@conference.short_title)
|
if current_user.tickets.for_registration(@conference).nil?
|
||||||
# # otherwise
|
if current_user.has_registration_ticket_for?(@conference) == true
|
||||||
# redirect_to conference_physical_tickets_path
|
redirect_to new_conference_conference_registration_path(@conference.short_title)
|
||||||
|
else
|
||||||
|
redirect_to conference_physical_tickets_path
|
||||||
|
end
|
||||||
|
else
|
||||||
|
redirect_to conference_physical_tickets_path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,11 @@ class TicketPurchase < ApplicationRecord
|
||||||
errors.add(:quantity, 'cannot be greater than one for registration tickets.')
|
errors.add(:quantity, 'cannot be greater than one for registration tickets.')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# def has_registration_ticket_for?(conference)
|
||||||
|
# # BUG: ticket_purchase has only one ticket?
|
||||||
|
# ticket.try(:registration_ticket?)
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
||||||
|
|
@ -346,6 +346,20 @@ class User < ApplicationRecord
|
||||||
events.where(program_id: conference.program.id, 'event_users.event_role': 'volunteer')
|
events.where(program_id: conference.program.id, 'event_users.event_role': 'volunteer')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_registration_ticket_for?(conference)
|
||||||
|
seen_registration = false
|
||||||
|
for ticket_purchase in current_user.ticket_purchases.by_conference(@conference)
|
||||||
|
for physical_ticket in ticket_purchase.physical_tickets
|
||||||
|
if physical_ticket.ticket.registration_ticket
|
||||||
|
seen_registration = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return seen_registration
|
||||||
|
end
|
||||||
|
|
||||||
def self.empty?
|
def self.empty?
|
||||||
User.count == 1 && User.first.email == 'deleted@localhost.osem'
|
User.count == 1 && User.first.email == 'deleted@localhost.osem'
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue