Update ConferenceRegistrationsController#new
- authenticate on all controller actions unless (OSEM_ICHAIN_ENABLED != true and action is 'new' or 'create') - before_filter rename to before_action - addition of before_action :user_already_registered on :new action (redirects to edit if user already registered) - increased specs
This commit is contained in:
parent
c6be0999b9
commit
af08dabc12
3 changed files with 78 additions and 46 deletions
|
|
@ -1,6 +1,7 @@
|
|||
class ConferenceRegistrationsController < ApplicationController
|
||||
before_filter :authenticate_user!, except: [:new, :create]
|
||||
before_action :authenticate_user!, unless: :allow_guests?
|
||||
load_resource :conference, find_by: :short_title
|
||||
before_action :user_already_registered, only: :new
|
||||
authorize_resource :conference_registrations, class: Registration, except: [:new, :create]
|
||||
before_action :set_registration, only: [:edit, :update, :destroy, :show]
|
||||
|
||||
|
|
@ -8,21 +9,6 @@ class ConferenceRegistrationsController < ApplicationController
|
|||
@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)
|
||||
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)
|
||||
end
|
||||
|
||||
# @user variable needs to be set so that _sign_up_form_embedded works properly
|
||||
@user = @registration.build_user
|
||||
end
|
||||
|
|
@ -96,6 +82,18 @@ class ConferenceRegistrationsController < ApplicationController
|
|||
|
||||
protected
|
||||
|
||||
def allow_guests?
|
||||
ENV['OSEM_ICHAIN_ENABLED'] != 'true' && params[:action].in?(['new', 'create'])
|
||||
end
|
||||
|
||||
def user_already_registered
|
||||
# Redirect to registration edit when user is already registered
|
||||
if @conference.user_registered?(current_user)
|
||||
redirect_to edit_conference_conference_registration_path(@conference.short_title)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
def set_registration
|
||||
@registration = Registration.find_by(conference: @conference, user: current_user)
|
||||
unless @registration
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue