Merge af08dabc12 into 2a0e1b5dea
This commit is contained in:
commit
093acfe697
3 changed files with 78 additions and 46 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
class ConferenceRegistrationsController < ApplicationController
|
class ConferenceRegistrationsController < ApplicationController
|
||||||
before_filter :authenticate_user!, except: [:new, :create]
|
before_action :authenticate_user!, unless: :allow_guests?
|
||||||
load_resource :conference, find_by: :short_title
|
load_resource :conference, find_by: :short_title
|
||||||
|
before_action :user_already_registered, only: :new
|
||||||
authorize_resource :conference_registrations, class: Registration, except: [:new, :create]
|
authorize_resource :conference_registrations, class: Registration, except: [:new, :create]
|
||||||
before_action :set_registration, only: [:edit, :update, :destroy, :show]
|
before_action :set_registration, only: [:edit, :update, :destroy, :show]
|
||||||
|
|
||||||
|
|
@ -8,21 +9,6 @@ class ConferenceRegistrationsController < ApplicationController
|
||||||
@registration = Registration.new(conference_id: @conference.id)
|
@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."
|
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 variable needs to be set so that _sign_up_form_embedded works properly
|
||||||
@user = @registration.build_user
|
@user = @registration.build_user
|
||||||
end
|
end
|
||||||
|
|
@ -96,6 +82,18 @@ class ConferenceRegistrationsController < ApplicationController
|
||||||
|
|
||||||
protected
|
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
|
def set_registration
|
||||||
@registration = Registration.find_by(conference: @conference, user: current_user)
|
@registration = Registration.find_by(conference: @conference, user: current_user)
|
||||||
unless @registration
|
unless @registration
|
||||||
|
|
|
||||||
|
|
@ -45,16 +45,17 @@ class Ability
|
||||||
# can view Commercials of confirmed Events
|
# can view Commercials of confirmed Events
|
||||||
can :show, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(state: 'confirmed').pluck(:id)
|
can :show, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(state: 'confirmed').pluck(:id)
|
||||||
can [:show, :create], User
|
can [:show, :create], User
|
||||||
|
|
||||||
|
can [:new, :create], Registration do |registration|
|
||||||
|
conference = registration.conference
|
||||||
|
conference.registration_open? && registration.new_record? && !conference.registration_limit_exceeded?
|
||||||
|
end
|
||||||
|
|
||||||
unless ENV['OSEM_ICHAIN_ENABLED'] == 'true'
|
unless ENV['OSEM_ICHAIN_ENABLED'] == 'true'
|
||||||
can :show, Registration do |registration|
|
can :show, Registration do |registration|
|
||||||
registration.new_record?
|
registration.new_record?
|
||||||
end
|
end
|
||||||
|
|
||||||
can [:new, :create], Registration do |registration|
|
|
||||||
conference = registration.conference
|
|
||||||
conference.registration_open? && registration.new_record? && !conference.registration_limit_exceeded?
|
|
||||||
end
|
|
||||||
|
|
||||||
can :show, Event do |event|
|
can :show, Event do |event|
|
||||||
event.new_record?
|
event.new_record?
|
||||||
end
|
end
|
||||||
|
|
@ -74,11 +75,6 @@ class Ability
|
||||||
|
|
||||||
can :manage, Registration, user_id: user.id
|
can :manage, Registration, user_id: user.id
|
||||||
|
|
||||||
can [:new, :create], Registration do |registration|
|
|
||||||
conference = registration.conference
|
|
||||||
conference.registration_open? && !conference.registration_limit_exceeded?
|
|
||||||
end
|
|
||||||
|
|
||||||
can :index, Ticket
|
can :index, Ticket
|
||||||
can :manage, TicketPurchase, user_id: user.id
|
can :manage, TicketPurchase, user_id: user.id
|
||||||
can [:new, :create], Payment, user_id: user.id
|
can [:new, :create], Payment, user_id: user.id
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,10 @@ describe ConferenceRegistrationsController, type: :controller do
|
||||||
get :new, conference_id: conference.short_title
|
get :new, conference_id: conference.short_title
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'redirects to root path' do
|
||||||
|
expect(response).to redirect_to root_path
|
||||||
|
end
|
||||||
|
|
||||||
it 'shows flash alert telling user they are unable to register' do
|
it 'shows flash alert telling user they are unable to register' do
|
||||||
expect(flash[:alert]).to eq "Sorry, you can not register for #{conference.title}. Registration limit exceeded or the registration is not open."
|
expect(flash[:alert]).to eq "Sorry, you can not register for #{conference.title}. Registration limit exceeded or the registration is not open."
|
||||||
end
|
end
|
||||||
|
|
@ -213,37 +217,71 @@ describe ConferenceRegistrationsController, type: :controller do
|
||||||
|
|
||||||
context 'user is not signed in' do
|
context 'user is not signed in' do
|
||||||
describe 'GET #new' do
|
describe 'GET #new' do
|
||||||
before do
|
context 'registration period open' do
|
||||||
@registration_period = create(:registration_period, conference: conference)
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'OSEM_ICHAIN_ENABLED is true' do
|
|
||||||
before do
|
before do
|
||||||
stub_const('ENV', ENV.to_hash.merge('OSEM_ICHAIN_ENABLED' => 'true'))
|
@registration_period = create(:registration_period, conference: conference)
|
||||||
get :new, conference_id: conference.short_title
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'redirects to root' do
|
context 'OSEM_ICHAIN_ENABLED is true' do
|
||||||
expect(response).to redirect_to root_path
|
before do
|
||||||
|
stub_const('ENV', ENV.to_hash.merge('OSEM_ICHAIN_ENABLED' => 'true'))
|
||||||
|
get :new, conference_id: conference.short_title
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redirects to root' do
|
||||||
|
expect(response).to redirect_to new_user_session_path
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'shows flash alert telling user they cannot register and they need to sign in' do
|
||||||
|
expect(flash[:alert]).to eq 'You need to sign in or sign up before continuing.'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'shows flash alert telling user they cannot register and they need to sign in' do
|
context 'OSEM_ICHAIN_ENABLED is false' do
|
||||||
expect(flash[:alert]).to eq "Sorry, you can not register for #{conference.title}. Registration limit exceeded or the registration is not open. Maybe you need to sign in?"
|
before do
|
||||||
|
stub_const('ENV', ENV.to_hash.merge('OSEM_ICHAIN_ENABLED' => 'false'))
|
||||||
|
get :new, conference_id: conference.short_title
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'user variable exists' do
|
||||||
|
expect(assigns(:user)).not_to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders the new template' do
|
||||||
|
expect(response).to render_template('new')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'OSEM_ICHAIN_ENABLED is false' do
|
context 'registration period not open' do
|
||||||
before do
|
context 'OSEM_ICHAIN_ENABLED is true' do
|
||||||
stub_const('ENV', ENV.to_hash.merge('OSEM_ICHAIN_ENABLED' => 'false'))
|
before do
|
||||||
get :new, conference_id: conference.short_title
|
stub_const('ENV', ENV.to_hash.merge('OSEM_ICHAIN_ENABLED' => 'true'))
|
||||||
|
get :new, conference_id: conference.short_title
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redirects to root' do
|
||||||
|
expect(response).to redirect_to new_user_session_path
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'shows flash alert telling user they need to sign in' do
|
||||||
|
expect(flash[:alert]).to eq 'You need to sign in or sign up before continuing.'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'user variable exists' do
|
context 'OSEM_ICHAIN_ENABLED is false' do
|
||||||
expect(assigns(:user)).not_to be_nil
|
before do
|
||||||
end
|
stub_const('ENV', ENV.to_hash.merge('OSEM_ICHAIN_ENABLED' => 'false'))
|
||||||
|
get :new, conference_id: conference.short_title
|
||||||
|
end
|
||||||
|
|
||||||
it 'renders the new template' do
|
it 'redirects to root path' do
|
||||||
expect(response).to render_template('new')
|
expect(response).to redirect_to root_path
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'shows flash alert telling user they cannot register' do
|
||||||
|
expect(flash[:alert]).to eq "Sorry, you can not register for #{conference.title}. Registration limit exceeded or the registration is not open. Maybe you need to sign in?"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue