Assert that a user has a paid ticket before registering for a conference.
This commit is contained in:
parent
69b18a97e1
commit
5bef4b7004
2 changed files with 18 additions and 0 deletions
|
|
@ -30,6 +30,7 @@ class Conference < ApplicationRecord
|
|||
has_many :payments, dependent: :destroy
|
||||
has_many :supporters, through: :ticket_purchases, source: :user
|
||||
has_many :tickets, dependent: :destroy
|
||||
has_many :registration_tickets, -> { for_registration }, class_name: 'Ticket'
|
||||
has_many :resources, dependent: :destroy
|
||||
has_many :booths, dependent: :destroy
|
||||
has_many :confirmed_booths, -> { where(state: 'confirmed') }, class_name: 'Booth'
|
||||
|
|
@ -111,6 +112,13 @@ class Conference < ApplicationRecord
|
|||
user.present? && registrations.where(user_id: user.id).count > 0
|
||||
end
|
||||
|
||||
##
|
||||
# True when there is at least one ticket marked as "registration"
|
||||
# A user must get a registration ticket before registering.
|
||||
def registration_ticket_required?
|
||||
tickets.for_registration.any?
|
||||
end
|
||||
|
||||
##
|
||||
# Delete all EventSchedules that are not in the hours range
|
||||
# After the conference has been successfully updated
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ class Registration < ApplicationRecord
|
|||
if: -> { conference.try(:code_of_conduct).present? }
|
||||
}
|
||||
|
||||
validate :user_has_registration_ticket, if: -> { conference.registration_ticket_required? }
|
||||
|
||||
after_create :set_week, :subscribe_to_conference, :send_registration_mail
|
||||
|
||||
##
|
||||
|
|
@ -65,4 +67,12 @@ class Registration < ApplicationRecord
|
|||
errors.add(:base, 'Registration limit exceeded')
|
||||
end
|
||||
end
|
||||
|
||||
def user_has_registration_ticket
|
||||
return if TicketPurchase.where(user: user, ticket: conference.registration_tickets).paid.any?
|
||||
errors.add(:base, 'You must purchase a registration ticket before registering')
|
||||
if TicketPurchase.where(user: user, ticket: conference.registration_tickets).unpaid.any?
|
||||
errors.add(:base, 'You currently have a ticket with an unfinished purchase')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue