Added check for payment date in ability.tb

This commit is contained in:
rishabhptr 2017-11-01 20:34:21 +05:30
parent 9171beabf8
commit 07abd88c1c
2 changed files with 7 additions and 4 deletions

View file

@ -1,6 +1,6 @@
class PaymentsController < ApplicationController
before_action :authenticate_user!
load_and_authorize_resource
load_and_authorize_resource except: :new
load_resource :conference, find_by: :short_title
authorize_resource :conference_registrations, class: Registration
@ -9,10 +9,8 @@ class PaymentsController < ApplicationController
end
def new
authorize! :new, Payment.new(conference_id: @conference.id)
@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?
raise CanCan::AccessDenied.new('Nothing to pay for!', :new, Payment)
end

View file

@ -73,6 +73,11 @@ class Ability
can :index, Ticket
can :manage, TicketPurchase, 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 [:new, :create], Booth do |booth|