Rebuild rubocop TODOs after auto-correcting
This commit is contained in:
parent
31c50255e9
commit
84dbb52d11
580 changed files with 3689 additions and 3133 deletions
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Ability
|
||||
include CanCan::Ability
|
||||
|
||||
|
|
@ -15,7 +17,7 @@ class Ability
|
|||
|
||||
# Abilities for not signed in users (guests)
|
||||
def not_signed_in
|
||||
can [:index, :conferences], Organization
|
||||
can %i[index conferences], Organization
|
||||
can [:index], Conference
|
||||
can [:show], Conference do |conference|
|
||||
conference.splashpage && conference.splashpage.public == true
|
||||
|
|
@ -31,20 +33,16 @@ class Ability
|
|||
|
||||
# can view Commercials of confirmed Events
|
||||
can :show, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(state: 'confirmed').pluck(:id)
|
||||
can [:show, :create], User
|
||||
can %i[show create], User
|
||||
unless ENV['OSEM_ICHAIN_ENABLED'] == 'true'
|
||||
can :show, Registration do |registration|
|
||||
registration.new_record?
|
||||
end
|
||||
can :show, Registration, &:new_record?
|
||||
|
||||
can [:new, :create], Registration do |registration|
|
||||
conference = registration.conference
|
||||
conference.registration_open? && registration.new_record? && !conference.registration_limit_exceeded?
|
||||
end
|
||||
|
||||
can :show, Event do |event|
|
||||
event.new_record?
|
||||
end
|
||||
can :show, Event, &:new_record?
|
||||
|
||||
can [:new, :create], Event do |event|
|
||||
event.program.cfp_open? && event.new_record?
|
||||
|
|
@ -78,8 +76,8 @@ class Ability
|
|||
can :index, Organization
|
||||
can :index, Ticket
|
||||
can :manage, TicketPurchase, user_id: user.id
|
||||
can [:new, :create], Payment, user_id: user.id
|
||||
can [:index, :show], PhysicalTicket, user: user
|
||||
can %i[new create], Payment, user_id: user.id
|
||||
can %i[index show], PhysicalTicket, user: user
|
||||
|
||||
can [:new, :create], Booth do |booth|
|
||||
booth.new_record? && booth.conference.program.cfps.for_booths.try(:open?)
|
||||
|
|
@ -89,7 +87,7 @@ class Ability
|
|||
booth.users.include?(user)
|
||||
end
|
||||
|
||||
can [:create, :destroy], Subscription, user_id: user.id
|
||||
can %i[create destroy], Subscription, user_id: user.id
|
||||
|
||||
can [:new, :create], Event do |event|
|
||||
event.program.cfp_open? && event.new_record?
|
||||
|
|
@ -108,7 +106,7 @@ class Ability
|
|||
track.new_record? && track.program.cfps.for_tracks.try(:open?)
|
||||
end
|
||||
|
||||
can [:index, :show, :restart, :confirm, :withdraw], Track, submitter_id: user.id
|
||||
can %i[index show restart confirm withdraw], Track, submitter_id: user.id
|
||||
|
||||
can [:edit, :update], Track do |track|
|
||||
user == track.submitter && !(track.accepted? || track.confirmed?)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AdminAbility
|
||||
include CanCan::Ability
|
||||
|
||||
|
|
@ -28,12 +30,12 @@ class AdminAbility
|
|||
conference.registration_open? && !conference.registration_limit_exceeded? || conference.program.speakers.confirmed.include?(user)
|
||||
end
|
||||
|
||||
can [:index, :admins], Organization
|
||||
can %i[index admins], Organization
|
||||
can :index, Ticket
|
||||
can :manage, TicketPurchase, user_id: user.id
|
||||
can [:new, :create], Payment, user_id: user.id
|
||||
can %i[new create], Payment, user_id: user.id
|
||||
|
||||
can [:create, :destroy], Subscription, user_id: user.id
|
||||
can %i[create destroy], Subscription, user_id: user.id
|
||||
|
||||
can [:new, :create], Event do |event|
|
||||
event.program.cfp_open? && event.new_record?
|
||||
|
|
@ -45,11 +47,11 @@ class AdminAbility
|
|||
can [:destroy], Openid
|
||||
can :access, Admin
|
||||
can :index, Commercial, commercialable_type: 'Conference'
|
||||
cannot [:edit, :update, :destroy], Question, global: true
|
||||
cannot %i[edit update destroy], Question, global: true
|
||||
# for admins
|
||||
can :manage, :all if user.is_admin
|
||||
# even admin cannot create new users with ICHAIN enabled
|
||||
cannot [:new, :create], User if ENV['OSEM_ICHAIN_ENABLED'] == 'true'
|
||||
cannot %i[new create], User if ENV['OSEM_ICHAIN_ENABLED'] == 'true'
|
||||
cannot :revert_object, PaperTrail::Version do |version|
|
||||
(version.event == 'create' && %w[Conference User Event].include?(version.item_type))
|
||||
end
|
||||
|
|
@ -67,9 +69,7 @@ class AdminAbility
|
|||
end
|
||||
|
||||
# Prevent requests for tracks from being destroyed
|
||||
cannot :destroy, Track do |track|
|
||||
track.self_organized?
|
||||
end
|
||||
cannot :destroy, Track, &:self_organized?
|
||||
# Can't accept a booth when booth_limit is reached
|
||||
cannot :accept, Booth do |booth|
|
||||
conference = booth.conference
|
||||
|
|
@ -92,10 +92,10 @@ class AdminAbility
|
|||
org_ids_for_organization_admin = Organization.with_role(:organization_admin, user).pluck(:id)
|
||||
conf_ids_for_organization_admin = Conference.where(organization_id: org_ids_for_organization_admin).pluck(:id)
|
||||
|
||||
can [:read, :update, :destroy, :assign_org_admins, :unassign_org_admins, :admins], Organization, id: org_ids_for_organization_admin
|
||||
can %i[read update destroy assign_org_admins unassign_org_admins admins], Organization, id: org_ids_for_organization_admin
|
||||
can :new, Conference
|
||||
can :manage, Conference, organization_id: org_ids_for_organization_admin
|
||||
can [:index, :show], Role
|
||||
can %i[index show], Role
|
||||
|
||||
signed_in_with_organizer_role(user, conf_ids_for_organization_admin)
|
||||
end
|
||||
|
|
@ -108,7 +108,7 @@ class AdminAbility
|
|||
track_ids = Track.joins(:program).where('programs.conference_id IN (?)', conf_ids).pluck(:id)
|
||||
|
||||
can :manage, Resource, conference_id: conf_ids
|
||||
can [:read, :update, :destroy], Conference, id: conf_ids
|
||||
can %i[read update destroy], Conference, id: conf_ids
|
||||
can :manage, Splashpage, conference_id: conf_ids
|
||||
can :manage, Contact, conference_id: conf_ids
|
||||
can :manage, EmailSettings, conference_id: conf_ids
|
||||
|
|
@ -163,8 +163,8 @@ class AdminAbility
|
|||
role.resource_type == 'Track' && (track_ids.include? role.resource_id)
|
||||
end
|
||||
|
||||
can [:index, :revert_object, :revert_attribute], PaperTrail::Version, item_type: 'User'
|
||||
can [:index, :revert_object, :revert_attribute], PaperTrail::Version, conference_id: conf_ids
|
||||
can %i[index revert_object revert_attribute], PaperTrail::Version, item_type: 'User'
|
||||
can %i[index revert_object revert_attribute], PaperTrail::Version, conference_id: conf_ids
|
||||
end
|
||||
|
||||
def signed_in_with_cfp_role(user)
|
||||
|
|
@ -174,7 +174,7 @@ class AdminAbility
|
|||
can :show, Conference do |conf|
|
||||
conf_ids_for_cfp.include?(conf.id)
|
||||
end
|
||||
can [:index, :show, :update], Resource, conference_id: conf_ids_for_cfp
|
||||
can %i[index show update], Resource, conference_id: conf_ids_for_cfp
|
||||
can :manage, Booth, conference_id: conf_ids_for_cfp
|
||||
can :manage, Event, program: { conference_id: conf_ids_for_cfp }
|
||||
can :manage, EventType, program: { conference_id: conf_ids_for_cfp }
|
||||
|
|
@ -203,7 +203,7 @@ class AdminAbility
|
|||
(Conference.with_role(:cfp, user).pluck(:id).include? role.resource_id)
|
||||
end
|
||||
|
||||
can [:index, :revert_object, :revert_attribute], PaperTrail::Version,
|
||||
can %i[index revert_object revert_attribute], PaperTrail::Version,
|
||||
item_type: %w[Event EventType Track DifficultyLevel EmailSettings Room Cfp Program Comment], conference_id: conf_ids_for_cfp
|
||||
can [:index, :revert_object, :revert_attribute], PaperTrail::Version,
|
||||
["item_type = 'Commercial' AND conference_id IN (?) AND (object LIKE '%Event%' OR object_changes LIKE '%Event%')", conf_ids_for_cfp] do |version|
|
||||
|
|
@ -219,7 +219,7 @@ class AdminAbility
|
|||
can :show, Conference do |conf|
|
||||
conf_ids_for_info_desk.include?(conf.id)
|
||||
end
|
||||
can [:index, :show, :update], Resource, conference_id: conf_ids_for_info_desk
|
||||
can %i[index show update], Resource, conference_id: conf_ids_for_info_desk
|
||||
can :manage, Registration, conference_id: conf_ids_for_info_desk
|
||||
can :manage, Question, conference_id: conf_ids_for_info_desk
|
||||
can :manage, Question do |question|
|
||||
|
|
@ -240,7 +240,7 @@ class AdminAbility
|
|||
role.resource_type == 'Conference' && role.name == 'info_desk' &&
|
||||
(Conference.with_role(:info_desk, user).pluck(:id).include? role.resource_id)
|
||||
end
|
||||
can [:index, :revert_object, :revert_attribute], PaperTrail::Version, item_type: 'Registration', conference_id: conf_ids_for_info_desk
|
||||
can %i[index revert_object revert_attribute], PaperTrail::Version, item_type: 'Registration', conference_id: conf_ids_for_info_desk
|
||||
end
|
||||
|
||||
def signed_in_with_volunteers_coordinator_role(user)
|
||||
|
|
@ -250,7 +250,7 @@ class AdminAbility
|
|||
can :show, Conference do |conf|
|
||||
conf_ids_for_volunteers_coordinator.include?(conf.id)
|
||||
end
|
||||
can [:index, :show, :update], Resource, conference_id: conf_ids_for_volunteers_coordinator
|
||||
can %i[index show update], Resource, conference_id: conf_ids_for_volunteers_coordinator
|
||||
can :manage, Vposition, conference_id: conf_ids_for_volunteers_coordinator
|
||||
can :manage, Vday, conference_id: conf_ids_for_volunteers_coordinator
|
||||
|
||||
|
|
@ -286,9 +286,7 @@ class AdminAbility
|
|||
|
||||
can :manage, Track, id: track_ids_for_track_organizer
|
||||
|
||||
cannot [:edit, :update], Track do |track|
|
||||
track.self_organized_and_accepted_or_confirmed?
|
||||
end
|
||||
cannot %i[edit update], Track, &:self_organized_and_accepted_or_confirmed?
|
||||
|
||||
# Show Roles in the admin sidebar and allow authorization of the index action
|
||||
can [:index, :show], Role do |role|
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Ahoy
|
||||
class Event < ApplicationRecord
|
||||
self.table_name = 'ahoy_events'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Answer < ApplicationRecord
|
||||
has_many :qanswers
|
||||
has_many :questions, through: :qanswers
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ApplicationRecord < ActiveRecord::Base
|
||||
self.abstract_class = true
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Booth < ApplicationRecord
|
||||
include ActiveRecord::Transitions
|
||||
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
|
||||
|
|
@ -41,28 +43,28 @@ class Booth < ApplicationRecord
|
|||
state :confirmed
|
||||
|
||||
event :restart do
|
||||
transitions to: :new, from: [:withdrawn, :rejected, :canceled]
|
||||
transitions to: :new, from: %i[withdrawn rejected canceled]
|
||||
end
|
||||
event :withdraw do
|
||||
transitions to: :withdrawn, from: [:new, :to_accept, :accepted, :to_reject, :rejected, :confirmed]
|
||||
transitions to: :withdrawn, from: %i[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]
|
||||
transitions to: :to_accept, from: %i[new to_reject]
|
||||
end
|
||||
event :to_reject do
|
||||
transitions to: :to_reject, from: [:new, :to_accept]
|
||||
transitions to: :to_reject, from: %i[new to_accept]
|
||||
end
|
||||
event :accept do
|
||||
transitions to: :accepted, from: [:new, :to_accept]
|
||||
transitions to: :accepted, from: %i[new to_accept]
|
||||
end
|
||||
event :reject do
|
||||
transitions to: :rejected, from: [:new, :to_reject]
|
||||
transitions to: :rejected, from: %i[new to_reject]
|
||||
end
|
||||
event :cancel do
|
||||
transitions to: :canceled, from: [:accepted, :rejected, :to_accept, :to_reject, :confirmed]
|
||||
transitions to: :canceled, from: %i[accepted rejected to_accept to_reject confirmed]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class BoothRequest < ApplicationRecord
|
||||
belongs_to :booth
|
||||
belongs_to :user
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Campaign < ApplicationRecord
|
||||
validates :name, :utm_campaign, presence: true
|
||||
|
||||
|
|
@ -66,11 +68,11 @@ class Campaign < ApplicationRecord
|
|||
# * +Hash+ -> parameter => value
|
||||
def get_parameters
|
||||
conditions = {}
|
||||
conditions[:utm_source] = self[:utm_source] unless self[:utm_source].blank?
|
||||
conditions[:utm_medium] = self[:utm_medium] unless self[:utm_medium].blank?
|
||||
conditions[:utm_term] = self[:utm_term] unless self[:utm_term].blank?
|
||||
conditions[:utm_content] = self[:utm_content] unless self[:utm_content].blank?
|
||||
conditions[:utm_campaign] = self[:utm_campaign] unless self[:utm_campaign].blank?
|
||||
conditions[:utm_source] = self[:utm_source] if self[:utm_source].present?
|
||||
conditions[:utm_medium] = self[:utm_medium] if self[:utm_medium].present?
|
||||
conditions[:utm_term] = self[:utm_term] if self[:utm_term].present?
|
||||
conditions[:utm_content] = self[:utm_content] if self[:utm_content].present?
|
||||
conditions[:utm_campaign] = self[:utm_campaign] if self[:utm_campaign].present?
|
||||
conditions
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# cannot delete program if there are events submitted
|
||||
|
||||
class Cfp < ApplicationRecord
|
||||
TYPES = %w(events booths tracks).freeze
|
||||
TYPES = %w[events booths tracks].freeze
|
||||
|
||||
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
|
||||
belongs_to :program
|
||||
|
|
@ -27,11 +29,11 @@ class Cfp < ApplicationRecord
|
|||
# * +True+ -> If cfp dates is updated and all other parameters are set
|
||||
# * +False+ -> Either cfp date is not updated or one or more parameter is not set
|
||||
def notify_on_cfp_date_update?
|
||||
!end_date.blank? && !start_date.blank?\
|
||||
end_date.present? && start_date.present?\
|
||||
&& (start_date_changed? || end_date_changed?)\
|
||||
&& program.conference.email_settings.send_on_cfp_dates_updated\
|
||||
&& !program.conference.email_settings.cfp_dates_updated_subject.blank?\
|
||||
&& !program.conference.email_settings.cfp_dates_updated_body.blank?
|
||||
&& program.conference.email_settings.cfp_dates_updated_subject.present?\
|
||||
&& program.conference.email_settings.cfp_dates_updated_body.present?
|
||||
end
|
||||
|
||||
##
|
||||
|
|
@ -106,20 +108,22 @@ class Cfp < ApplicationRecord
|
|||
private
|
||||
|
||||
def before_end_of_conference
|
||||
if program && program.conference && program.conference.end_date && end_date && (end_date > program.conference.end_date)
|
||||
if program&.conference && program.conference.end_date && end_date && (end_date > program.conference.end_date)
|
||||
errors
|
||||
.add(:end_date, "can't be after the conference end date (#{program.conference.end_date})")
|
||||
.add(:end_date, "can't be after the conference end date (#{program.conference.end_date})")
|
||||
end
|
||||
|
||||
if program && program.conference && program.conference.end_date && start_date && (start_date > program.conference.end_date)
|
||||
if program&.conference && program.conference.end_date && start_date && (start_date > program.conference.end_date)
|
||||
errors
|
||||
.add(:start_date, "can't be after the conference end date (#{program.conference.end_date})")
|
||||
.add(:start_date, "can't be after the conference end date (#{program.conference.end_date})")
|
||||
end
|
||||
end
|
||||
|
||||
def start_after_end_date
|
||||
errors
|
||||
.add(:start_date, "can't be after the end date") if start_date && end_date && start_date > end_date
|
||||
if start_date && end_date && start_date > end_date
|
||||
errors
|
||||
.add(:start_date, "can't be after the end date")
|
||||
end
|
||||
end
|
||||
|
||||
def conference_id
|
||||
|
|
|
|||
|
|
@ -1,19 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Comment < ApplicationRecord
|
||||
acts_as_nested_set scope: %i(commentable_id commentable_type)
|
||||
acts_as_nested_set scope: %i[commentable_id commentable_type]
|
||||
validates :body, presence: true
|
||||
validates :user, presence: true
|
||||
after_create :send_notification
|
||||
|
||||
# NOTE: install the acts_as_votable plugin if you
|
||||
# want user to vote on the quality of comments.
|
||||
#acts_as_votable
|
||||
# acts_as_votable
|
||||
|
||||
belongs_to :commentable, counter_cache: true, polymorphic: true
|
||||
|
||||
# NOTE: Comments belong to a user
|
||||
belongs_to :user
|
||||
|
||||
has_paper_trail on: %i(create destroy), meta: { conference_id: :conference_id }
|
||||
has_paper_trail on: %i[create destroy], meta: { conference_id: :conference_id }
|
||||
|
||||
# Helper class method that allows you to build a comment
|
||||
# by passing a commentable object, a user_id, and comment text
|
||||
|
|
@ -25,7 +27,7 @@ class Comment < ApplicationRecord
|
|||
user_id: user_id
|
||||
end
|
||||
|
||||
#helper method to check if a comment has children
|
||||
# helper method to check if a comment has children
|
||||
def has_children?
|
||||
children.any?
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Commercial < ApplicationRecord
|
||||
require 'oembed'
|
||||
|
||||
|
|
@ -6,7 +8,7 @@ class Commercial < ApplicationRecord
|
|||
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
|
||||
|
||||
validates :url, presence: true, uniqueness: { scope: :commercialable }
|
||||
validates :url, format: URI::regexp(%w(http https))
|
||||
validates :url, format: URI.regexp(%w[http https])
|
||||
|
||||
validate :valid_url
|
||||
|
||||
|
|
@ -36,9 +38,7 @@ class Commercial < ApplicationRecord
|
|||
errors[:no_event] << id && next unless event
|
||||
|
||||
commercial = event.commercials.new(url: url)
|
||||
unless commercial.save
|
||||
errors[:validation_errors] << "Could not create commercial for event with ID #{event.id} (" + commercial.errors.full_messages.to_sentence + ')'
|
||||
end
|
||||
errors[:validation_errors] << "Could not create commercial for event with ID #{event.id} (" + commercial.errors.full_messages.to_sentence + ')' unless commercial.save
|
||||
end
|
||||
errors
|
||||
end
|
||||
|
|
@ -47,9 +47,7 @@ class Commercial < ApplicationRecord
|
|||
|
||||
def valid_url
|
||||
result = Commercial.render_from_url(url)
|
||||
if result[:error]
|
||||
errors.add(:base, result[:error])
|
||||
end
|
||||
errors.add(:base, result[:error]) if result[:error]
|
||||
end
|
||||
|
||||
def self.register_provider
|
||||
|
|
@ -58,12 +56,12 @@ class Commercial < ApplicationRecord
|
|||
speakerdeck << 'http://speakerdeck.com/*'
|
||||
|
||||
OEmbed::Providers.register(
|
||||
OEmbed::Providers::Youtube,
|
||||
OEmbed::Providers::Vimeo,
|
||||
OEmbed::Providers::Slideshare,
|
||||
OEmbed::Providers::Flickr,
|
||||
OEmbed::Providers::Instagram,
|
||||
speakerdeck
|
||||
OEmbed::Providers::Youtube,
|
||||
OEmbed::Providers::Vimeo,
|
||||
OEmbed::Providers::Slideshare,
|
||||
OEmbed::Providers::Flickr,
|
||||
OEmbed::Providers::Instagram,
|
||||
speakerdeck
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module RevisionCount
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Conference < ApplicationRecord
|
||||
include RevisionCount
|
||||
require 'uri'
|
||||
|
|
@ -12,7 +14,7 @@ class Conference < ApplicationRecord
|
|||
|
||||
belongs_to :organization
|
||||
|
||||
has_paper_trail ignore: %i(updated_at guid revision events_per_week), meta: { conference_id: :id }
|
||||
has_paper_trail ignore: %i[updated_at guid revision events_per_week], meta: { conference_id: :id }
|
||||
|
||||
has_and_belongs_to_many :questions
|
||||
|
||||
|
|
@ -91,7 +93,7 @@ class Conference < ApplicationRecord
|
|||
after_create :create_free_ticket
|
||||
after_update :delete_event_schedules
|
||||
|
||||
enum ticket_layout: [:portrait, :landscape]
|
||||
enum ticket_layout: %i[portrait landscape]
|
||||
|
||||
##
|
||||
# Checks if the user is registered to the conference
|
||||
|
|
@ -101,7 +103,7 @@ class Conference < ApplicationRecord
|
|||
# ====Returns
|
||||
# * +false+ -> If the user is registered
|
||||
# * +true+ - If the user isn't registered
|
||||
def user_registered? user
|
||||
def user_registered?(user)
|
||||
user.present? && registrations.where(user_id: user.id).count > 0
|
||||
end
|
||||
|
||||
|
|
@ -112,8 +114,8 @@ class Conference < ApplicationRecord
|
|||
if start_hour_changed? || end_hour_changed?
|
||||
event_schedules = program.event_schedules.select do |event_schedule|
|
||||
event_schedule.start_time.hour < start_hour ||
|
||||
event_schedule.end_time.hour > end_hour ||
|
||||
(event_schedule.end_time.hour == end_hour && event_schedule.end_time.minute > 0)
|
||||
event_schedule.end_time.hour > end_hour ||
|
||||
(event_schedule.end_time.hour == end_hour && event_schedule.end_time.minute > 0)
|
||||
end
|
||||
event_schedules.each(&:destroy)
|
||||
end
|
||||
|
|
@ -151,7 +153,7 @@ class Conference < ApplicationRecord
|
|||
def get_submissions_per_week
|
||||
result = []
|
||||
|
||||
if program && program.cfp && program.events
|
||||
if program&.cfp && program.events
|
||||
submissions = program.events.select(:week).group(:week).order(:week).count
|
||||
start_week = program.cfp.start_week
|
||||
weeks = program.cfp.weeks
|
||||
|
|
@ -168,7 +170,7 @@ class Conference < ApplicationRecord
|
|||
# * +Array+ -> e.g. 'Submitted' => [0, 3, 3, 5] -> first week 0 events, second week 3 events.
|
||||
def get_submissions_data
|
||||
result = {}
|
||||
if program && program.cfp && program.events
|
||||
if program&.cfp && program.events
|
||||
result = get_events_per_week_by_state
|
||||
|
||||
start_week = program.cfp.start_week
|
||||
|
|
@ -196,9 +198,9 @@ class Conference < ApplicationRecord
|
|||
result = []
|
||||
|
||||
if registrations &&
|
||||
registration_period &&
|
||||
registration_period.start_date &&
|
||||
registration_period.end_date
|
||||
registration_period &&
|
||||
registration_period.start_date &&
|
||||
registration_period.end_date
|
||||
|
||||
reg = registrations.group(:week).order(:week).count
|
||||
start_week = get_registration_start_week
|
||||
|
|
@ -269,11 +271,10 @@ class Conference < ApplicationRecord
|
|||
def registration_weeks
|
||||
result = 0
|
||||
weeks = 0
|
||||
if registration_period &&
|
||||
registration_period.start_date &&
|
||||
registration_period.end_date
|
||||
if registration_period&.start_date &&
|
||||
registration_period.end_date
|
||||
weeks = Date.new(registration_period.start_date.year, 12, 31)
|
||||
.strftime('%W').to_i
|
||||
.strftime('%W').to_i
|
||||
|
||||
result = get_registration_end_week - get_registration_start_week + 1
|
||||
end
|
||||
|
|
@ -343,7 +344,7 @@ class Conference < ApplicationRecord
|
|||
tracks: tracks_set?,
|
||||
event_types: event_types_set?,
|
||||
difficulty_levels: difficulty_levels_set?,
|
||||
splashpage: splashpage && splashpage.public?
|
||||
splashpage: splashpage&.public?
|
||||
}
|
||||
|
||||
result.update(
|
||||
|
|
@ -370,8 +371,8 @@ class Conference < ApplicationRecord
|
|||
# * +hash+ -> user: submissions
|
||||
def get_top_submitter(limit = 5)
|
||||
submitter = EventUser.joins(:event).select(:user_id)
|
||||
.where('event_role = ? and program_id = ?', 'submitter', Conference.find(id).program.id)
|
||||
.limit(limit).group(:user_id)
|
||||
.where('event_role = ? and program_id = ?', 'submitter', Conference.find(id).program.id)
|
||||
.limit(limit).group(:user_id)
|
||||
counter = submitter.order('count_all desc').count(:all)
|
||||
Conference.calculate_user_submission_hash(submitter, counter)
|
||||
end
|
||||
|
|
@ -595,12 +596,12 @@ class Conference < ApplicationRecord
|
|||
# * +ActiveRecord+
|
||||
def self.get_active_conferences_for_dashboard
|
||||
result = Conference.where('start_date > ?', Time.now)
|
||||
.select('id, short_title, color, start_date, organization_id')
|
||||
.select('id, short_title, color, start_date, organization_id')
|
||||
|
||||
if result.empty?
|
||||
result = Conference
|
||||
.select('id, short_title, color, start_date, organization_id').limit(2)
|
||||
.order(start_date: :desc)
|
||||
.select('id, short_title, color, start_date, organization_id').limit(2)
|
||||
.order(start_date: :desc)
|
||||
end
|
||||
result
|
||||
end
|
||||
|
|
@ -671,9 +672,7 @@ class Conference < ApplicationRecord
|
|||
result[state.name] = count
|
||||
end
|
||||
|
||||
unless conference.events_per_week
|
||||
conference.events_per_week = {}
|
||||
end
|
||||
conference.events_per_week = {} unless conference.events_per_week
|
||||
|
||||
# Write to database
|
||||
conference.events_per_week[week] = result
|
||||
|
|
@ -785,7 +784,7 @@ class Conference < ApplicationRecord
|
|||
# the color. We make use of big prime numbers to avoid repetition and to make
|
||||
# consecutive colors clearly different.
|
||||
def next_color_component(component, i)
|
||||
big_prime_numbers = {r: 113, g: 67, b: 151}
|
||||
big_prime_numbers = { r: 113, g: 67, b: 151 }
|
||||
((i * big_prime_numbers[component]) % 239 + 16).to_s(16)
|
||||
end
|
||||
|
||||
|
|
@ -861,12 +860,9 @@ class Conference < ApplicationRecord
|
|||
# Completed weeks
|
||||
events_per_week.each do |week, values|
|
||||
values.each do |state, value|
|
||||
if %i(confirmed unconfirmed).include?(state)
|
||||
unless result[state.to_s.capitalize]
|
||||
result[state.to_s.capitalize] = {}
|
||||
end
|
||||
result[state.to_s.capitalize][week.strftime('%W').to_i] = value
|
||||
end
|
||||
next unless %i[confirmed unconfirmed].include?(state)
|
||||
result[state.to_s.capitalize] = {} unless result[state.to_s.capitalize]
|
||||
result[state.to_s.capitalize][week.strftime('%W').to_i] = value
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -923,9 +919,7 @@ class Conference < ApplicationRecord
|
|||
# * +Array+
|
||||
def pad_left(first_week, start_week)
|
||||
left = []
|
||||
if first_week > start_week
|
||||
left = Array.new(first_week - start_week - 1, 0)
|
||||
end
|
||||
left = Array.new(first_week - start_week - 1, 0) if first_week > start_week
|
||||
left
|
||||
end
|
||||
|
||||
|
|
@ -938,9 +932,7 @@ class Conference < ApplicationRecord
|
|||
def assert_keys_are_continuously(hash)
|
||||
keys = hash.keys
|
||||
(keys.min..keys.max).each do |key|
|
||||
unless hash[key]
|
||||
hash[key] = 0
|
||||
end
|
||||
hash[key] = 0 unless hash[key]
|
||||
end
|
||||
Hash[hash.sort]
|
||||
end
|
||||
|
|
@ -1048,12 +1040,11 @@ class Conference < ApplicationRecord
|
|||
|
||||
grouped.each do |event|
|
||||
object = event.send(symbol)
|
||||
if object
|
||||
result[object.title] = {
|
||||
'value' => counter[object.id],
|
||||
'color' => object.color
|
||||
}
|
||||
end
|
||||
next unless object
|
||||
result[object.title] = {
|
||||
'value' => counter[object.id],
|
||||
'color' => object.color
|
||||
}
|
||||
end
|
||||
result
|
||||
end
|
||||
|
|
@ -1067,12 +1058,11 @@ class Conference < ApplicationRecord
|
|||
def calculate_track_distribution_hash(tracks_grouped, tracks_counter)
|
||||
result = {}
|
||||
tracks_grouped.each do |event|
|
||||
if event.track
|
||||
result[event.track.name] = {
|
||||
'value' => tracks_counter[event.track_id],
|
||||
'color' => event.track.color
|
||||
}
|
||||
end
|
||||
next unless event.track
|
||||
result[event.track.name] = {
|
||||
'value' => tracks_counter[event.track_id],
|
||||
'color' => event.track.color
|
||||
}
|
||||
end
|
||||
result
|
||||
end
|
||||
|
|
@ -1127,10 +1117,10 @@ class Conference < ApplicationRecord
|
|||
result = {}
|
||||
states.each do |key, value|
|
||||
result[key.capitalize] =
|
||||
{
|
||||
'value' => value,
|
||||
'color' => Event.get_state_color(key)
|
||||
}
|
||||
{
|
||||
'value' => value,
|
||||
'color' => Event.get_state_color(key)
|
||||
}
|
||||
end
|
||||
result
|
||||
end
|
||||
|
|
@ -1145,9 +1135,7 @@ class Conference < ApplicationRecord
|
|||
counter.each do |key, value|
|
||||
# make PG happy by including the user_id in ORDER
|
||||
submitter = submitters.where(user_id: key).order(:user_id).first
|
||||
if submitter
|
||||
result[submitter.user] = value
|
||||
end
|
||||
result[submitter.user] = value if submitter
|
||||
end
|
||||
result
|
||||
end
|
||||
|
|
@ -1165,9 +1153,9 @@ class Conference < ApplicationRecord
|
|||
#
|
||||
def generate_guid
|
||||
guid = SecureRandom.urlsafe_base64
|
||||
# begin
|
||||
# guid = SecureRandom.urlsafe_base64
|
||||
# end while User.where(:guid => guid).exists?
|
||||
# begin
|
||||
# guid = SecureRandom.urlsafe_base64
|
||||
# end while User.where(:guid => guid).exists?
|
||||
self.guid = guid
|
||||
end
|
||||
|
||||
|
|
@ -1175,19 +1163,17 @@ class Conference < ApplicationRecord
|
|||
# Adds a random color to the conference
|
||||
#
|
||||
def add_color
|
||||
unless color
|
||||
self.color = get_color
|
||||
end
|
||||
self.color = get_color unless color
|
||||
end
|
||||
|
||||
def get_color
|
||||
%w(
|
||||
#000000 #0000FF #00FF00 #FF0000 #FFFF00 #9900CC
|
||||
#CC0066 #00FFFF #FF00FF #C0C0C0 #00008B #FFD700
|
||||
#FFA500 #FF1493 #FF00FF #F0FFFF #EE82EE #D2691E
|
||||
#C0C0C0 #A52A2A #9ACD32 #9400D3 #8B008B #8B0000
|
||||
#87CEEB #808080 #800080 #008B8B #006400
|
||||
).sample
|
||||
%w[
|
||||
#000000 #0000FF #00FF00 #FF0000 #FFFF00 #9900CC
|
||||
#CC0066 #00FFFF #FF00FF #C0C0C0 #00008B #FFD700
|
||||
#FFA500 #FF1493 #FF00FF #F0FFFF #EE82EE #D2691E
|
||||
#C0C0C0 #A52A2A #9ACD32 #9400D3 #8B008B #8B0000
|
||||
#87CEEB #808080 #800080 #008B8B #006400
|
||||
].sample
|
||||
end
|
||||
|
||||
# Calculates items per week from a hash.
|
||||
|
|
@ -1206,9 +1192,7 @@ class Conference < ApplicationRecord
|
|||
|
||||
items.each do |key, value|
|
||||
# Padding
|
||||
if last_key < (key.to_i - 1)
|
||||
result += Array.new(key.to_i - last_key - 1, sum)
|
||||
end
|
||||
result += Array.new(key.to_i - last_key - 1, sum) if last_key < (key.to_i - 1)
|
||||
|
||||
sum += value
|
||||
result.push(sum)
|
||||
|
|
@ -1216,9 +1200,7 @@ class Conference < ApplicationRecord
|
|||
end
|
||||
|
||||
# Padding right
|
||||
if result.length < weeks
|
||||
result += Array.new(weeks - result.length, sum)
|
||||
end
|
||||
result += Array.new(weeks - result.length, sum) if result.length < weeks
|
||||
|
||||
result
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Contact < ApplicationRecord
|
||||
has_paper_trail on: [:update], ignore: [:updated_at], meta: { conference_id: :conference_id }
|
||||
|
||||
|
|
@ -6,7 +8,7 @@ class Contact < ApplicationRecord
|
|||
validates :conference, presence: true
|
||||
# Conferences only have one contact
|
||||
validates :facebook, :twitter, :googleplus, :instagram, :mastodon,
|
||||
format: URI::regexp(%w(http https)), allow_blank: true
|
||||
format: URI.regexp(%w[http https]), allow_blank: true
|
||||
|
||||
def has_social_media?
|
||||
return true if facebook.present? || twitter.present? || googleplus.present? || instagram.present? || mastodon.present? || email.present?
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DifficultyLevel < ApplicationRecord
|
||||
belongs_to :program, touch: true
|
||||
has_many :events, dependent: :nullify
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class EmailSettings < ApplicationRecord
|
||||
belongs_to :conference
|
||||
|
||||
|
|
@ -11,12 +13,15 @@ class EmailSettings < ApplicationRecord
|
|||
'conference_start_date' => conference.start_date,
|
||||
'conference_end_date' => conference.end_date,
|
||||
'registrationlink' => Rails.application.routes.url_helpers.conference_conference_registration_url(
|
||||
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')),
|
||||
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')
|
||||
),
|
||||
'conference_splash_link' => Rails.application.routes.url_helpers.conference_url(
|
||||
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')),
|
||||
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')
|
||||
),
|
||||
|
||||
'schedule_link' => Rails.application.routes.url_helpers.conference_schedule_url(
|
||||
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000'))
|
||||
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')
|
||||
)
|
||||
}
|
||||
|
||||
if conference.program.cfp
|
||||
|
|
@ -43,12 +48,11 @@ class EmailSettings < ApplicationRecord
|
|||
if event
|
||||
h['eventtitle'] = event.title
|
||||
h['proposalslink'] = Rails.application.routes.url_helpers.conference_program_proposals_url(
|
||||
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000'))
|
||||
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')
|
||||
)
|
||||
end
|
||||
|
||||
if booth
|
||||
h['booth_title'] = booth.title
|
||||
end
|
||||
h['booth_title'] = booth.title if booth
|
||||
h
|
||||
end
|
||||
|
||||
|
|
@ -71,8 +75,8 @@ class EmailSettings < ApplicationRecord
|
|||
|
||||
def parse_template(text, values)
|
||||
values.each do |key, value|
|
||||
if value.kind_of?(Date)
|
||||
text = text.gsub "{#{key}}", value.strftime('%Y-%m-%d') unless text.blank?
|
||||
if value.is_a?(Date)
|
||||
text = text.gsub "{#{key}}", value.strftime('%Y-%m-%d') if text.present?
|
||||
else
|
||||
text = text.gsub "{#{key}}", value unless text.blank? || value.blank?
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Event < ApplicationRecord
|
||||
include ActiveRecord::Transitions
|
||||
include RevisionCount
|
||||
has_paper_trail on: [:create, :update], ignore: [:updated_at, :guid, :week], meta: { conference_id: :conference_id }
|
||||
has_paper_trail on: %i[create update], ignore: %i[updated_at guid week], meta: { conference_id: :conference_id }
|
||||
|
||||
acts_as_commentable
|
||||
|
||||
|
|
@ -61,10 +63,10 @@ class Event < ApplicationRecord
|
|||
state :rejected
|
||||
|
||||
event :restart do
|
||||
transitions to: :new, from: [:rejected, :withdrawn, :canceled]
|
||||
transitions to: :new, from: %i[rejected withdrawn canceled]
|
||||
end
|
||||
event :withdraw do
|
||||
transitions to: :withdrawn, from: [:new, :unconfirmed, :confirmed]
|
||||
transitions to: :withdrawn, from: %i[new unconfirmed confirmed]
|
||||
end
|
||||
event :accept do
|
||||
transitions to: :unconfirmed, from: [:new], on_transition: :process_acceptance
|
||||
|
|
@ -73,7 +75,7 @@ class Event < ApplicationRecord
|
|||
transitions to: :confirmed, from: :unconfirmed, on_transition: :process_confirmation
|
||||
end
|
||||
event :cancel do
|
||||
transitions to: :canceled, from: [:unconfirmed, :confirmed]
|
||||
transitions to: :canceled, from: %i[unconfirmed confirmed]
|
||||
end
|
||||
event :reject do
|
||||
transitions to: :rejected, from: [:new], on_transition: :process_rejection
|
||||
|
|
@ -108,7 +110,7 @@ class Event < ApplicationRecord
|
|||
# ====Returns
|
||||
# * +true+ -> If the event has votes (optionally, by the user)
|
||||
# * +false+ -> If the event does not have any votes (optionally, by the user)
|
||||
def voted?(user=nil)
|
||||
def voted?(user = nil)
|
||||
return votes.where(user: user).any? if user
|
||||
|
||||
votes.any?
|
||||
|
|
@ -128,9 +130,7 @@ class Event < ApplicationRecord
|
|||
def speakers_ordered
|
||||
speakers_list = speakers.to_a
|
||||
|
||||
if speakers_list.reject! { |speaker| speaker == submitter }
|
||||
speakers_list.unshift(submitter)
|
||||
end
|
||||
speakers_list.unshift(submitter) if speakers_list.reject! { |speaker| speaker == submitter }
|
||||
|
||||
speakers_list
|
||||
end
|
||||
|
|
@ -141,28 +141,26 @@ class Event < ApplicationRecord
|
|||
|
||||
def process_confirmation
|
||||
if program.conference.email_settings.send_on_confirmed_without_registration? &&
|
||||
program.conference.email_settings.confirmed_without_registration_body &&
|
||||
program.conference.email_settings.confirmed_without_registration_subject
|
||||
if program.conference.registrations.where(user_id: submitter.id).first.nil?
|
||||
Mailbot.confirm_reminder_mail(self).deliver_later
|
||||
end
|
||||
program.conference.email_settings.confirmed_without_registration_body &&
|
||||
program.conference.email_settings.confirmed_without_registration_subject
|
||||
Mailbot.confirm_reminder_mail(self).deliver_later if program.conference.registrations.where(user_id: submitter.id).first.nil?
|
||||
end
|
||||
end
|
||||
|
||||
def process_acceptance(options)
|
||||
if program.conference.email_settings.send_on_accepted &&
|
||||
program.conference.email_settings.accepted_body &&
|
||||
program.conference.email_settings.accepted_subject &&
|
||||
!options[:send_mail].blank?
|
||||
program.conference.email_settings.accepted_body &&
|
||||
program.conference.email_settings.accepted_subject &&
|
||||
options[:send_mail].present?
|
||||
Mailbot.acceptance_mail(self).deliver_later
|
||||
end
|
||||
end
|
||||
|
||||
def process_rejection(options)
|
||||
if program.conference.email_settings.send_on_rejected &&
|
||||
program.conference.email_settings.rejected_body &&
|
||||
program.conference.email_settings.rejected_subject &&
|
||||
!options[:send_mail].blank?
|
||||
program.conference.email_settings.rejected_body &&
|
||||
program.conference.email_settings.rejected_subject &&
|
||||
options[:send_mail].present?
|
||||
Mailbot.rejection_mail(self).deliver_later
|
||||
end
|
||||
end
|
||||
|
|
@ -186,28 +184,26 @@ class Event < ApplicationRecord
|
|||
|
||||
def update_state(transition, mail = false, subject = false, send_mail = false, send_mail_param)
|
||||
alert = ''
|
||||
if mail && send_mail_param && subject && send_mail
|
||||
alert = 'Update Email Subject before Sending Mails'
|
||||
end
|
||||
begin
|
||||
if mail
|
||||
send(transition,
|
||||
send_mail: send_mail_param)
|
||||
else
|
||||
send(transition)
|
||||
end
|
||||
save
|
||||
# If the event was previously scheduled, and then withdrawn or cancelled
|
||||
# its event_schedule will have enabled set to false
|
||||
# If the event is now confirmed again, we want it to be available for scheduling
|
||||
Rails.logger.debug "transition is #{transition}"
|
||||
if transition == :confirm
|
||||
Rails.logger.debug "schedules #{EventSchedule.unscoped.where(event: self, enabled: false)}"
|
||||
EventSchedule.unscoped.where(event: self, enabled: false).destroy_all
|
||||
end
|
||||
rescue Transitions::InvalidTransition => e
|
||||
alert = "Update state failed. #{e.message}"
|
||||
alert = 'Update Email Subject before Sending Mails' if mail && send_mail_param && subject && send_mail
|
||||
begin
|
||||
if mail
|
||||
send(transition,
|
||||
send_mail: send_mail_param)
|
||||
else
|
||||
send(transition)
|
||||
end
|
||||
save
|
||||
# If the event was previously scheduled, and then withdrawn or cancelled
|
||||
# its event_schedule will have enabled set to false
|
||||
# If the event is now confirmed again, we want it to be available for scheduling
|
||||
Rails.logger.debug "transition is #{transition}"
|
||||
if transition == :confirm
|
||||
Rails.logger.debug "schedules #{EventSchedule.unscoped.where(event: self, enabled: false)}"
|
||||
EventSchedule.unscoped.where(event: self, enabled: false).destroy_all
|
||||
end
|
||||
rescue Transitions::InvalidTransition => e
|
||||
alert = "Update state failed. #{e.message}"
|
||||
end
|
||||
alert
|
||||
end
|
||||
|
||||
|
|
@ -227,10 +223,10 @@ class Event < ApplicationRecord
|
|||
{
|
||||
registered: speakers.all? { |speaker| program.conference.user_registered? speaker },
|
||||
commercials: commercials.any?,
|
||||
biographies: speakers.all? { |speaker| !speaker.biography.blank? },
|
||||
subtitle: !subtitle.blank?,
|
||||
track: (!track.blank? unless program.tracks.empty?),
|
||||
difficulty_level: !difficulty_level.blank?,
|
||||
biographies: speakers.all? { |speaker| speaker.biography.present? },
|
||||
subtitle: subtitle.present?,
|
||||
track: (track.present? unless program.tracks.empty?),
|
||||
difficulty_level: difficulty_level.present?,
|
||||
title: true,
|
||||
abstract: true
|
||||
}.with_indifferent_access
|
||||
|
|
@ -266,9 +262,7 @@ class Event < ApplicationRecord
|
|||
event_schedules.find_by(schedule_id: selected_schedule_id).try(:start_time)
|
||||
end
|
||||
|
||||
def conference
|
||||
program.conference
|
||||
end
|
||||
delegate :conference, to: :program
|
||||
|
||||
private
|
||||
|
||||
|
|
@ -309,9 +303,11 @@ class Event < ApplicationRecord
|
|||
end
|
||||
|
||||
def before_end_of_conference
|
||||
errors
|
||||
.add(:created_at, "can't be after the conference end date!") if program.conference && program.conference.end_date &&
|
||||
(Date.today > program.conference.end_date)
|
||||
if program.conference&.end_date &&
|
||||
(Date.today > program.conference.end_date)
|
||||
errors
|
||||
.add(:created_at, "can't be after the conference end date!")
|
||||
end
|
||||
end
|
||||
|
||||
def conference_id
|
||||
|
|
@ -322,7 +318,7 @@ class Event < ApplicationRecord
|
|||
# Allow only confirmed tracks that belong to the same program as the event
|
||||
#
|
||||
def valid_track
|
||||
return unless track && track.program && program
|
||||
return unless track&.program && program
|
||||
errors.add(:track, 'is invalid') unless track.confirmed? && track.program == program
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class EventSchedule < ApplicationRecord
|
||||
default_scope { where(enabled: true) }
|
||||
belongs_to :schedule
|
||||
|
|
@ -71,13 +73,9 @@ class EventSchedule < ApplicationRecord
|
|||
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
|
||||
errors.add(:start_time, "can't be before the track's start date (#{event.track.start_date})") if event.track.try(:start_date) && event.track.start_date > start_time
|
||||
|
||||
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
|
||||
errors.add(:end_time, "can't be after the track's end date (#{event.track.end_date})") if event.track.try(:end_date) && event.track.end_date + 1.day < end_time
|
||||
end
|
||||
|
||||
##
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class EventType < ApplicationRecord
|
||||
belongs_to :program, touch: true
|
||||
has_many :events, dependent: :restrict_with_error
|
||||
|
|
@ -6,7 +8,7 @@ class EventType < ApplicationRecord
|
|||
ignore: %i[updated_at]
|
||||
|
||||
validates :title, presence: true
|
||||
validates :length, numericality: {greater_than: 0}
|
||||
validates :length, numericality: { greater_than: 0 }
|
||||
validates :minimum_abstract_length, presence: true
|
||||
validates :maximum_abstract_length, presence: true
|
||||
validate :length_step
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class EventUser < ApplicationRecord
|
||||
# TODO: Do we need these roles?
|
||||
ROLES = [%w[Speaker speaker], %w[Submitter submitter], %w[Moderator moderator]]
|
||||
ROLES = [%w[Speaker speaker], %w[Submitter submitter], %w[Moderator moderator]].freeze
|
||||
|
||||
belongs_to :event, touch: true
|
||||
belongs_to :user
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class EventsRegistration < ApplicationRecord
|
||||
belongs_to :registration
|
||||
belongs_to :event
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Lodging < ApplicationRecord
|
||||
belongs_to :conference
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Openid < ApplicationRecord
|
||||
belongs_to :user
|
||||
validates :provider, :uid, :email, presence: true
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Organization < ApplicationRecord
|
||||
resourcify :roles, dependent: :delete_all
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Payment < ApplicationRecord
|
||||
has_many :ticket_purchases
|
||||
belongs_to :user
|
||||
|
|
@ -32,7 +34,6 @@ class Payment < ApplicationRecord
|
|||
self.authorization_code = gateway_response[:id]
|
||||
self.status = 'success'
|
||||
true
|
||||
|
||||
rescue Stripe::StripeError => error
|
||||
errors.add(:base, error.message)
|
||||
self.status = 'failure'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class PhysicalTicket < ApplicationRecord
|
||||
belongs_to :ticket_purchase
|
||||
has_one :ticket, through: :ticket_purchase
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# cannot delete program if there are events submitted
|
||||
|
||||
class Program < ApplicationRecord
|
||||
|
|
@ -42,7 +44,7 @@ class Program < ApplicationRecord
|
|||
has_many :event_schedules, through: :events
|
||||
|
||||
has_many :event_users, through: :events
|
||||
has_many :program_events_speakers, -> {where(event_role: 'speaker')}, through: :events, source: :event_users
|
||||
has_many :program_events_speakers, -> { where(event_role: 'speaker') }, through: :events, source: :event_users
|
||||
has_many :speakers, -> { distinct }, through: :program_events_speakers, source: :user do
|
||||
def confirmed
|
||||
joins(:events).where(events: { state: :confirmed })
|
||||
|
|
@ -61,7 +63,7 @@ class Program < ApplicationRecord
|
|||
accepts_nested_attributes_for :tracks, reject_if: proc { |r| r['name'].blank? }, allow_destroy: true
|
||||
accepts_nested_attributes_for :difficulty_levels, allow_destroy: true
|
||||
|
||||
# validates :conference_id, presence: true, uniqueness: true
|
||||
# validates :conference_id, presence: true, uniqueness: true
|
||||
validates :rating, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 10, only_integer: true }
|
||||
validates :schedule_interval, numericality: { greater_than_or_equal_to: 5, less_than_or_equal_to: 60 }, presence: true
|
||||
validate :schedule_interval_divisor_60
|
||||
|
|
@ -80,7 +82,7 @@ class Program < ApplicationRecord
|
|||
tracks.self_organized.confirmed.order(start_date: :asc).each do |track|
|
||||
event_schedules += track.selected_schedule.event_schedules.order(start_time: :asc) if track.selected_schedule
|
||||
end
|
||||
event_schedules.sort_by(&:start_time) if event_schedules
|
||||
event_schedules&.sort_by(&:start_time)
|
||||
end
|
||||
|
||||
##
|
||||
|
|
@ -154,11 +156,11 @@ class Program < ApplicationRecord
|
|||
# do not notify if the schedule is not public
|
||||
return false unless schedule_public
|
||||
# do not notify unless the mail content is set up
|
||||
(!conference.email_settings.program_schedule_public_subject.blank? && !conference.email_settings.program_schedule_public_body.blank?)
|
||||
(conference.email_settings.program_schedule_public_subject.present? && conference.email_settings.program_schedule_public_body.present?)
|
||||
end
|
||||
|
||||
def languages_list
|
||||
languages.split(',').map {|l| ISO_639.find(l).english_name} if languages.present?
|
||||
languages.split(',').map { |l| ISO_639.find(l).english_name } if languages.present?
|
||||
end
|
||||
|
||||
##
|
||||
|
|
@ -224,16 +226,16 @@ class Program < ApplicationRecord
|
|||
# Check if languages string has the right format. Used as validation.
|
||||
#
|
||||
def check_languages_format
|
||||
return unless languages.present?
|
||||
return if languages.blank?
|
||||
# All white spaces are removed to allow languages to be separated by ',' and ', '. The languages string without spaces is saved
|
||||
self.languages = languages.delete(' ').downcase
|
||||
errors.add(:languages, 'must be two letters separated by commas') && return unless
|
||||
languages.match(/^$|(\A[a-z][a-z](,[a-z][a-z])*\z)/).present?
|
||||
errors.add(:languages, 'must be two letters separated by commas') && return if
|
||||
languages.match(/^$|(\A[a-z][a-z](,[a-z][a-z])*\z)/).blank?
|
||||
languages_array = languages.split(',')
|
||||
# We check that languages are not repeated
|
||||
errors.add(:languages, "can't be repeated") && return unless languages_array.uniq!.nil?
|
||||
# We check if every language is a valid ISO 639-1 language
|
||||
errors.add(:languages, 'must be ISO 639-1 valid codes') unless languages_array.select{ |x| ISO_639.find(x).nil? }.empty?
|
||||
errors.add(:languages, 'must be ISO 639-1 valid codes') unless languages_array.select { |x| ISO_639.find(x).nil? }.empty?
|
||||
end
|
||||
|
||||
##
|
||||
|
|
@ -259,7 +261,7 @@ class Program < ApplicationRecord
|
|||
def normalize_event_types_length
|
||||
event_types.each do |event_type|
|
||||
new_length = event_type.length > schedule_interval ? event_type.length - (event_type.length % schedule_interval) : schedule_interval
|
||||
event_type.update_attributes length: new_length
|
||||
event_type.update length: new_length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Qanswer < ApplicationRecord
|
||||
belongs_to :question
|
||||
belongs_to :answer, dependent: :delete
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Question < ApplicationRecord
|
||||
belongs_to :question_type
|
||||
has_and_belongs_to_many :conferences
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class QuestionType < ApplicationRecord
|
||||
has_many :questions
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Registration < ApplicationRecord
|
||||
require 'csv'
|
||||
belongs_to :user
|
||||
|
|
@ -9,7 +11,7 @@ class Registration < ApplicationRecord
|
|||
has_many :events_registrations
|
||||
has_many :events, through: :events_registrations, dependent: :destroy
|
||||
|
||||
has_paper_trail ignore: %i(updated_at week), meta: { conference_id: :conference_id }
|
||||
has_paper_trail ignore: %i[updated_at week], meta: { conference_id: :conference_id }
|
||||
|
||||
accepts_nested_attributes_for :user
|
||||
accepts_nested_attributes_for :qanswers
|
||||
|
|
@ -64,9 +66,7 @@ class Registration < ApplicationRecord
|
|||
end
|
||||
|
||||
def send_registration_mail
|
||||
if conference.email_settings.send_on_registration?
|
||||
Mailbot.registration_mail(conference, user).deliver_later
|
||||
end
|
||||
Mailbot.registration_mail(conference, user).deliver_later if conference.email_settings.send_on_registration?
|
||||
end
|
||||
|
||||
def set_week
|
||||
|
|
@ -77,8 +77,6 @@ class Registration < ApplicationRecord
|
|||
end
|
||||
|
||||
def registration_limit_not_exceed
|
||||
if conference.registration_limit > 0 && conference.registrations(:reload).count >= conference.registration_limit
|
||||
errors.add(:base, 'Registration limit exceeded')
|
||||
end
|
||||
errors.add(:base, 'Registration limit exceeded') if conference.registration_limit > 0 && conference.registrations(:reload).count >= conference.registration_limit
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RegistrationPeriod < ApplicationRecord
|
||||
belongs_to :conference
|
||||
|
||||
|
|
@ -10,15 +12,21 @@ class RegistrationPeriod < ApplicationRecord
|
|||
private
|
||||
|
||||
def before_end_of_conference
|
||||
errors
|
||||
.add(:start_date, "can't be after the conference end date (#{conference.end_date})") if conference && conference.end_date && start_date && (start_date > conference.end_date)
|
||||
if conference&.end_date && start_date && (start_date > conference.end_date)
|
||||
errors
|
||||
.add(:start_date, "can't be after the conference end date (#{conference.end_date})")
|
||||
end
|
||||
|
||||
errors
|
||||
.add(:end_date, "can't be after the conference end date (#{conference.end_date})") if conference && conference.end_date && end_date && (end_date > conference.end_date)
|
||||
if conference&.end_date && end_date && (end_date > conference.end_date)
|
||||
errors
|
||||
.add(:end_date, "can't be after the conference end date (#{conference.end_date})")
|
||||
end
|
||||
end
|
||||
|
||||
def start_date_before_end_date
|
||||
errors
|
||||
.add(:start_date, "can't be after the end date") if start_date && end_date && start_date > end_date
|
||||
if start_date && end_date && start_date > end_date
|
||||
errors
|
||||
.add(:start_date, "can't be after the end date")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Resource < ApplicationRecord
|
||||
belongs_to :conference
|
||||
validates :name, :used, :quantity, presence: true
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Role < ApplicationRecord
|
||||
belongs_to :resource, polymorphic: true
|
||||
has_many :users_roles
|
||||
has_many :users, through: :users_roles
|
||||
|
||||
has_paper_trail on: [:create, :update], only: [:name, :description], meta: { conference_id: :resource_id }
|
||||
has_paper_trail on: %i[create update], only: %i[name description], meta: { conference_id: :resource_id }
|
||||
|
||||
before_destroy :cancel
|
||||
scopify
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Room < ApplicationRecord
|
||||
include RevisionCount
|
||||
belongs_to :venue
|
||||
|
|
@ -12,9 +14,7 @@ class Room < ApplicationRecord
|
|||
|
||||
validates :size, numericality: { only_integer: true, greater_than: 0 }, allow_nil: true
|
||||
|
||||
def conference
|
||||
venue.conference
|
||||
end
|
||||
delegate :conference, to: :venue
|
||||
|
||||
private
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Schedule < ApplicationRecord
|
||||
belongs_to :program
|
||||
belongs_to :track
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Splashpage < ApplicationRecord
|
||||
belongs_to :conference
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Sponsor < ApplicationRecord
|
||||
belongs_to :sponsorship_level
|
||||
belongs_to :conference
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class SponsorshipLevel < ApplicationRecord
|
||||
validates :title, presence: true
|
||||
belongs_to :conference
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Subscription < ApplicationRecord
|
||||
belongs_to :conference
|
||||
belongs_to :user
|
||||
|
||||
has_paper_trail on: %i(create destroy), ignore: [:updated_at], meta: { conference_id: :conference_id }
|
||||
has_paper_trail on: %i[create destroy], ignore: [:updated_at], meta: { conference_id: :conference_id }
|
||||
|
||||
validates :user_id, uniqueness: { scope: :conference_id, message: 'already subscribed!' }
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Target < ApplicationRecord
|
||||
include ActionView::Helpers::TextHelper
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Ticket < ApplicationRecord
|
||||
belongs_to :conference
|
||||
has_many :ticket_purchases, dependent: :destroy
|
||||
|
|
@ -58,7 +60,7 @@ class Ticket < ApplicationRecord
|
|||
|
||||
def self.total_price_user(conference, user, paid: false)
|
||||
tickets = TicketPurchase.where(conference: conference, user: user, paid: paid)
|
||||
tickets.inject(0){ |sum, ticket| sum + (ticket.amount_paid * ticket.quantity) }
|
||||
tickets.inject(0) { |sum, ticket| sum + (ticket.amount_paid * ticket.quantity) }
|
||||
end
|
||||
|
||||
def tickets_turnover_total(id)
|
||||
|
|
@ -77,8 +79,6 @@ class Ticket < ApplicationRecord
|
|||
def tickets_of_conference_have_same_currency
|
||||
tickets = Ticket.where(conference_id: conference_id)
|
||||
return if tickets.count.zero? || (tickets.count == 1 && self == tickets.first)
|
||||
unless tickets.all?{|t| t.price_currency == price_currency }
|
||||
errors.add(:price_currency, 'is different from the existing tickets of this conference.')
|
||||
end
|
||||
errors.add(:price_currency, 'is different from the existing tickets of this conference.') unless tickets.all? { |t| t.price_currency == price_currency }
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TicketPurchase < ApplicationRecord
|
||||
belongs_to :ticket
|
||||
belongs_to :user
|
||||
|
|
@ -38,9 +40,7 @@ class TicketPurchase < ApplicationRecord
|
|||
else
|
||||
purchase_ticket(conference, quantity, ticket, user)
|
||||
end
|
||||
if purchase && !purchase.save
|
||||
errors.push(purchase.errors.full_messages)
|
||||
end
|
||||
errors.push(purchase.errors.full_messages) if purchase && !purchase.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -75,7 +75,7 @@ class TicketPurchase < ApplicationRecord
|
|||
end
|
||||
|
||||
def pay(payment)
|
||||
update_attributes(paid: true, payment: payment)
|
||||
update(paid: true, payment: payment)
|
||||
PhysicalTicket.transaction do
|
||||
quantity.times { physical_tickets.create }
|
||||
end
|
||||
|
|
@ -83,15 +83,11 @@ class TicketPurchase < ApplicationRecord
|
|||
end
|
||||
|
||||
def one_registration_ticket_per_user
|
||||
if ticket.try(:registration_ticket?) && quantity != 1
|
||||
errors.add(:quantity, 'cannot be greater than one for registration tickets.')
|
||||
end
|
||||
errors.add(:quantity, 'cannot be greater than one for registration tickets.') if ticket.try(:registration_ticket?) && quantity != 1
|
||||
end
|
||||
|
||||
def registration_ticket_already_purchased
|
||||
if ticket.try(:registration_ticket?) && user.tickets.for_registration(conference).present?
|
||||
errors.add(:quantity, 'cannot be greater than one for registration tickets.')
|
||||
end
|
||||
errors.add(:quantity, 'cannot be greater than one for registration tickets.') if ticket.try(:registration_ticket?) && user.tickets.for_registration(conference).present?
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TicketScanning < ApplicationRecord
|
||||
belongs_to :physical_ticket
|
||||
|
||||
|
|
@ -6,8 +8,6 @@ class TicketScanning < ApplicationRecord
|
|||
private
|
||||
|
||||
def mark_user_present
|
||||
if physical_ticket.ticket.registration_ticket?
|
||||
physical_ticket.user.mark_attendance_for_conference(physical_ticket.conference)
|
||||
end
|
||||
physical_ticket.user.mark_attendance_for_conference(physical_ticket.conference) if physical_ticket.ticket.registration_ticket?
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Track < ApplicationRecord
|
||||
include ActiveRecord::Transitions
|
||||
include RevisionCount
|
||||
|
|
@ -24,7 +26,7 @@ class Track < ApplicationRecord
|
|||
}
|
||||
validates :state,
|
||||
presence: true,
|
||||
inclusion: { in: %w(new to_accept accepted confirmed to_reject rejected canceled withdrawn) }
|
||||
inclusion: { in: %w[new to_accept accepted confirmed to_reject rejected canceled withdrawn] }
|
||||
validates :cfp_active, inclusion: { in: [true, false] }
|
||||
validates :start_date, presence: true, if: :self_organized_and_accepted_or_confirmed?
|
||||
validates :end_date, presence: true, if: :self_organized_and_accepted_or_confirmed?
|
||||
|
|
@ -54,34 +56,32 @@ class Track < ApplicationRecord
|
|||
state :withdrawn
|
||||
|
||||
event :restart do
|
||||
transitions to: :new, from: [:rejected, :withdrawn, :canceled]
|
||||
transitions to: :new, from: %i[rejected withdrawn canceled]
|
||||
end
|
||||
event :to_accept do
|
||||
transitions to: :to_accept, from: [:new, :to_reject]
|
||||
transitions to: :to_accept, from: %i[new to_reject]
|
||||
end
|
||||
event :accept do
|
||||
transitions to: :accepted, from: [:new, :to_accept], on_transition: :create_organizer_role
|
||||
transitions to: :accepted, from: %i[new to_accept], on_transition: :create_organizer_role
|
||||
end
|
||||
event :confirm do
|
||||
transitions to: :confirmed, from: [:accepted], on_transition: :assign_role_to_submitter
|
||||
end
|
||||
event :to_reject do
|
||||
transitions to: :to_reject, from: [:new, :to_accept]
|
||||
transitions to: :to_reject, from: %i[new to_accept]
|
||||
end
|
||||
event :reject do
|
||||
transitions to: :rejected, from: [:new, :to_reject]
|
||||
transitions to: :rejected, from: %i[new to_reject]
|
||||
end
|
||||
event :cancel do
|
||||
transitions to: :canceled, from: [:to_accept, :to_reject, :accepted, :confirmed], on_transition: :revoke_role_and_cleanup
|
||||
transitions to: :canceled, from: %i[to_accept to_reject accepted confirmed], on_transition: :revoke_role_and_cleanup
|
||||
end
|
||||
event :withdraw do
|
||||
transitions to: :withdrawn, from: [:new, :to_accept, :to_reject, :accepted, :confirmed], on_transition: :revoke_role_and_cleanup
|
||||
transitions to: :withdrawn, from: %i[new to_accept to_reject accepted confirmed], on_transition: :revoke_role_and_cleanup
|
||||
end
|
||||
end
|
||||
|
||||
def conference
|
||||
program.conference
|
||||
end
|
||||
delegate :conference, to: :program
|
||||
|
||||
##
|
||||
# Checks if the track is self-organized
|
||||
|
|
@ -113,10 +113,8 @@ class Track < ApplicationRecord
|
|||
def revoke_role_and_cleanup
|
||||
role = Role.find_by(name: 'track_organizer', resource: self)
|
||||
|
||||
if role
|
||||
role.users.each do |user|
|
||||
user.remove_role 'track_organizer', self
|
||||
end
|
||||
role&.users&.each do |user|
|
||||
user.remove_role 'track_organizer', self
|
||||
end
|
||||
|
||||
self.selected_schedule_id = nil
|
||||
|
|
@ -175,9 +173,9 @@ class Track < ApplicationRecord
|
|||
|
||||
def generate_guid
|
||||
guid = SecureRandom.urlsafe_base64
|
||||
# begin
|
||||
# guid = SecureRandom.urlsafe_base64
|
||||
# end while Person.where(:guid => guid).exists?
|
||||
# begin
|
||||
# guid = SecureRandom.urlsafe_base64
|
||||
# end while Person.where(:guid => guid).exists?
|
||||
self.guid = guid
|
||||
end
|
||||
|
||||
|
|
@ -227,12 +225,11 @@ class Track < ApplicationRecord
|
|||
return unless start_date && end_date && room && program.try(:tracks)
|
||||
(program.tracks.accepted + program.tracks.confirmed - [self]).each do |existing_track|
|
||||
next unless existing_track.room == room && existing_track.start_date && existing_track.end_date
|
||||
if start_date >= existing_track.start_date && start_date <= existing_track.end_date ||
|
||||
end_date >= existing_track.start_date && end_date <= existing_track.end_date ||
|
||||
start_date <= existing_track.start_date && end_date >= existing_track.end_date
|
||||
errors.add(:track, 'has overlapping dates with a confirmed or accepted track in the same room')
|
||||
break
|
||||
end
|
||||
next unless start_date >= existing_track.start_date && start_date <= existing_track.end_date ||
|
||||
end_date >= existing_track.start_date && end_date <= existing_track.end_date ||
|
||||
start_date <= existing_track.start_date && end_date >= existing_track.end_date
|
||||
errors.add(:track, 'has overlapping dates with a confirmed or accepted track in the same room')
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class IChainRecordNotFound < StandardError
|
||||
end
|
||||
|
||||
|
|
@ -17,8 +19,8 @@ class User < ApplicationRecord
|
|||
has_many :users_roles
|
||||
has_many :roles, through: :users_roles, dependent: :destroy
|
||||
|
||||
has_paper_trail on: [:create, :update], ignore: [:sign_in_count, :remember_created_at, :current_sign_in_at, :last_sign_in_at, :current_sign_in_ip, :last_sign_in_ip, :unconfirmed_email,
|
||||
:avatar_content_type, :avatar_file_size, :avatar_updated_at, :updated_at, :confirmation_sent_at, :confirmation_token, :reset_password_token]
|
||||
has_paper_trail on: %i[create update], ignore: %i[sign_in_countremember_created_atcurrent_sign_in_atlast_sign_in_atcurrent_sign_in_iplast_sign_in_ipunconfirmed_email
|
||||
avatar_content_type avatar_file_size avatar_updated_at updated_at confirmation_sent_at confirmation_token reset_password_token]
|
||||
|
||||
include Gravtastic
|
||||
gravtastic size: 32
|
||||
|
|
@ -28,7 +30,7 @@ class User < ApplicationRecord
|
|||
after_save :touch_events
|
||||
|
||||
# add scope
|
||||
scope :comment_notifiable, ->(conference) {joins(:roles).where('roles.name IN (?)', [:organizer, :cfp]).where('roles.resource_type = ? AND roles.resource_id = ?', 'Conference', conference.id)}
|
||||
scope :comment_notifiable, ->(conference) { joins(:roles).where('roles.name IN (?)', %i[organizer cfp]).where('roles.resource_type = ? AND roles.resource_id = ?', 'Conference', conference.id) }
|
||||
|
||||
# Include default devise modules. Others available are:
|
||||
# :token_authenticatable, :confirmable,
|
||||
|
|
@ -40,7 +42,7 @@ class User < ApplicationRecord
|
|||
else
|
||||
[:database_authenticatable, :registerable,
|
||||
:recoverable, :rememberable, :trackable, :validatable, :confirmable,
|
||||
:omniauthable, omniauth_providers: [:suse, :google, :facebook, :github]]
|
||||
:omniauthable, omniauth_providers: %i[suse google facebook github]]
|
||||
end
|
||||
|
||||
devise(*devise_modules)
|
||||
|
|
@ -51,9 +53,9 @@ class User < ApplicationRecord
|
|||
|
||||
has_many :event_users, dependent: :destroy
|
||||
has_many :events, -> { distinct }, through: :event_users
|
||||
has_many :presented_events, -> { joins(:event_users).where(event_users: {event_role: 'speaker'}).distinct }, through: :event_users, source: :event
|
||||
has_many :presented_events, -> { joins(:event_users).where(event_users: { event_role: 'speaker' }).distinct }, through: :event_users, source: :event
|
||||
has_many :registrations, dependent: :destroy do
|
||||
def for_conference conference
|
||||
def for_conference(conference)
|
||||
where(conference: conference).first
|
||||
end
|
||||
end
|
||||
|
|
@ -61,7 +63,7 @@ class User < ApplicationRecord
|
|||
has_many :ticket_purchases, dependent: :destroy
|
||||
has_many :payments, dependent: :destroy
|
||||
has_many :tickets, through: :ticket_purchases, source: :ticket do
|
||||
def for_registration conference
|
||||
def for_registration(conference)
|
||||
where(conference: conference, registration_ticket: true).first
|
||||
end
|
||||
end
|
||||
|
|
@ -81,7 +83,7 @@ class User < ApplicationRecord
|
|||
|
||||
validates :username,
|
||||
uniqueness: {
|
||||
case_sensitive: false
|
||||
case_sensitive: false
|
||||
},
|
||||
presence: true
|
||||
|
||||
|
|
@ -95,48 +97,48 @@ class User < ApplicationRecord
|
|||
# === Returns
|
||||
# * +true+ if the user attended the event
|
||||
# * +false+ if the user did not attend the event
|
||||
def attended_event? event
|
||||
def attended_event?(event)
|
||||
event_registration = event.events_registrations.find_by(registration: registrations)
|
||||
|
||||
return false unless event_registration.present?
|
||||
return false if event_registration.blank?
|
||||
event_registration.attended
|
||||
end
|
||||
|
||||
def mark_attendance_for_conference conference
|
||||
def mark_attendance_for_conference(conference)
|
||||
registration = registrations.for_conference(conference)
|
||||
registration.attended = true
|
||||
registration.save
|
||||
end
|
||||
|
||||
def name
|
||||
self[:name].blank? ? username : self[:name]
|
||||
self[:name].presence || username
|
||||
end
|
||||
|
||||
##
|
||||
# Checks if a user has registered to an event
|
||||
# ====Returns
|
||||
# * +true+ or +false+
|
||||
def registered_to_event? event
|
||||
def registered_to_event?(event)
|
||||
event.registrations.include? registrations.find_by(conference: event.program.conference)
|
||||
end
|
||||
|
||||
def subscribed? conference
|
||||
def subscribed?(conference)
|
||||
subscriptions.find_by(conference_id: conference.id).present?
|
||||
end
|
||||
|
||||
def supports? conference
|
||||
def supports?(conference)
|
||||
ticket_purchases.find_by(conference_id: conference.id).present?
|
||||
end
|
||||
|
||||
def self.for_ichain_username(username, attributes)
|
||||
user = find_by(username: username)
|
||||
|
||||
raise UserDisabled if user && user.is_disabled
|
||||
raise UserDisabled if user&.is_disabled
|
||||
|
||||
if user
|
||||
user.update_attributes(email: attributes[:email],
|
||||
last_sign_in_at: user.current_sign_in_at,
|
||||
current_sign_in_at: Time.current)
|
||||
user.update(email: attributes[:email],
|
||||
last_sign_in_at: user.current_sign_in_at,
|
||||
current_sign_in_at: Time.current)
|
||||
else
|
||||
begin
|
||||
user = create!(username: username, email: attributes[:email])
|
||||
|
|
@ -163,9 +165,7 @@ class User < ApplicationRecord
|
|||
def self.find_for_auth(auth, current_user = nil)
|
||||
user = current_user
|
||||
|
||||
if user.nil? # No current user available, user is not already logged in
|
||||
user = User.where(email: auth.info.email).first_or_initialize
|
||||
end
|
||||
user = User.where(email: auth.info.email).first_or_initialize if user.nil? # No current user available, user is not already logged in
|
||||
|
||||
if user.new_record?
|
||||
user.email = auth.info.email
|
||||
|
|
@ -231,9 +231,7 @@ class User < ApplicationRecord
|
|||
private
|
||||
|
||||
def setup_role
|
||||
if User.count == 1 && User.first.email == 'deleted@localhost.osem'
|
||||
self.is_admin = true
|
||||
end
|
||||
self.is_admin = true if User.count == 1 && User.first.email == 'deleted@localhost.osem'
|
||||
end
|
||||
|
||||
def touch_events
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class UsersRole < ApplicationRecord
|
||||
belongs_to :role
|
||||
belongs_to :user
|
||||
|
||||
has_paper_trail on: [:create, :destroy], meta: { conference_id: :conference_id }
|
||||
has_paper_trail on: %i[create destroy], meta: { conference_id: :conference_id }
|
||||
|
||||
private
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Vchoice < ApplicationRecord
|
||||
belongs_to :vday
|
||||
belongs_to :vposition
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Vday < ApplicationRecord
|
||||
belongs_to :conference
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Venue < ApplicationRecord
|
||||
belongs_to :conference
|
||||
has_one :commercial, as: :commercialable, dependent: :destroy
|
||||
has_many :rooms, dependent: :destroy
|
||||
before_create :generate_guid
|
||||
|
||||
has_paper_trail ignore: [:updated_at, :guid], meta: { conference_id: :conference_id }
|
||||
has_paper_trail ignore: %i[updated_at guid], meta: { conference_id: :conference_id }
|
||||
|
||||
accepts_nested_attributes_for :commercial, allow_destroy: true
|
||||
validates :name, :street, :city, :country, presence: true
|
||||
|
|
@ -19,7 +21,7 @@ class Venue < ApplicationRecord
|
|||
|
||||
def country_name
|
||||
name = ISO3166::Country[country]
|
||||
name.name if name
|
||||
name&.name
|
||||
end
|
||||
|
||||
def location?
|
||||
|
|
@ -37,7 +39,7 @@ class Venue < ApplicationRecord
|
|||
# do not notify unless the address changed
|
||||
return false unless name_changed? || street_changed? || city_changed? || country_changed?
|
||||
# do not notify unless the mail content is set up
|
||||
(!conference.email_settings.venue_updated_subject.blank? && !conference.email_settings.venue_updated_body.blank?)
|
||||
(conference.email_settings.venue_updated_subject.present? && conference.email_settings.venue_updated_body.present?)
|
||||
end
|
||||
|
||||
# TODO: create a module to be mixed into model to perform same operation
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Visit < ApplicationRecord
|
||||
has_many :ahoy_events, class_name: 'Ahoy::Event'
|
||||
belongs_to :user
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Vote < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :event
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Vposition < ApplicationRecord
|
||||
belongs_to :conference
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue