Fix authorization of new and create in ConferenceRegistrationsController

Before authorization we need to set conference relation.
Change in proposal spec cause conference has to have valid registration
period for successful redirect to registration after confirm proposal.
This commit is contained in:
Aditya Prakash 2016-03-17 14:54:35 +05:30
parent 10ef898a0d
commit eae6d90e9f
4 changed files with 27 additions and 5 deletions

View file

@ -1,10 +1,13 @@
class ConferenceRegistrationsController < ApplicationController
before_filter :authenticate_user!, except: [:new, :create]
load_resource :conference, find_by: :short_title
authorize_resource :conference_registrations, class: Registration
authorize_resource :conference_registrations, class: Registration, except: [:new, :create]
before_action :set_registration, only: [:edit, :update, :destroy, :show]
def new
@registration = Registration.new(conference_id: @conference.id)
authorize! :new, @registration
# Redirect to registration edit when user is already registered
if @conference.user_registered?(current_user)
redirect_to edit_conference_conference_registrations_path(@conference.short_title)
@ -25,8 +28,6 @@ class ConferenceRegistrationsController < ApplicationController
return
end
@registration = Registration.new
# @user variable needs to be set so that _sign_up_form_embedded works properly
@user = @registration.build_user
end
@ -50,6 +51,7 @@ class ConferenceRegistrationsController < ApplicationController
end
@registration.user = @user
authorize! :create, @registration
if @registration.save
# Trigger ahoy event