mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
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
89 lines
3.1 KiB
Ruby
89 lines
3.1 KiB
Ruby
class EventSchedule < ApplicationRecord
|
|
belongs_to :schedule
|
|
belongs_to :event
|
|
belongs_to :room
|
|
|
|
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
|
|
|
|
validates :schedule, presence: true
|
|
validates :event, presence: true
|
|
validates :room, presence: true
|
|
validates :start_time, presence: true
|
|
validates :event, uniqueness: { scope: :schedule }
|
|
validate :start_after_end_hour
|
|
validate :start_before_start_hour
|
|
validate :same_room_as_track
|
|
validate :during_track
|
|
validate :valid_schedule
|
|
|
|
scope :confirmed, -> { joins(:event).where('state = ?', 'confirmed') }
|
|
scope :canceled, -> { joins(:event).where('state = ?', 'canceled') }
|
|
scope :withdrawn, -> { joins(:event).where('state = ?', 'withdrawn') }
|
|
|
|
delegate :guid, to: :room, prefix: true
|
|
|
|
##
|
|
# Returns end of the event
|
|
#
|
|
def end_time
|
|
start_time + event.event_type.length.minutes
|
|
end
|
|
|
|
##
|
|
# Returns event schedules that are scheduled in the same room and start_time as event
|
|
#
|
|
def intersecting_event_schedules
|
|
room.event_schedules.where(start_time: start_time, schedule: schedule).where.not(id: id)
|
|
end
|
|
|
|
def replacement?
|
|
event.state == 'confirmed' && (!intersecting_event_schedules.canceled.empty? || !intersecting_event_schedules.withdrawn.empty?)
|
|
end
|
|
|
|
private
|
|
|
|
def start_after_end_hour
|
|
return unless event && start_time && event.program && event.program.conference && event.program.conference.end_hour
|
|
errors.add(:start_time, "can't be after the conference end hour (#{event.program.conference.end_hour})") if start_time.hour >= event.program.conference.end_hour
|
|
end
|
|
|
|
def start_before_start_hour
|
|
return unless event && start_time && event.program && event.program.conference && event.program.conference.start_hour
|
|
errors.add(:start_time, "can't be before the conference start hour (#{event.program.conference.start_hour})") if start_time.hour < event.program.conference.start_hour
|
|
end
|
|
|
|
def conference_id
|
|
schedule.program.conference_id
|
|
end
|
|
|
|
##
|
|
# Validates that the event is scheduled in the same room as its track
|
|
#
|
|
def same_room_as_track
|
|
return unless event.try(:track).try(:room)
|
|
errors.add(:room, "must be the same as the track's room (#{event.track.room.name})") unless event.track.room == room
|
|
end
|
|
|
|
##
|
|
# Validates that the event is scheduled within its track's time slot
|
|
#
|
|
def during_track
|
|
return unless event.try(:track) && start_time
|
|
|
|
if event.track.try(:start_date) && event.track.start_date > start_time
|
|
errors.add(:start_time, "can't be before the track's start date (#{event.track.start_date})")
|
|
end
|
|
|
|
if event.track.try(:end_date) && event.track.end_date + 1.day < end_time
|
|
errors.add(:end_time, "can't be after the track's end date (#{event.track.end_date})")
|
|
end
|
|
end
|
|
|
|
##
|
|
# Validates that the event is scheduled in its self-organized tracks's schedules
|
|
#
|
|
def valid_schedule
|
|
return unless event.try(:track).try(:self_organized?) && schedule
|
|
errors.add(:schedule, "must be one of #{event.track.name} track's schedules") unless event.track.schedules.include?(schedule)
|
|
end
|
|
end
|