registration_limit check moved to ability file

This commit is contained in:
Ana 2016-05-04 23:46:52 +02:00
parent 0018284c66
commit 866e58b5bf
2 changed files with 5 additions and 8 deletions

View file

@ -6,7 +6,7 @@ class ConferenceRegistrationsController < ApplicationController
def new
@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
if @conference.user_registered?(current_user)
@ -23,11 +23,6 @@ class ConferenceRegistrationsController < ApplicationController
redirect_to edit_conference_conference_registrations_path(@conference.short_title)
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 = @registration.build_user
end

View file

@ -51,7 +51,8 @@ class Ability
end
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
can :show, Event do |event|
@ -74,7 +75,8 @@ class Ability
can :manage, Registration, user_id: user.id
can [:new, :create], Registration do |registration|
registration.conference.registration_open?
conference = registration.conference
conference.registration_open? && !conference.registration_limit_exceeded?
end
can :index, Ticket