Merge pull request #1266 from AEtherC0r3/fix_unreachable_code

Remove the unreachable code and modify the error message in ConferenceRegistrationsController#new
This commit is contained in:
Stella Rouzi 2017-03-08 10:55:27 +02:00 committed by GitHub
commit 77c7bdfecf
3 changed files with 215 additions and 52 deletions

View file

@ -46,7 +46,7 @@ class ApplicationController < ActionController::Base
rescue_from CanCan::AccessDenied do |exception|
Rails.logger.debug "Access denied on #{exception.action} #{exception.subject.inspect}"
message = exception.message
message << ' Maybe you need to sign in?' unless current_user
message << ' Maybe you need to sign in?' unless @ignore_not_signed_in_user || current_user
redirect_to root_path, alert: message
end

View file

@ -6,22 +6,21 @@ class ConferenceRegistrationsController < ApplicationController
def new
@registration = Registration.new(conference_id: @conference.id)
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)
# Authorization needs to happen in every action before the return statement
# We authorize the #edit action, since we redirect to it
authorize! :edit, current_user.registrations.find_by(conference_id: @conference.id)
redirect_to edit_conference_conference_registration_path(@conference.short_title)
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.'
return
end
# avoid openid sign_in to redirect to register/new when the sign_in user had already a registration
if current_user && @conference.user_registered?(current_user)
redirect_to edit_conference_conference_registration_path(@conference.short_title)
if !@conference.registration_open? || @conference.registration_limit_exceeded?
message = "Sorry, you can not register for #{@conference.title}. Registration limit exceeded or the registration is not open."
@ignore_not_signed_in_user = true
end
authorize! :new, @registration, message: message
# @user variable needs to be set so that _sign_up_form_embedded works properly
@user = @registration.build_user