Rooms belong to venue

This commit is contained in:
Stella Rouzi 2015-11-07 11:43:36 +02:00 committed by Henne Vogelsang
parent feabbfbc99
commit f840f2b3f0
31 changed files with 221 additions and 166 deletions

View file

@ -106,6 +106,10 @@ class Ability
can :manage, :all if user.is_admin
cannot :destroy, Program
# Do not delete venue, when there are rooms being used
cannot :destroy, Venue do |venue|
venue.conference.program.events.where.not(room_id: nil).any?
end
end
def signed_in_with_organizer_role(user)
@ -141,7 +145,7 @@ class Ability
commercialable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organizer).pluck(:id)).pluck(:id)
can :manage, Venue, conference_id: conf_ids_for_organizer
can :manage, Lodging, conference_id: conf_ids_for_organizer
can :manage, Room, program: { conference_id: conf_ids_for_organizer}
can :manage, Room, venue: { conference_id: conf_ids_for_organizer}
can :manage, Sponsor, conference_id: conf_ids_for_organizer
can :manage, SponsorshipLevel, conference_id: conf_ids_for_organizer
can :manage, Ticket, conference_id: conf_ids_for_organizer
@ -160,7 +164,7 @@ class Ability
can :manage, Track, program: { conference_id: conf_ids_for_cfp }
can :manage, DifficultyLevel, program: { conference_id: conf_ids_for_cfp }
can :manage, EmailSettings, conference_id: conf_ids_for_cfp
can :manage, Room, program: { conference_id: conf_ids_for_cfp }
can :manage, Room, venue: { conference_id: conf_ids_for_cfp }
can :index, Venue, conference_id: conf_ids_for_cfp
can :manage, Cfp, program: { conference_id: conf_ids_for_cfp }
can :manage, Program, conference_id: conf_ids_for_cfp

View file

@ -707,7 +707,7 @@ class Conference < ActiveRecord::Base
# * +True+ -> One room or more
# * +False+ -> No room
def rooms_set?
program.rooms.count > 0
venue.present? && venue.rooms.count > 0
end
# Checks if the conference has a venue object.

View file

@ -7,7 +7,6 @@ class Program < ActiveRecord::Base
has_many :event_types, dependent: :destroy
has_many :tracks, dependent: :destroy
has_many :difficulty_levels, dependent: :destroy
has_many :rooms, dependent: :destroy
has_many :events, dependent: :destroy do
def workshops
where(require_registration: true, state: :confirmed)
@ -36,11 +35,10 @@ class Program < ActiveRecord::Base
accepts_nested_attributes_for :event_types, allow_destroy: true
accepts_nested_attributes_for :tracks, reject_if: proc { |r| r['name'].blank? }, allow_destroy: true
accepts_nested_attributes_for :difficulty_levels, allow_destroy: true
accepts_nested_attributes_for :rooms, reject_if: proc { |r| r['name'].blank? }, allow_destroy: true
attr_accessible :schedule_fluid, :rating,
:schedule_public, :include_cfp_in_splash, :conference_id,
:event_types_attributes, :difficulty_levels_attributes, :rooms_attributes, :tracks_attributes
:event_types_attributes, :difficulty_levels_attributes, :tracks_attributes
# validates :conference_id, presence: true, uniqueness: true
validates :rating, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 10 }

View file

@ -1,10 +1,10 @@
class Room < ActiveRecord::Base
belongs_to :program
belongs_to :venue
has_many :events, dependent: :nullify
before_create :generate_guid
validates :name, presence: true
validates :name, :venue_id, presence: true
validates :size, numericality: { only_integer: true, greater_than: 0 }, allow_nil: true

View file

@ -1,9 +1,10 @@
class Venue < ActiveRecord::Base
belongs_to :conference
has_many :lodgings
has_many :rooms, dependent: :destroy
before_create :generate_guid
validates :name, :street, :city, :country, presence: true
validates :conference_id, presence: true, uniqueness: true
has_attached_file :photo,
styles: { thumb: '100x100>', large: '300x300>' }
@ -11,8 +12,6 @@ class Venue < ActiveRecord::Base
content_type: [/jpg/, /jpeg/, /png/, /gif/],
size: { in: 0..500.kilobytes }
accepts_nested_attributes_for :lodgings, allow_destroy: true
after_update :send_mail_notification
def address