Sha256: 519362dfc6df526bbd6f2174e3327b96b1d7eda4ea454338b27f7452084ff7ed

Contents?: true

Size: 1.57 KB

Versions: 6

Compression:

Stored size: 1.57 KB

Contents

module Effective
  class EventRegistrationsController < ApplicationController
    if defined?(Devise)
      before_action :authenticate_user!, unless: -> { action_name == 'new' || (action_name == 'show' && params[:id] == 'start') }
    end

    include Effective::WizardController

    before_action :redirect_unless_registerable, only: [:new, :show]
    before_action :expire_ticket_selection_window, only: [:show]

    resource_scope -> {
      event = Effective::Event.find(params[:event_id])
      EffectiveEvents.EventRegistration.deep.where(owner: current_user, event: event)
    }

    # If the event is no longer registerable, do not let them continue
    def redirect_unless_registerable
      return if resource.blank?
      return if resource.was_submitted?
      return if resource.event.blank?
      return if resource.submit_order&.deferred?
      return if resource.event.registerable? && !resource.event.sold_out?(except: resource)

      flash[:danger] = "Your selected event is no longer available for registration. This event registration is no longer available."
      return redirect_to('/dashboard')
    end

    def expire_ticket_selection_window
      return if resource.blank?
      return if resource.was_submitted?
      return if resource.event.blank?
      return if resource.selection_not_expired?

      resource.ticket_selection_expired!

      flash[:danger] = "Your ticket reservation window has expired. Your tickets are no longer reserved. Please start over."

      return redirect_to(wizard_path(:start))
    end

    # TODO: Add better permitted params

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
effective_events-0.20.5 app/controllers/effective/event_registrations_controller.rb
effective_events-0.20.4 app/controllers/effective/event_registrations_controller.rb
effective_events-0.20.3 app/controllers/effective/event_registrations_controller.rb
effective_events-0.20.2 app/controllers/effective/event_registrations_controller.rb
effective_events-0.20.1 app/controllers/effective/event_registrations_controller.rb
effective_events-0.20.0 app/controllers/effective/event_registrations_controller.rb