Refactoring Tickets
- Tickets now independent from registration - Implemented money gem #419
This commit is contained in:
parent
5485fe0e7f
commit
5f8a8ac6d9
63 changed files with 1581 additions and 573 deletions
|
|
@ -17,13 +17,13 @@ module Admin
|
|||
flash[:notice] = "Successfully updated Attended for #{@user.email}"
|
||||
redirect_to admin_conference_registrations_path(@conference.short_title)
|
||||
else
|
||||
flash[:notice] = "Update Attended for #{@user.email} failed!"
|
||||
flash[:notice] = "Update Attended for #{@user.email} failed!" \
|
||||
"#{@registration.errors.full_messages.join('. ')}"
|
||||
redirect_to admin_conference_registrations_path(@conference.short_title)
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
def edit; end
|
||||
|
||||
def update
|
||||
@registration.update_attributes(registration_params)
|
||||
|
|
@ -51,7 +51,7 @@ module Admin
|
|||
protected
|
||||
|
||||
def set_user
|
||||
@user = User.where('id = ?', @registration.user_id).first
|
||||
@user = User.find_by(id: @registration.user_id)
|
||||
end
|
||||
|
||||
def registration_params
|
||||
|
|
@ -63,10 +63,7 @@ module Admin
|
|||
qanswers_attributes: [],
|
||||
user_attributes: [
|
||||
:id, :name, :tshirt, :mobile, :volunteer_experience, :languages,
|
||||
:nickname, :affiliation ],
|
||||
supporter_registration_attributes: [
|
||||
:id, :supporter_level_id, :code
|
||||
])
|
||||
:nickname, :affiliation ])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
module Admin
|
||||
class SupporterLevelsController < Admin::BaseController
|
||||
load_and_authorize_resource :conference, find_by: :short_title
|
||||
authorize_resource through: :conference
|
||||
|
||||
def index
|
||||
authorize! :update, SupporterLevel.new(conference_id: @conference.id)
|
||||
end
|
||||
|
||||
def show
|
||||
render :supporter_levels
|
||||
end
|
||||
|
||||
def update
|
||||
begin
|
||||
@conference.update_attributes!(params[:conference])
|
||||
redirect_to(admin_conference_supporter_levels_path(conference_id: @conference.short_title), notice: 'Supporter levels were successfully updated.')
|
||||
rescue => e
|
||||
redirect_to(admin_conference_supporter_levels_path(conference_id: @conference.short_title), alert: "Supporter levels update failed: #{e.message}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
module Admin
|
||||
class SupportersController < Admin::BaseController
|
||||
load_and_authorize_resource :conference, find_by: :short_title
|
||||
load_and_authorize_resource through: :conference
|
||||
|
||||
def index
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json { render json: DatatableSupporters.new(@conference.supporter_registrations, view_context) }
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
params[:supporter_registration][:conference_id] = @conference.id
|
||||
SupporterRegistration.create!(params[:supporter_registration])
|
||||
redirect_to(admin_conference_supporters_path(conference_id: @conference.short_title), notice: "Supporter added")
|
||||
end
|
||||
end
|
||||
end
|
||||
54
app/controllers/admin/tickets_controller.rb
Normal file
54
app/controllers/admin/tickets_controller.rb
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
module Admin
|
||||
class TicketsController < Admin::BaseController
|
||||
load_and_authorize_resource :conference, find_by: :short_title
|
||||
load_and_authorize_resource :ticket, through: :conference
|
||||
|
||||
def index
|
||||
authorize! :update, Ticket.new(conference_id: @conference.id)
|
||||
end
|
||||
|
||||
def new
|
||||
@ticket = @conference.tickets.new
|
||||
end
|
||||
|
||||
def create
|
||||
@ticket = @conference.tickets.new(ticket_params)
|
||||
if @ticket.save(ticket_params)
|
||||
redirect_to(admin_conference_tickets_path(conference_id: @conference.short_title),
|
||||
notice: 'Ticket successfully created.')
|
||||
else
|
||||
flash[:alert] = "Creating Ticket failed: #{@ticket.errors.full_messages.join('. ')}."
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def edit; end
|
||||
|
||||
def update
|
||||
if @ticket.update_attributes(ticket_params)
|
||||
redirect_to(admin_conference_tickets_path(conference_id: @conference.short_title),
|
||||
notice: 'Ticket successfully updated.')
|
||||
else
|
||||
flash[:alert] = "Ticket update failed: #{@ticket.errors.full_messages.join('. ')}."
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @ticket.destroy
|
||||
redirect_to(admin_conference_tickets_path(conference_id: @conference.short_title),
|
||||
notice: 'Ticket successfully destroyed.')
|
||||
else
|
||||
redirect_to(admin_conference_tickets_path(conference_id: @conference.short_title),
|
||||
alert: "Ticket was successfully destroyed." \
|
||||
"#{@ticket.errors.full_messages.join('. ')}.")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ticket_params
|
||||
params[:ticket]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -2,17 +2,19 @@ class ConferenceRegistrationsController < ApplicationController
|
|||
before_filter :verify_user
|
||||
load_resource :conference, find_by: :short_title
|
||||
authorize_resource :conference_registrations, class: Registration
|
||||
before_action :set_registration, only: [:edit, :update, :destroy]
|
||||
before_action :set_workshops, only: [:new, :edit, :update, :create]
|
||||
before_action :set_registration, only: [:edit, :update, :destroy, :show]
|
||||
|
||||
def new
|
||||
@registration = current_user.registrations.build(conference_id: @conference.id)
|
||||
@registration.build_supporter_registration
|
||||
end
|
||||
|
||||
def edit
|
||||
def show
|
||||
@workshops = @registration.workshops if @registration
|
||||
@total_price = Ticket.total_price(@conference, current_user)
|
||||
end
|
||||
|
||||
def edit; end
|
||||
|
||||
def create
|
||||
user_attributes = registration_params[:user_attributes]
|
||||
params[:registration].delete :user_attributes
|
||||
|
|
@ -24,16 +26,13 @@ class ConferenceRegistrationsController < ApplicationController
|
|||
# Trigger ahoy event
|
||||
ahoy.track 'Registered', title: 'New registration'
|
||||
|
||||
# Send registration mail
|
||||
if @conference.email_settings.send_on_registration?
|
||||
Mailbot.delay.registration_mail(@conference, current_user)
|
||||
if @conference.tickets.any?
|
||||
redirect_to conference_tickets_path(@conference.short_title),
|
||||
notice: 'You are now registered and will be receiving E-Mail notifications.'
|
||||
else
|
||||
redirect_to conference_conference_registrations_path(@conference.short_title),
|
||||
notice: 'You are now registered and will be receiving E-Mail notifications.'
|
||||
end
|
||||
|
||||
# Set subscription for the conference
|
||||
Subscription.create(conference_id: @conference.id, user_id: current_user.id)
|
||||
|
||||
redirect_to edit_conference_conference_registrations_path(@conference.short_title),
|
||||
notice: 'You are now registered and will be receiving E-Mail notifications.'
|
||||
else
|
||||
flash[:alert] = "A error prohibited the registration for #{@conference.title}: "\
|
||||
"#{@registration.errors.full_messages.join('. ')}."
|
||||
|
|
@ -42,9 +41,9 @@ class ConferenceRegistrationsController < ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
if @registration.update(registration_params)
|
||||
redirect_to edit_conference_conference_registrations_path(@conference.short_title),
|
||||
notice: 'Registration was successfully updated.'
|
||||
if @registration.update_attributes(registration_params)
|
||||
redirect_to conference_conference_registrations_path(@conference.short_title),
|
||||
notice: 'Registration was successfully updated.'
|
||||
else
|
||||
flash[:alert] = "A error prohibited the registration for #{@conference.title}: "\
|
||||
"#{@registration.errors.full_messages.join('. ')}."
|
||||
|
|
@ -53,19 +52,20 @@ class ConferenceRegistrationsController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
@registration.destroy
|
||||
redirect_to root_path,
|
||||
notice: "You are not registered for #{@conference.title} anymore!"
|
||||
if @registration.destroy
|
||||
redirect_to root_path,
|
||||
notice: "You are not registered for #{@conference.title} anymore!"
|
||||
else
|
||||
redirect_to root_path,
|
||||
alert: "A error prohibited deleting the registration for #{@conference.title}: "\
|
||||
"#{@registration.errors.full_messages.join('. ')}."
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def set_workshops
|
||||
@workshops = @conference.events.where('require_registration = ? AND state LIKE ?', true, 'confirmed')
|
||||
end
|
||||
|
||||
def set_registration
|
||||
@registration = current_user.registrations.where(conference_id: @conference.id).first
|
||||
@registration = current_user.registrations.find_by(conference_id: @conference.id)
|
||||
end
|
||||
|
||||
def registration_params
|
||||
|
|
@ -77,9 +77,7 @@ class ConferenceRegistrationsController < ApplicationController
|
|||
qanswers_attributes: [],
|
||||
event_ids: [],
|
||||
user_attributes: [
|
||||
:id, :name, :tshirt, :mobile, :volunteer_experience, :languages],
|
||||
supporter_registration_attributes: [
|
||||
:id, :supporter_level_id, :code
|
||||
])
|
||||
:id, :name, :tshirt, :mobile, :volunteer_experience, :languages]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
29
app/controllers/ticket_purchases_controller.rb
Normal file
29
app/controllers/ticket_purchases_controller.rb
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
class TicketPurchasesController < ApplicationController
|
||||
before_filter :verify_user
|
||||
load_resource :conference, find_by: :short_title
|
||||
authorize_resource :conference_registrations, class: Registration
|
||||
|
||||
def create
|
||||
message = TicketPurchase.purchase(@conference, current_user, params[:tickets][0])
|
||||
if message.blank?
|
||||
redirect_to conference_conference_registrations_path(@conference.short_title),
|
||||
notice: "Congratulations, you have successfully purchased a ticket! " \
|
||||
"You can pay it cash on check in! Thank you for supporting #{@conference.title}!"
|
||||
else
|
||||
redirect_to conference_conference_registrations_path(@conference.short_title),
|
||||
alert: "Oops, something went wrong with your purchase! #{message}"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@ticket_purchases = current_user.ticket_purchases.find_by(ticket_id: params[:id])
|
||||
if @ticket_purchases.destroy
|
||||
redirect_to conference_conference_registrations_path(@conference.short_title),
|
||||
notice: 'Ticket successfully destroyed.'
|
||||
else
|
||||
redirect_to conference_conference_registrations_path(@conference.short_title),
|
||||
notice: "A error prohibited deleting your purchase! "\
|
||||
"#{@ticket_purchases.errors.full_messages.join('. ')}."
|
||||
end
|
||||
end
|
||||
end
|
||||
8
app/controllers/tickets_controller.rb
Normal file
8
app/controllers/tickets_controller.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
class TicketsController < ApplicationController
|
||||
before_filter :verify_user
|
||||
load_resource :conference, find_by: :short_title
|
||||
load_resource :tickets, class: Ticket
|
||||
authorize_resource :conference_registrations, class: Registration
|
||||
|
||||
def index; end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue