2013-01-07 09:04:09 +01:00
|
|
|
class Track < ActiveRecord::Base
|
2017-01-04 22:27:46 -05:00
|
|
|
include RevisionCount
|
2017-06-08 12:25:33 +03:00
|
|
|
|
|
|
|
|
resourcify :roles, dependent: :delete_all
|
|
|
|
|
|
2015-10-25 13:29:02 +02:00
|
|
|
belongs_to :program
|
2017-06-08 12:25:33 +03:00
|
|
|
belongs_to :submitter, class_name: 'User'
|
2014-12-18 13:38:40 +01:00
|
|
|
has_many :events, dependent: :nullify
|
2013-01-07 09:04:09 +01:00
|
|
|
|
2016-05-24 23:54:46 +05:30
|
|
|
has_paper_trail only: [:name, :description, :color], meta: { conference_id: :conference_id }
|
|
|
|
|
|
2013-01-07 09:04:09 +01:00
|
|
|
before_create :generate_guid
|
2014-12-05 16:04:34 +01:00
|
|
|
validates :name, presence: true
|
2016-07-04 17:53:21 +02:00
|
|
|
validates :color, format: /\A#[0-9A-F]{6}\z/
|
2017-06-29 23:39:56 +03:00
|
|
|
validates :short_name,
|
|
|
|
|
presence: true,
|
|
|
|
|
format: /\A[a-zA-Z0-9_-]*\z/,
|
|
|
|
|
uniqueness: {
|
|
|
|
|
scope: :program
|
|
|
|
|
}
|
2017-06-08 12:25:33 +03:00
|
|
|
validates :state, presence: true, if: :self_organized?
|
|
|
|
|
validates :cfp_active, inclusion: { in: [true, false] }, if: :self_organized?
|
2016-07-04 17:53:21 +02:00
|
|
|
|
|
|
|
|
before_validation :capitalize_color
|
2013-01-07 09:04:09 +01:00
|
|
|
|
2017-06-08 12:25:33 +03:00
|
|
|
after_create :create_organizer_role, if: :self_organized?
|
|
|
|
|
|
2017-01-04 22:27:46 -05:00
|
|
|
def conference
|
|
|
|
|
program.conference
|
|
|
|
|
end
|
|
|
|
|
|
2017-06-08 12:25:33 +03:00
|
|
|
##
|
|
|
|
|
# Checks if the track is self-organized
|
|
|
|
|
# ====Returns
|
|
|
|
|
# * +true+ -> If the track has a submitter
|
|
|
|
|
# * +false+ -> if the track doesn't have a submitter
|
|
|
|
|
def self_organized?
|
|
|
|
|
return true if submitter
|
|
|
|
|
false
|
|
|
|
|
end
|
|
|
|
|
|
2013-01-07 09:04:09 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def generate_guid
|
2014-06-23 19:07:50 +03:00
|
|
|
guid = SecureRandom.urlsafe_base64
|
|
|
|
|
# begin
|
|
|
|
|
# guid = SecureRandom.urlsafe_base64
|
|
|
|
|
# end while Person.where(:guid => guid).exists?
|
2013-01-07 09:04:09 +01:00
|
|
|
self.guid = guid
|
|
|
|
|
end
|
2016-07-04 17:53:21 +02:00
|
|
|
|
|
|
|
|
def capitalize_color
|
|
|
|
|
self.color = color.upcase if color.present?
|
|
|
|
|
end
|
2016-05-24 23:54:46 +05:30
|
|
|
|
|
|
|
|
def conference_id
|
|
|
|
|
program.conference_id
|
|
|
|
|
end
|
2017-06-08 12:25:33 +03:00
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Creates the role of the track organizer
|
|
|
|
|
def create_organizer_role
|
|
|
|
|
Role.where(name: 'track_organizer', resource: self).first_or_create(description: 'For the organizers of the Track')
|
|
|
|
|
end
|
2014-06-30 17:07:53 +02:00
|
|
|
end
|