Merge pull request #989 from Ana06/registration_limit
registration_limit check moved to ability file
This commit is contained in:
commit
c39a4541cf
2 changed files with 5 additions and 8 deletions
|
|
@ -6,7 +6,7 @@ class ConferenceRegistrationsController < ApplicationController
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@registration = Registration.new(conference_id: @conference.id)
|
@registration = Registration.new(conference_id: @conference.id)
|
||||||
authorize! :new, @registration
|
authorize! :new, @registration, message: "Sorry, you can not register for #{@conference.title}. Registration limit exceeded or the registration is not open."
|
||||||
|
|
||||||
# Redirect to registration edit when user is already registered
|
# Redirect to registration edit when user is already registered
|
||||||
if @conference.user_registered?(current_user)
|
if @conference.user_registered?(current_user)
|
||||||
|
|
@ -23,11 +23,6 @@ class ConferenceRegistrationsController < ApplicationController
|
||||||
redirect_to edit_conference_conference_registrations_path(@conference.short_title)
|
redirect_to edit_conference_conference_registrations_path(@conference.short_title)
|
||||||
end
|
end
|
||||||
|
|
||||||
if @conference.registration_limit_exceeded?
|
|
||||||
redirect_to root_path, error: "Sorry, registration limit exceeded for #{@conference.title}"
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
# @user variable needs to be set so that _sign_up_form_embedded works properly
|
# @user variable needs to be set so that _sign_up_form_embedded works properly
|
||||||
@user = @registration.build_user
|
@user = @registration.build_user
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,8 @@ class Ability
|
||||||
end
|
end
|
||||||
|
|
||||||
can [:new, :create], Registration do |registration|
|
can [:new, :create], Registration do |registration|
|
||||||
registration.conference.registration_open? && registration.new_record?
|
conference = registration.conference
|
||||||
|
conference.registration_open? && registration.new_record? && !conference.registration_limit_exceeded?
|
||||||
end
|
end
|
||||||
|
|
||||||
can :show, Event do |event|
|
can :show, Event do |event|
|
||||||
|
|
@ -74,7 +75,8 @@ class Ability
|
||||||
can :manage, Registration, user_id: user.id
|
can :manage, Registration, user_id: user.id
|
||||||
|
|
||||||
can [:new, :create], Registration do |registration|
|
can [:new, :create], Registration do |registration|
|
||||||
registration.conference.registration_open?
|
conference = registration.conference
|
||||||
|
conference.registration_open? && !conference.registration_limit_exceeded?
|
||||||
end
|
end
|
||||||
|
|
||||||
can :index, Ticket
|
can :index, Ticket
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue