diff --git a/app/models/ability.rb b/app/models/ability.rb index caf8f2a4..cdf7ad2f 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -68,6 +68,7 @@ class Ability end # Abilities for signed in users + # rubocop:disable Metrics/AbcSize def signed_in(user) # Abilities from not_signed_in user are also inherited not_signed_in @@ -93,7 +94,9 @@ class Ability can [:index, :show], PhysicalTicket, user: user can [:new, :create], Booth do |booth| - booth.new_record? && booth.conference.program.cfps.for_booths.try(:open?) + invited_user = booth.conference.invites.where('end_date >= ?', Date.today).where( + user_id: user.id, invite_for: (I18n.t 'booth').capitalize.to_s) + invited_user.exists? || (booth.new_record? && booth.conference.program.cfps.for_booths.try(:open?)) end can [:edit, :update, :index, :show], Booth do |booth| @@ -129,7 +132,9 @@ class Ability can [:destroy], Openid can [:new, :create], Track do |track| - track.new_record? && track.program.cfps.for_tracks.try(:open?) + invited_user = track.conference.invites.where('end_date >= ?', Date.today).where( + user_id: user.id, invite_for: 'Track') + invited_user.exists? || (track.new_record? && track.program.cfps.for_tracks.try(:open?)) end can [:index, :show, :restart, :confirm, :withdraw], Track, submitter_id: user.id @@ -139,6 +144,7 @@ class Ability end end + # rubocop:enable Metrics/AbcSize # Abilities for users with roles wandering around in non-admin views. def common_abilities_for_admins(user) can :access, Admin diff --git a/spec/ability/ability_spec.rb b/spec/ability/ability_spec.rb index d119f9c5..7c27f36e 100644 --- a/spec/ability/ability_spec.rb +++ b/spec/ability/ability_spec.rb @@ -94,7 +94,52 @@ describe 'User' do it{ should be_able_to(:manage, registration_public) } it{ should be_able_to(:manage, registration_not_public) } + context 'when user wants to submit a booth' do + let(:conference) { create(:conference) } + + context 'when booth submission is open' do + before :each do + create(:cfp, program: conference.program, cfp_type: 'booths') + end + + it{ should be_able_to(:new, Booth.new(conference: conference)) } + it{ should be_able_to(:create, Booth.new(conference: conference)) } + end + + context 'when booth submission is closed' do + + context 'when user is not invited for late booth submssion' do + before :each do + create(:cfp, program: conference.program, cfp_type: 'booths', start_date: Date.current - 6.days, end_date: Date.current - 6.days) + end + + it{ should_not be_able_to(:new, Booth.new(conference: conference)) } + it{ should_not be_able_to(:create, Booth.new(conference: conference)) } + end + + context 'when user is invited for late booth submssion' do + before :each do + create(:cfp, program: conference.program, cfp_type: 'booths', start_date: Date.current - 6.days, end_date: Date.current - 6.days) + create(:invite, conference_id: conference.id, invite_for: (t 'booth').capitalize.to_s, user_id: user.id, end_date: Date.current + 6.days) + end + + it{ should be_able_to(:new, Booth.new(conference: conference)) } + it{ should be_able_to(:create, Booth.new(conference: conference)) } + end + + context 'when user is invited for late booth submssion but invitation expires' do + before :each do + create(:cfp, program: conference.program, cfp_type: 'booths', start_date: Date.current - 6.days, end_date: Date.current - 6.days) + create(:invite, conference_id: conference.id, invite_for: (t 'booth').capitalize.to_s, user_id: user.id, end_date: Date.current - 2.days) + end + + it{ should_not be_able_to(:new, Booth.new(conference: conference)) } + it{ should_not be_able_to(:create, Booth.new(conference: conference)) } + end + end + end # Test for user can register or not + context 'when user is not a speaker with event confirmed' do let(:conference) { create(:conference) }