Merge branch 'master' into move-ability-namespace

This commit is contained in:
Shlok Srivastava 2017-07-13 22:40:44 +05:30 committed by GitHub
commit 3e396f7070
35 changed files with 404 additions and 70 deletions

View file

@ -8,7 +8,7 @@ class Comment < ActiveRecord::Base
# want user to vote on the quality of comments.
#acts_as_votable
belongs_to :commentable, polymorphic: true
belongs_to :commentable, counter_cache: true, polymorphic: true
# NOTE: Comments belong to a user
belongs_to :user

View file

@ -0,0 +1,11 @@
module RevisionCount
extend ActiveSupport::Concern
included do
after_update :increment_revision
end
def increment_revision
conference.update_column(:revision, conference.revision + 1)
end
end

View file

@ -1,4 +1,5 @@
class Conference < ActiveRecord::Base
include RevisionCount
require 'uri'
serialize :events_per_week, Hash
# Needed to call 'Conference.with_role' in /models/ability.rb
@ -6,6 +7,8 @@ class Conference < ActiveRecord::Base
resourcify :roles, dependent: :delete_all
default_scope { order('start_date DESC') }
scope :upcoming, (-> { where('end_date >= ?', Date.current) })
scope :past, (-> { where('end_date < ?', Date.current) })
belongs_to :organization
@ -734,6 +737,15 @@ class Conference < ActiveRecord::Base
(start_hour..(end_hour - 1)).cover?(current_hour) ? current_hour - start_hour : 0
end
##
# Return the current conference object to be used in RevisionCount
#
# ====Returns
# * +ActiveRecord+
def conference
self
end
private
# Returns a different html colour for every i and consecutive colors are

View file

@ -1,5 +1,6 @@
class Event < ActiveRecord::Base
include ActiveRecord::Transitions
include RevisionCount
has_paper_trail on: [:create, :update], ignore: [:updated_at, :guid, :week], meta: { conference_id: :conference_id }
acts_as_commentable
@ -251,6 +252,10 @@ class Event < ActiveRecord::Base
event_schedules.find_by(schedule_id: program.selected_schedule_id).try(:start_time)
end
def conference
program.conference
end
private
##

View file

@ -3,4 +3,5 @@ class PhysicalTicket < ActiveRecord::Base
has_one :ticket, through: :ticket_purchase
has_one :conference, through: :ticket_purchase
has_one :user, through: :ticket_purchase
has_many :ticket_scannings
end

View file

@ -1,26 +0,0 @@
#
# suseconferenceclient relies on a 'revision' attribute for caching and
# doing some calculations.
#
# It should be incremented after any change in the conference or in any
# associated models
#
# This observer updates the revision column in a non-intrusive way,
# preventing validations, callbacks or exceptions to be triggered
#
# Relying on paper_trail could also be an option, but a 'revision' column
# in table 'conferences' looks like a more simple and straightforward solution
#
class RevisionObserver < ActiveRecord::Observer
observe :conference, :event, :room, :track
def after_save(model)
begin
conference = model.kind_of?(Conference) ? model : model.conference
conference.reload.increment(:revision)
conference.update_column(:revision, conference.revision)
rescue
nil
end
end
end

View file

@ -1,4 +1,5 @@
class Room < ActiveRecord::Base
include RevisionCount
belongs_to :venue
has_many :event_schedules, dependent: :destroy
@ -10,6 +11,10 @@ class Room < ActiveRecord::Base
validates :size, numericality: { only_integer: true, greater_than: 0 }, allow_nil: true
def conference
venue.conference
end
private
def generate_guid

View file

@ -0,0 +1,3 @@
class TicketScanning < ActiveRecord::Base
belongs_to :physical_ticket
end

View file

@ -1,4 +1,5 @@
class Track < ActiveRecord::Base
include RevisionCount
belongs_to :program
has_many :events, dependent: :nullify
@ -16,6 +17,10 @@ class Track < ActiveRecord::Base
before_validation :capitalize_color
def conference
program.conference
end
private
def generate_guid

View file

@ -184,4 +184,4 @@
%ul.dropdown-menu{ role: 'menu' }
= render 'change_state_dropdown', event: event
%td.text-center
= link_to "#{event.comment_threads.count}", admin_conference_program_event_path(@conference.short_title, event), anchor: 'comments-div'
= link_to "#{event.comments_count}", admin_conference_program_event_path(@conference.short_title, event), anchor: 'comments-div'

View file

@ -20,9 +20,9 @@
%td
= organization.name
%td
= organization.conferences.count
= organization.conferences.upcoming.count
%td
= organization.conferences.count
= organization.conferences.past.count
%td
.btn-group
= link_to 'Edit', edit_admin_organization_path(organization),

View file

@ -16,7 +16,7 @@
%span.fa.fa-cog
Manage
= conference.short_title
- if (current_user.is_admin) || (current_user.has_role? :organizer, :any)
- if can? :new, Conference.new
%li
= link_to(new_admin_conference_path) do
%span.fa.fa-plus

View file

@ -16,7 +16,7 @@
%span.fa.fa-cog
Manage
= conference.short_title
- if can? :create, Conference
- if can? :new, Conference.new
%li
= link_to(new_admin_conference_path) do
%span.fa.fa-plus

View file

@ -28,10 +28,10 @@
= link_to(admin_conferences_path()) do
%span.fa.fa-home
Administration
- if can? :create, Conference
- if can? :new, Conference.new
=link_to(new_admin_conference_path) do
%span.fa.fa-plus
Create Conference
New Conference
-if @conference and @conference.id and can? :show, @conference
%li
= link_to(admin_conference_path(@conference.short_title)) do