From 9171beabf8b99bb5ab8eaff636f0bb3bc259763b Mon Sep 17 00:00:00 2001 From: rishabhptr Date: Tue, 10 Oct 2017 21:51:24 +0530 Subject: [PATCH 1/2] Added check for conference end_date in payments#new --- app/controllers/payments_controller.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/controllers/payments_controller.rb b/app/controllers/payments_controller.rb index 322ed397..ae8c89da 100644 --- a/app/controllers/payments_controller.rb +++ b/app/controllers/payments_controller.rb @@ -10,6 +10,9 @@ class PaymentsController < ApplicationController def new @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 From 07abd88c1cbcdc371322c55384820d55f1627aca Mon Sep 17 00:00:00 2001 From: rishabhptr Date: Wed, 1 Nov 2017 20:34:21 +0530 Subject: [PATCH 2/2] Added check for payment date in ability.tb --- app/controllers/payments_controller.rb | 6 ++---- app/models/ability.rb | 5 +++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/controllers/payments_controller.rb b/app/controllers/payments_controller.rb index ae8c89da..6b7ac926 100644 --- a/app/controllers/payments_controller.rb +++ b/app/controllers/payments_controller.rb @@ -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 diff --git a/app/models/ability.rb b/app/models/ability.rb index 18f9d4c4..04f56e51 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -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|