This commit is contained in:
Chaitanya Yadav 2017-07-12 14:11:54 +00:00 committed by GitHub
commit f1d2bf710f
4 changed files with 32 additions and 16 deletions

View file

@ -1,17 +1,14 @@
class SchedulesController < ApplicationController class SchedulesController < ApplicationController
load_and_authorize_resource
protect_from_forgery with: :null_session protect_from_forgery with: :null_session
before_action :respond_to_options before_action :respond_to_options
load_resource :conference, find_by: :short_title load_resource :conference, find_by: :short_title
load_resource :program, through: :conference, singleton: true, except: :index load_resource :program, through: :conference, singleton: true, except: :index
before_action :presence_of_selected_schedule
load_and_authorize_resource :selected_schedule, through: :program, singleton: true
def show def show
@rooms = @conference.venue.rooms if @conference.venue @rooms = @conference.venue.rooms if @conference.venue
schedules = @program.selected_event_schedules schedules = @program.selected_event_schedules
unless schedules
redirect_to events_conference_schedule_path(@conference.short_title)
end
@events_xml = schedules.map(&:event).group_by{ |event| event.time.to_date } if schedules @events_xml = schedules.map(&:event).group_by{ |event| event.time.to_date } if schedules
@dates = @conference.start_date..@conference.end_date @dates = @conference.start_date..@conference.end_date
@step_minutes = @program.schedule_interval.minutes @step_minutes = @program.schedule_interval.minutes
@ -49,4 +46,9 @@ class SchedulesController < ApplicationController
format.html { head :ok } format.html { head :ok }
end if request.options? end if request.options?
end end
def presence_of_selected_schedule
return if @program.selected_event_schedules
redirect_to root_path, notice: 'Program is yet to be scheduled.'
end
end end

View file

@ -34,10 +34,6 @@ class Ability
can [:show], Conference do |conference| can [:show], Conference do |conference|
conference.splashpage && conference.splashpage.public == true conference.splashpage && conference.splashpage.public == true
end end
# Can view the schedule
can [:schedule, :events], Conference do |conference|
conference.program.cfp && conference.program.schedule_public
end
can :show, Event do |event| can :show, Event do |event|
event.state == 'confirmed' event.state == 'confirmed'

View file

@ -21,7 +21,7 @@
- if !@conference || @conference != conference - if !@conference || @conference != conference
- if conference.splashpage && conference.splashpage.public - if conference.splashpage && conference.splashpage.public
= link_to "View Conference", conference_path(conference.short_title), class: 'btn btn-default' = link_to "View Conference", conference_path(conference.short_title), class: 'btn btn-default'
- if conference.program and conference.program.schedule_public - if conference.program and conference.program.selected_event_schedules and conference.program.schedule_public
= link_to "Schedule", conference_schedule_path(conference.short_title), class: 'btn btn-default' = link_to "Schedule", conference_schedule_path(conference.short_title), class: 'btn btn-default'
- if conference.registration_open? - if conference.registration_open?
- if conference.user_registered?(current_user) - if conference.user_registered?(current_user)

View file

@ -23,6 +23,10 @@ describe 'User' do
let(:conference_not_public) { create(:conference, splashpage: create(:splashpage, public: false)) } let(:conference_not_public) { create(:conference, splashpage: create(:splashpage, public: false)) }
let(:conference_public) { create(:full_conference, splashpage: create(:splashpage, public: true)) } let(:conference_public) { create(:full_conference, splashpage: create(:splashpage, public: true)) }
# Other schedule which is either public or not_public.
let(:schedule_public) { create(:schedule, program: create(:program, schedule_public: true))}
let(:schedule_not_public) { create(:schedule, program: create(:program, schedule_public: false))}
let(:event_confirmed) { create(:event, state: 'confirmed') } let(:event_confirmed) { create(:event, state: 'confirmed') }
let(:event_unconfirmed) { create(:event) } let(:event_unconfirmed) { create(:event) }
@ -51,12 +55,8 @@ describe 'User' do
it{ should be_able_to(:show, conference_public)} it{ should be_able_to(:show, conference_public)}
it{ should_not be_able_to(:show, conference_not_public)} it{ should_not be_able_to(:show, conference_not_public)}
it do it{ should be_able_to(:show, schedule_public) }
conference_public.program.schedule_public = true it{ should_not be_able_to(:show, schedule_not_public) }
conference_public.program.save
should be_able_to(:schedule, conference_public)
end
it{ should_not be_able_to(:schedule, conference_not_public)}
it{ should be_able_to(:show, event_confirmed)} it{ should be_able_to(:show, event_confirmed)}
it{ should_not be_able_to(:show, event_unconfirmed)} it{ should_not be_able_to(:show, event_unconfirmed)}
@ -102,6 +102,9 @@ describe 'User' do
it{ should_not be_able_to(:new, Registration.new(conference_id: conference_with_closed_registration.id))} it{ should_not be_able_to(:new, Registration.new(conference_id: conference_with_closed_registration.id))}
it{ should_not be_able_to(:create, Registration.new(conference_id: conference_with_closed_registration.id))} it{ should_not be_able_to(:create, Registration.new(conference_id: conference_with_closed_registration.id))}
it{ should be_able_to(:show, schedule_public) }
it{ should_not be_able_to(:show, schedule_not_public) }
it{ should be_able_to(:index, Ticket) } it{ should be_able_to(:index, Ticket) }
it{ should be_able_to(:manage, TicketPurchase.new(user_id: user.id)) } it{ should be_able_to(:manage, TicketPurchase.new(user_id: user.id)) }
@ -136,6 +139,9 @@ describe 'User' do
it{ should be_able_to(:manage, :all) } it{ should be_able_to(:manage, :all) }
it{ should_not be_able_to(:destroy, my_conference.program) } it{ should_not be_able_to(:destroy, my_conference.program) }
it{ should_not be_able_to(:destroy, my_venue) } it{ should_not be_able_to(:destroy, my_venue) }
it{ should be_able_to(:show, schedule_public) }
it{ should be_able_to(:show, schedule_not_public) }
end end
shared_examples 'user with any role' do shared_examples 'user with any role' do
@ -244,6 +250,9 @@ describe 'User' do
it{ should be_able_to(:manage, my_conference.tickets.first) } it{ should be_able_to(:manage, my_conference.tickets.first) }
it{ should_not be_able_to(:manage, conference_public.tickets.first) } it{ should_not be_able_to(:manage, conference_public.tickets.first) }
it{ should be_able_to(:show, schedule_public) }
it{ should_not be_able_to(:show, schedule_not_public) }
it{ should be_able_to(:manage, my_registration) } it{ should be_able_to(:manage, my_registration) }
it{ should_not be_able_to(:manage, other_registration) } it{ should_not be_able_to(:manage, other_registration) }
@ -315,6 +324,9 @@ describe 'User' do
it{ should_not be_able_to(:manage, my_conference.tickets.first) } it{ should_not be_able_to(:manage, my_conference.tickets.first) }
it{ should_not be_able_to(:manage, conference_public.tickets.first) } it{ should_not be_able_to(:manage, conference_public.tickets.first) }
it{ should be_able_to(:show, schedule_public) }
it{ should_not be_able_to(:show, schedule_not_public) }
it{ should_not be_able_to(:manage, my_registration) } it{ should_not be_able_to(:manage, my_registration) }
it{ should_not be_able_to(:manage, other_registration) } it{ should_not be_able_to(:manage, other_registration) }
@ -382,6 +394,9 @@ describe 'User' do
it{ should_not be_able_to(:manage, my_conference.tickets.first) } it{ should_not be_able_to(:manage, my_conference.tickets.first) }
it{ should_not be_able_to(:manage, conference_public.tickets.first) } it{ should_not be_able_to(:manage, conference_public.tickets.first) }
it{ should be_able_to(:show, schedule_public) }
it{ should_not be_able_to(:show, schedule_not_public) }
it{ should be_able_to(:manage, my_registration) } it{ should be_able_to(:manage, my_registration) }
it{ should_not be_able_to(:manage, other_registration) } it{ should_not be_able_to(:manage, other_registration) }
@ -449,6 +464,9 @@ describe 'User' do
it{ should_not be_able_to(:manage, my_conference.tickets.first) } it{ should_not be_able_to(:manage, my_conference.tickets.first) }
it{ should_not be_able_to(:manage, conference_public.tickets.first) } it{ should_not be_able_to(:manage, conference_public.tickets.first) }
it{ should be_able_to(:show, schedule_public) }
it{ should_not be_able_to(:show, schedule_not_public) }
it{ should_not be_able_to(:manage, registration) } it{ should_not be_able_to(:manage, registration) }
it{ should_not be_able_to(:manage, other_registration) } it{ should_not be_able_to(:manage, other_registration) }