Added check for payment date in ability.tb
This commit is contained in:
parent
9171beabf8
commit
07abd88c1c
2 changed files with 7 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
class PaymentsController < ApplicationController
|
class PaymentsController < ApplicationController
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_user!
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource except: :new
|
||||||
load_resource :conference, find_by: :short_title
|
load_resource :conference, find_by: :short_title
|
||||||
authorize_resource :conference_registrations, class: Registration
|
authorize_resource :conference_registrations, class: Registration
|
||||||
|
|
||||||
|
|
@ -9,10 +9,8 @@ class PaymentsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
authorize! :new, Payment.new(conference_id: @conference.id)
|
||||||
@total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false)
|
@total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false)
|
||||||
if @conference.end_date < Date.today
|
|
||||||
raise CanCan::AccessDenied.new("This conference has ended on #{@conference.end_date}!", :new, Payment)
|
|
||||||
end
|
|
||||||
if @total_amount_to_pay.zero?
|
if @total_amount_to_pay.zero?
|
||||||
raise CanCan::AccessDenied.new('Nothing to pay for!', :new, Payment)
|
raise CanCan::AccessDenied.new('Nothing to pay for!', :new, Payment)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,11 @@ class Ability
|
||||||
can :index, Ticket
|
can :index, Ticket
|
||||||
can :manage, TicketPurchase, user_id: user.id
|
can :manage, TicketPurchase, user_id: user.id
|
||||||
can [:new, :create], Payment, user_id: user.id
|
can [:new, :create], Payment, user_id: user.id
|
||||||
|
|
||||||
|
can :new, Payment do |payment|
|
||||||
|
payment.conference.end_date >= Date.today
|
||||||
|
end
|
||||||
|
|
||||||
can [:index, :show], PhysicalTicket, user: user
|
can [:index, :show], PhysicalTicket, user: user
|
||||||
|
|
||||||
can [:new, :create], Booth do |booth|
|
can [:new, :create], Booth do |booth|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue