First checkin
This commit is contained in:
parent
f207e2c8b7
commit
90b30db9e8
260 changed files with 37349 additions and 0 deletions
0
app/models/.gitkeep
Normal file
0
app/models/.gitkeep
Normal file
28
app/models/ability.rb
Normal file
28
app/models/ability.rb
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
class Ability
|
||||
include CanCan::Ability
|
||||
|
||||
def initialize(user)
|
||||
# Define abilities for the passed in user here. For example:
|
||||
#
|
||||
# user ||= User.new # guest user (not logged in)
|
||||
# if user.admin?
|
||||
# can :manage, :all
|
||||
# else
|
||||
# can :read, :all
|
||||
# end
|
||||
#
|
||||
# The first argument to `can` is the action you are giving the user permission to do.
|
||||
# If you pass :manage it will apply to every action. Other common actions here are
|
||||
# :read, :create, :update and :destroy.
|
||||
#
|
||||
# The second argument is the resource the user can perform the action on. If you pass
|
||||
# :all it will apply to every resource. Otherwise pass a Ruby class of the resource.
|
||||
#
|
||||
# The third argument is an optional hash of conditions to further filter the objects.
|
||||
# For example, here the user can only update published articles.
|
||||
#
|
||||
# can :update, Article, :published => true
|
||||
#
|
||||
# See the wiki for details: https://github.com/ryanb/cancan/wiki/Defining-Abilities
|
||||
end
|
||||
end
|
||||
17
app/models/admin_ability.rb
Normal file
17
app/models/admin_ability.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
class AdminAbility
|
||||
include CanCan::Ability
|
||||
|
||||
def initialize(user)
|
||||
@user = user || User.new # for guest
|
||||
@user.get_roles.each { |role| send(role.name.downcase) }
|
||||
end
|
||||
|
||||
def organizer
|
||||
can :manage, Event
|
||||
end
|
||||
|
||||
def admin
|
||||
organizer
|
||||
can :manage, :all
|
||||
end
|
||||
end
|
||||
7
app/models/call_for_papers.rb
Normal file
7
app/models/call_for_papers.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class CallForPapers < ActiveRecord::Base
|
||||
attr_accessible :start_date, :end_date, :hard_deadline, :description
|
||||
belongs_to :conference
|
||||
|
||||
validates_presence_of :start_date, :end_date, :hard_deadline
|
||||
|
||||
end
|
||||
48
app/models/comment.rb
Normal file
48
app/models/comment.rb
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
class Comment < ActiveRecord::Base
|
||||
acts_as_nested_set :scope => [:commentable_id, :commentable_type]
|
||||
attr_accessible :commentable, :body, :user_id
|
||||
validates_presence_of :body
|
||||
validates_presence_of :user
|
||||
|
||||
# NOTE: install the acts_as_votable plugin if you
|
||||
# want user to vote on the quality of comments.
|
||||
#acts_as_votable
|
||||
|
||||
belongs_to :commentable, :polymorphic => true
|
||||
|
||||
# NOTE: Comments belong to a user
|
||||
belongs_to :user
|
||||
|
||||
# Helper class method that allows you to build a comment
|
||||
# by passing a commentable object, a user_id, and comment text
|
||||
# example in readme
|
||||
def self.build_from(obj, user_id, comment)
|
||||
new \
|
||||
:commentable => obj,
|
||||
:body => comment,
|
||||
:user_id => user_id
|
||||
end
|
||||
|
||||
#helper method to check if a comment has children
|
||||
def has_children?
|
||||
self.children.any?
|
||||
end
|
||||
|
||||
# Helper class method to lookup all comments assigned
|
||||
# to all commentable types for a given user.
|
||||
scope :find_comments_by_user, lambda { |user|
|
||||
where(:user_id => user.id).order('created_at DESC')
|
||||
}
|
||||
|
||||
# Helper class method to look up all comments for
|
||||
# commentable class name and commentable id.
|
||||
scope :find_comments_for_commentable, lambda { |commentable_str, commentable_id|
|
||||
where(:commentable_type => commentable_str.to_s, :commentable_id => commentable_id).order('created_at DESC')
|
||||
}
|
||||
|
||||
# Helper class method to look up a commentable object
|
||||
# given the commentable class name and id
|
||||
def self.find_commentable(commentable_str, commentable_id)
|
||||
commentable_str.constantize.find(commentable_id)
|
||||
end
|
||||
end
|
||||
87
app/models/conference.rb
Normal file
87
app/models/conference.rb
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
class Conference < ActiveRecord::Base
|
||||
attr_accessible :title, :short_title, :social_tag, :contact_email, :timezone, :html_export_path,
|
||||
:start_date, :end_date, :rooms_attributes, :tracks_attributes, :cfp_open, :registration_open,
|
||||
:event_types_attributes
|
||||
|
||||
has_one :call_for_papers, :dependent => :destroy
|
||||
has_many :events, :dependent => :destroy
|
||||
has_many :event_types, :dependent => :destroy
|
||||
has_many :tracks, :dependent => :destroy
|
||||
has_many :rooms, :dependent => :destroy
|
||||
has_many :registrations, :dependent => :destroy
|
||||
|
||||
belongs_to :venue
|
||||
|
||||
accepts_nested_attributes_for :rooms, :reject_if => proc {|r| r["name"].blank?}, :allow_destroy => true
|
||||
accepts_nested_attributes_for :tracks, :reject_if => proc {|r| r["name"].blank?}, :allow_destroy => true
|
||||
accepts_nested_attributes_for :venue
|
||||
accepts_nested_attributes_for :event_types, :allow_destroy => true
|
||||
|
||||
validates_presence_of :title,
|
||||
:short_title,
|
||||
:social_tag
|
||||
validates_uniqueness_of :short_title
|
||||
validates_format_of :short_title, :with => /^[a-zA-Z0-9_-]*$/
|
||||
before_create :generate_guid
|
||||
before_create :create_venue
|
||||
|
||||
|
||||
def self.current
|
||||
self.order("created_at DESC").first
|
||||
end
|
||||
|
||||
def date_range_string
|
||||
startstr = "Unknown - "
|
||||
endstr = "Unknown"
|
||||
if start_date.month == end_date.month && start_date.year == end_date.year
|
||||
startstr = start_date.strftime("%B %d - ")
|
||||
endstr = end_date.strftime("%d, %Y")
|
||||
elsif start_date.month != end_date.month && start_date.year == end_date.year
|
||||
startstr = start_date.strftime("%B %d - ")
|
||||
endstr = end_date.strftime("%B %d, %Y")
|
||||
else
|
||||
startstr = start_date.strftime("%B %d, %Y - ")
|
||||
endstr = end_date.strftime("%B %d, %Y")
|
||||
end
|
||||
|
||||
result = startstr + endstr
|
||||
result
|
||||
end
|
||||
|
||||
def user_registered? user
|
||||
return nil if user.nil?
|
||||
return nil if user.person.nil?
|
||||
|
||||
if self.registrations.where(:person_id => user.person.id).count == 0
|
||||
Rails.logger.debug("Returning false")
|
||||
false
|
||||
else
|
||||
Rails.logger.debug("Returning true")
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
def cfp_open?
|
||||
today = Date.current
|
||||
cfp = self.call_for_papers
|
||||
if !cfp.nil? && (cfp.start_date.. cfp.end_date).cover?(today)
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
private
|
||||
|
||||
def create_venue
|
||||
self.venue_id = Venue.create.id
|
||||
true
|
||||
end
|
||||
|
||||
def generate_guid
|
||||
begin
|
||||
guid = SecureRandom.urlsafe_base64
|
||||
end while Person.where(:guid => guid).exists?
|
||||
self.guid = guid
|
||||
end
|
||||
|
||||
end
|
||||
101
app/models/event.rb
Normal file
101
app/models/event.rb
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
class Event < ActiveRecord::Base
|
||||
include ActiveRecord::Transitions
|
||||
|
||||
attr_accessible :title, :subtitle, :abstract, :description, :event_type_id, :people_attributes, :person,
|
||||
:proposal_additional_speakers
|
||||
acts_as_commentable
|
||||
|
||||
has_many :event_people, :dependent => :destroy
|
||||
has_many :event_attachments, :dependent => :destroy
|
||||
has_many :people, :through => :event_people
|
||||
belongs_to :event_type
|
||||
|
||||
belongs_to :track
|
||||
belongs_to :room
|
||||
belongs_to :conference
|
||||
|
||||
accepts_nested_attributes_for :event_people
|
||||
accepts_nested_attributes_for :event_attachments, :allow_destroy => true, :reject_if => :all_blank
|
||||
accepts_nested_attributes_for :people
|
||||
before_create :generate_guid
|
||||
validate :abstract_limit
|
||||
|
||||
state_machine :initial => :new do
|
||||
state :new
|
||||
state :review
|
||||
state :withdrawn
|
||||
state :accepted
|
||||
state :unconfirmed
|
||||
state :confirmed
|
||||
state :canceled
|
||||
state :rejected
|
||||
|
||||
event :start_review do
|
||||
transitions :to => :review, :from => [:new, :rejected]
|
||||
end
|
||||
event :withdraw do
|
||||
transitions :to => :withdrawn, :from => [:new, :review, :unconfirmed]
|
||||
end
|
||||
event :accept do
|
||||
transitions :to => :unconfirmed, :from => [:new, :review], :on_transition => :process_acceptance
|
||||
end
|
||||
event :unconfirm do
|
||||
transitions :to => :review, :from=>[:confirmed]
|
||||
end
|
||||
event :confirm do
|
||||
transitions :to => :confirmed, :from => :unconfirmed
|
||||
end
|
||||
event :cancel do
|
||||
transitions :to => :canceled, :from => [:unconfirmed, :confirmed]
|
||||
end
|
||||
event :reject do
|
||||
transitions :to => :rejected, :from => [:new, :review], :on_transition => :process_rejection
|
||||
end
|
||||
end
|
||||
|
||||
def submitter
|
||||
result = self.event_people.where(:event_role => "submitter").first
|
||||
if !result.nil?
|
||||
result.person
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def transition_possible?(transition)
|
||||
self.class.state_machine.events_for(self.current_state).include?(transition)
|
||||
end
|
||||
|
||||
def process_acceptance(options)
|
||||
# if options[:send_mail]
|
||||
# self.event_people.presenter.each do |event_person|
|
||||
# event_person.generate_token!
|
||||
# SelectionNotification.acceptance_notification(event_person).deliver
|
||||
# end
|
||||
# end
|
||||
|
||||
end
|
||||
|
||||
def abstract_word_count
|
||||
if self.abstract.nil?
|
||||
0
|
||||
else
|
||||
self.abstract.split.size
|
||||
end
|
||||
end
|
||||
private
|
||||
|
||||
def abstract_limit
|
||||
if self.abstract.split.size > 250
|
||||
errors.add(:abstract, "cannot have more than 250 words")
|
||||
end
|
||||
end
|
||||
|
||||
def generate_guid
|
||||
begin
|
||||
guid = SecureRandom.urlsafe_base64
|
||||
end while self.class.where(:guid => guid).exists?
|
||||
self.guid = guid
|
||||
end
|
||||
|
||||
end
|
||||
28
app/models/event_attachment.rb
Normal file
28
app/models/event_attachment.rb
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
class EventAttachment < ActiveRecord::Base
|
||||
belongs_to :event
|
||||
scope :public, where(:public => true)
|
||||
attr_accessible :public, :attachment, :event_id, :title
|
||||
|
||||
has_attached_file :attachment, :path => ":rails_root/storage/:rails_env/attachments/:id/:style/:basename.:extension"
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
def to_jq_upload
|
||||
{
|
||||
"name" => read_attribute(:attachment_file_name),
|
||||
"size" => read_attribute(:attachment_file_size),
|
||||
"title" => read_attribute(:title),
|
||||
"public" => read_attribute(:public),
|
||||
#"url" => attachment.url(:original),
|
||||
"url" => conference_proposal_event_attachment_path(self.event.conference.short_title, self.event_id, self.id),
|
||||
"delete_url" => conference_proposal_event_attachment_path(self.event.conference.short_title, self.event_id, self.id),
|
||||
"delete_type" => "DELETE"
|
||||
}
|
||||
|
||||
end
|
||||
#:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
|
||||
# :url => "/system/:attachment/:id/:style/:filename"
|
||||
|
||||
#has_paper_trail :meta => {:associated_id => :event_id, :associated_type => "Event"}
|
||||
|
||||
|
||||
end
|
||||
8
app/models/event_person.rb
Normal file
8
app/models/event_person.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
class EventPerson < ActiveRecord::Base
|
||||
attr_accessible :event, :person, :person_id, :event_role
|
||||
# TODO Do we need these roles?
|
||||
ROLES = [["Speaker","speaker"], ["Submitter","submitter"], ["Moderator","moderator"]]
|
||||
|
||||
belongs_to :event
|
||||
belongs_to :person
|
||||
end
|
||||
5
app/models/event_type.rb
Normal file
5
app/models/event_type.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class EventType < ActiveRecord::Base
|
||||
attr_accessible :title, :length
|
||||
|
||||
belongs_to :conference
|
||||
end
|
||||
71
app/models/person.rb
Normal file
71
app/models/person.rb
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
class Person < ActiveRecord::Base
|
||||
attr_accessible :email, :first_name, :last_name, :public_name, :biography, :company
|
||||
|
||||
has_many :event_people, :dependent => :destroy
|
||||
has_many :events, :through => :event_people, :uniq => true
|
||||
has_many :registrations, :dependent => :destroy
|
||||
validates :first_name, :presence => true
|
||||
validates :last_name, :presence => true
|
||||
validate :biography_limit
|
||||
|
||||
before_create :generate_guid
|
||||
before_save :set_public_name
|
||||
|
||||
def to_s
|
||||
if self.public_name.empty?
|
||||
self.first_name + " " + self.last_name
|
||||
else
|
||||
self.public_name
|
||||
end
|
||||
end
|
||||
|
||||
def withdraw_proposal id
|
||||
proposal = self.events.find_by_id(id)
|
||||
if !proposal.nil?
|
||||
proposal.withdraw
|
||||
proposal.save
|
||||
end
|
||||
end
|
||||
|
||||
def attending_conference? conference
|
||||
Registration.where(:conference_id => conference.id,
|
||||
:person_id => self.id).count
|
||||
end
|
||||
|
||||
def proposals conference
|
||||
self.events.where("conference_id = ? AND state != ? AND state != ?", conference.id, "withdrawn", "rejected")
|
||||
end
|
||||
|
||||
def proposal_count conference
|
||||
proposals(conference).count
|
||||
end
|
||||
|
||||
def biography_word_count
|
||||
if self.biography.nil?
|
||||
0
|
||||
else
|
||||
self.biography.split.size
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def biography_limit
|
||||
if self.biography.split.size > 150
|
||||
errors.add(:abstract, "cannot have more than 150 words")
|
||||
end
|
||||
end
|
||||
|
||||
def set_public_name
|
||||
if public_name.empty?
|
||||
self.public_name = "#{first_name} #{last_name}"
|
||||
end
|
||||
end
|
||||
|
||||
def generate_guid
|
||||
begin
|
||||
guid = SecureRandom.urlsafe_base64
|
||||
end while Person.where(:guid => guid).exists?
|
||||
self.guid = guid
|
||||
end
|
||||
|
||||
end
|
||||
9
app/models/registration.rb
Normal file
9
app/models/registration.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
class Registration < ActiveRecord::Base
|
||||
belongs_to :person
|
||||
belongs_to :conference
|
||||
|
||||
attr_accessible :person_id, :conference_id, :attending_social_events, :attending_social_events_with_partner,
|
||||
:using_affiliated_lodging, :arrival, :departure, :person_attributes
|
||||
accepts_nested_attributes_for :person
|
||||
|
||||
end
|
||||
4
app/models/role.rb
Normal file
4
app/models/role.rb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
class Role < ActiveRecord::Base
|
||||
attr_accessible :name
|
||||
has_and_belongs_to_many :users
|
||||
end
|
||||
18
app/models/room.rb
Normal file
18
app/models/room.rb
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
class Room < ActiveRecord::Base
|
||||
attr_accessible :name, :size, :public
|
||||
|
||||
belongs_to :conference
|
||||
has_many :events
|
||||
|
||||
before_create :generate_guid
|
||||
|
||||
private
|
||||
|
||||
def generate_guid
|
||||
begin
|
||||
guid = SecureRandom.urlsafe_base64
|
||||
end while Person.where(:guid => guid).exists?
|
||||
self.guid = guid
|
||||
end
|
||||
|
||||
end
|
||||
17
app/models/track.rb
Normal file
17
app/models/track.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
class Track < ActiveRecord::Base
|
||||
attr_accessible :name, :description, :color
|
||||
|
||||
belongs_to :conference
|
||||
|
||||
before_create :generate_guid
|
||||
|
||||
private
|
||||
|
||||
def generate_guid
|
||||
begin
|
||||
guid = SecureRandom.urlsafe_base64
|
||||
end while Person.where(:guid => guid).exists?
|
||||
self.guid = guid
|
||||
end
|
||||
|
||||
end
|
||||
55
app/models/user.rb
Normal file
55
app/models/user.rb
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
class User < ActiveRecord::Base
|
||||
|
||||
# Include default devise modules. Others available are:
|
||||
# :token_authenticatable, :confirmable,
|
||||
# :lockable, :timeoutable and :omniauthable
|
||||
devise :database_authenticatable, :registerable,
|
||||
:recoverable, :rememberable, :trackable, :validatable
|
||||
|
||||
has_and_belongs_to_many :roles
|
||||
has_one :person
|
||||
|
||||
attr_accessible :email, :password, :password_confirmation, :remember_me, :role_id, :role_ids, :person_attributes
|
||||
accepts_nested_attributes_for :person
|
||||
accepts_nested_attributes_for :roles
|
||||
|
||||
before_save :setup_role
|
||||
before_create :create_person
|
||||
|
||||
def role?(role)
|
||||
Rails.logger.debug("Checking role in user")
|
||||
return !!self.roles.find_by_name(role.to_s.camelize)
|
||||
end
|
||||
|
||||
def get_roles
|
||||
return self.roles
|
||||
end
|
||||
|
||||
def setup_role
|
||||
if self.role_ids.empty?
|
||||
self.role_ids = [1]
|
||||
end
|
||||
end
|
||||
|
||||
def popup_details
|
||||
details = "<b>Sign-in Count</b><br>"
|
||||
details += "#{self.sign_in_count}<br>"
|
||||
details += "<b>Current Sign-in</b><br>"
|
||||
details += "#{self.current_sign_in_at}<br>"
|
||||
details += "<b>Last Sign-in</b><br>"
|
||||
details += "#{self.last_sign_in_at}<br>"
|
||||
details += "<b>Current Sign-in IP</b><br>"
|
||||
details += "#{self.current_sign_in_ip}<br>"
|
||||
details += "<b>Last Sign-in IP</b><br>"
|
||||
details += "#{self.last_sign_in_ip}<br>"
|
||||
details += "<b>Created at</b><br>"
|
||||
details += "#{self.created_at}<br>"
|
||||
end
|
||||
|
||||
private
|
||||
def create_person
|
||||
# TODO Search people for existing email address, add to their account
|
||||
build_person(:email => self.email)
|
||||
true
|
||||
end
|
||||
end
|
||||
14
app/models/venue.rb
Normal file
14
app/models/venue.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
class Venue < ActiveRecord::Base
|
||||
has_many :conferences
|
||||
before_create :generate_guid
|
||||
|
||||
private
|
||||
|
||||
def generate_guid
|
||||
begin
|
||||
guid = SecureRandom.urlsafe_base64
|
||||
end while Venue.where(:guid => guid).exists?
|
||||
self.guid = guid
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue