diff --git a/app/models/ability.rb b/app/models/ability.rb index 654345b8..ff1628a1 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -80,7 +80,7 @@ class Ability can [:new, :create], Registration do |registration| conference = registration.conference - conference.registration_open? && !conference.registration_limit_exceeded? + conference.registration_open? && !conference.registration_limit_exceeded? || conference.program.speakers.confirmed.include?(user) end can :index, Ticket diff --git a/app/models/conference.rb b/app/models/conference.rb index 224c1dfb..1c4ccc73 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -594,8 +594,15 @@ class Conference < ActiveRecord::Base (email_settings.conference_registration_dates_updated_subject.present? && email_settings.conference_registration_dates_updated_body.present?) end + ## + # Checks if the registration limit has been exceeded + # Additionally, it takes into account the confirmed speakers that haven't registered yet + # + # ====Returns + # * +True+ -> If the registration limit has been reached or exceeded + # * +False+ -> If the registration limit hasn't been exceeded def registration_limit_exceeded? - registration_limit > 0 && registrations.count >= registration_limit + registration_limit > 0 && registrations.count + program.speakers.confirmed.count - program.speakers.confirmed.registered(program.conference).count >= registration_limit end # Returns an hexadecimal color given a collection. The returned color changed diff --git a/app/models/program.rb b/app/models/program.rb index e8114f99..c7168849 100644 --- a/app/models/program.rb +++ b/app/models/program.rb @@ -46,6 +46,10 @@ class Program < ActiveRecord::Base def confirmed joins(:events).where(events: { state: :confirmed }) end + + def registered(conference) + joins(:registrations).where('registrations.conference_id = ?', conference.id) + end end accepts_nested_attributes_for :event_types, allow_destroy: true diff --git a/app/views/admin/conferences/edit.html.haml b/app/views/admin/conferences/edit.html.haml index de8d6316..5aa717ea 100644 --- a/app/views/admin/conferences/edit.html.haml +++ b/app/views/admin/conferences/edit.html.haml @@ -24,5 +24,5 @@ = f.input :start_hour, input_html: {size: 2, type: 'number', min: 0, max: 23} = f.input :end_hour, input_html: {size: 2, type: 'number', min: 1, max: 24} = f.inputs name: 'Registrations' do - = f.input :registration_limit, as: :number, in: 0..9999, hint: 'Limit the number of registrations to the conference (0 no limit). You currently have ' + pluralize(@conference.registrations.count, 'registration') + = f.input :registration_limit, as: :number, in: 0..9999, hint: 'Limit the number of registrations to the conference (0 no limit). Please note that the registration limit doesn\'t apply to speakers of confirmed events (they will still be able to register even if it has been reached). You currently have ' + pluralize(@conference.registrations.count, 'registration') = f.action :submit, as: :button, button_html: {class: 'btn btn-primary'} diff --git a/app/views/conferences/_conference_details.html.haml b/app/views/conferences/_conference_details.html.haml index 6ee51573..bdbd5fc6 100644 --- a/app/views/conferences/_conference_details.html.haml +++ b/app/views/conferences/_conference_details.html.haml @@ -27,8 +27,8 @@ - if conference.user_registered?(current_user) = link_to "My Registration", conference_conference_registration_path(conference.short_title), class: 'btn btn-default' - else - = link_to "Register", new_conference_conference_registration_path(conference.short_title), class: "btn btn-default", disabled: conference.registration_limit_exceeded? - - if conference.registration_limit_exceeded? + = link_to "Register", new_conference_conference_registration_path(conference.short_title), class: "btn btn-default", disabled: cannot?(:new, Registration.new(conference_id: conference.id)) + - if cannot?(:new, Registration.new(conference_id: conference.id)) && conference.registration_limit_exceeded? Sorry, no places left - if !current_user.nil? && current_user.proposal_count(conference) > 0 = link_to "My Proposals", conference_program_proposals_path(conference.short_title), class: 'btn btn-default'