Merge pull request #41 from snap-cloud/enforce-ticket-registrations

Enforce ticket registrations
This commit is contained in:
Michael Ball 2020-07-11 01:54:01 -07:00 committed by GitHub
commit fff156a453
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 0 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

View file

@ -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?
registration_tickets.any?
end
##
# Delete all EventSchedules that are not in the hours range
# After the conference has been successfully updated

View file

@ -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

View file

@ -16,6 +16,28 @@
= content_for :title do
= @conference.title
= content_for :additional_messages do
- if @unpaid_tickets
.row
.col-md-12
.alert.alert-dismissable.alert-info.text-center#unpaid-tickets{role: 'alert'}
%button.button.close{"data-dismiss" => "alert", "aria-label"=>"close"}
&times;
%p
You have unpaid tickets. Please complete your purchase.
= link_to('Purchase Tickets', new_conference_payment_path(@conference), class: 'btn btn-success btn-lg')
- if @user_needs_to_register
.row
.col-md-12
.alert.alert-dismissable.alert-warning.text-center#flash{role: 'alert'}
%button.button.close{"data-dismiss" => "alert", 'aria-label': 'close'}
&times;
%p
You still need to complete your registration for #{@conference.title}.
= link_to('Complete Registration', new_conference_conference_registration_path(@conference), class: 'btn btn-success btn-lg')
#splash
- if @conference.code_of_conduct.present?

View file

@ -30,6 +30,7 @@
#messages
.container
= render 'layouts/messages'
= yield :additional_messages
#content
= yield