Add (admin-only) tickets via 'visibile' attribute [migration]
(cherry picked from commit ce0db3d7a736e7bcde480721986dbfb4a82aa083)
This commit is contained in:
parent
6e276b2787
commit
199bc00c08
15 changed files with 73 additions and 9 deletions
|
|
@ -85,7 +85,10 @@ class Ability
|
|||
end
|
||||
end
|
||||
|
||||
can :index, Ticket
|
||||
can :index, Organization
|
||||
can :index, Ticket do |ticket|
|
||||
ticket.visible
|
||||
end
|
||||
can :manage, TicketPurchase, user_id: user.id
|
||||
can [:new, :create], Payment, user_id: user.id
|
||||
can [:index, :show], PhysicalTicket, user: user
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ class Ticket < ApplicationRecord
|
|||
|
||||
validates :price_cents, numericality: { greater_than_or_equal_to: 0 }
|
||||
|
||||
scope :visible, -> { where(visible: true) }
|
||||
|
||||
def bought?(user)
|
||||
buyers.include?(user)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class TicketPurchase < ApplicationRecord
|
|||
errors.push('You cannot buy more than one registration tickets.')
|
||||
else
|
||||
ActiveRecord::Base.transaction do
|
||||
conference.tickets.each do |ticket|
|
||||
conference.tickets.visible.each do |ticket|
|
||||
quantity = purchases[ticket.id.to_s].to_i
|
||||
# if the user bought the ticket and is still unpaid, just update the quantity
|
||||
purchase = if ticket.bought?(user) && ticket.unpaid?(user)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue