diff --git a/app/controllers/conference_registrations_controller.rb b/app/controllers/conference_registrations_controller.rb index 176f7937..d07adf3a 100644 --- a/app/controllers/conference_registrations_controller.rb +++ b/app/controllers/conference_registrations_controller.rb @@ -14,7 +14,7 @@ class ConferenceRegistrationsController < ApplicationController return # ichain does not allow us to create users during registration elsif (ENV['OSEM_ICHAIN_ENABLED'] == 'true') && !current_user - redirect_to root_path, alert: 'You need to sign in or sign up before continuing.' + redirect_to new_user_ichain_session_path, alert: 'You need to sign in or sign up before continuing.' return end diff --git a/app/models/ability.rb b/app/models/ability.rb index 09d73da9..70e08d5a 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -45,14 +45,20 @@ class Ability # can view Commercials of confirmed Events can :show, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(state: 'confirmed').pluck(:id) can [:show, :create], User - unless ENV['OSEM_ICHAIN_ENABLED'] == 'true' + if ENV['OSEM_ICHAIN_ENABLED'] == 'true' + can [:new, :create], Registration do |registration| + conference = registration.conference + can_register?(conference, registration) + end + + else can :show, Registration do |registration| registration.new_record? end can [:new, :create], Registration do |registration| conference = registration.conference - conference.registration_open? && registration.new_record? && !conference.registration_limit_exceeded? + can_register?(conference, registration) end can :show, Event do |event| @@ -62,6 +68,7 @@ class Ability can [:new, :create], Event do |event| event.program.cfp_open? && event.new_record? end + end end @@ -262,3 +269,9 @@ class Ability end end end + +def can_register? conference, registration + conference.registration_open? && + registration.new_record? && + !conference.registration_limit_exceeded? +end