osem-fcy/app/models/booth.rb
AEtherC0r3 efaf07178f Upgrade to Rails 5
Update config with rails app:update
Update schema.rb rails db:migrate
Add puma
Make jobs and models inherit from ApplicationJob and ApplicationRecord
Update acts_as_list to 0.9.7 in order to fix
"undefined method `sanitize_sql_hash_for_conditions'" error
Update web-console to 2.3.0 to fix a 500 internal server error
Replace before_filter with before_action
Add rails-controller-testing gem
Add prepend: :true to protect_from_forgery in ApplicationController to
avoid ActionController::InvalidAuthenticityToken exceptions
Remove activeuuid
Update formtastic to 3.1.5 to fix deprecation warnings and issues
with the Input class
Update ahoy_matey to 1.6.0
Update cancancan to 2.0.0 to fix issues with malformed sql queries
Fix program spec
Fix issue with the picture being nil in admin/Organizations#new and #edit
and Organizations#show
Fix ActiveRecord::Base.raise_in_transactional_callbacks= deprecation
warning by removing an unnecessary line in application.rb
Fix failing versions specs
2017-12-11 20:58:04 +02:00

83 lines
2.4 KiB
Ruby

class Booth < ApplicationRecord
include ActiveRecord::Transitions
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
belongs_to :conference
has_many :booth_requests, dependent: :destroy
has_many :users, through: :booth_requests
has_one :submitter_booth_user, -> { where(role: 'submitter') }, class_name: 'BoothRequest'
has_one :submitter, through: :submitter_booth_user, source: :user
has_many :responsibles_booth_user, -> { where(role: 'responsible') }, class_name: 'BoothRequest'
has_many :responsibles, through: :responsibles_booth_user, source: :user
validates :title,
uniqueness: { case_sensitive: false },
presence: true
validates :description,
:reasoning,
:state,
:responsibles,
:conference_id,
:website_url,
:submitter_relationship,
presence: true
scope :accepted, -> { where(state: 'accepted') }
scope :confirmed, -> { where(state: 'confirmed') }
mount_uploader :picture, PictureUploader, mount_on: :logo_link
state_machine initial: :new do
state :new
state :withdrawn
state :to_accept
state :accepted
state :to_reject
state :rejected
state :canceled
state :confirmed
event :restart do
transitions to: :new, from: [:withdrawn, :rejected, :canceled]
end
event :withdraw do
transitions to: :withdrawn, from: [:new, :to_accept, :accepted, :to_reject, :rejected, :confirmed]
end
event :confirm do
transitions to: :confirmed, from: [:accepted]
end
event :to_accept do
transitions to: :to_accept, from: [:new, :to_reject]
end
event :to_reject do
transitions to: :to_reject, from: [:new, :to_accept]
end
event :accept do
transitions to: :accepted, from: [:new, :to_accept]
end
event :reject do
transitions to: :rejected, from: [:new, :to_reject]
end
event :cancel do
transitions to: :canceled, from: [:accepted, :rejected, :to_accept, :to_reject, :confirmed]
end
end
def transition_possible?(transition)
self.class.state_machine.events_for(current_state).include?(transition)
end
def update_state(transition, _notice)
alert = ''
begin
send(transition)
save
rescue Transitions::InvalidTransition => e
alert = "Update state failed. #{e.message}"
end
alert
end
end