2018-05-07 16:47:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2013-01-07 09:04:09 +01:00
|
|
|
class Ability
|
|
|
|
|
include CanCan::Ability
|
|
|
|
|
|
2015-04-13 16:47:07 +02:00
|
|
|
# Initializes the ability class
|
2014-07-23 16:24:05 +02:00
|
|
|
def initialize(user)
|
2015-04-13 16:47:07 +02:00
|
|
|
user ||= User.new
|
2014-08-12 11:51:59 +03:00
|
|
|
|
|
|
|
|
if user.new_record?
|
2015-04-13 16:47:07 +02:00
|
|
|
not_signed_in
|
2014-07-23 16:24:05 +02:00
|
|
|
else
|
2015-01-12 23:13:10 +02:00
|
|
|
signed_in(user)
|
2017-07-13 01:23:48 +05:30
|
|
|
common_abilities_for_admins(user) if user.roles.any? || user.is_admin?
|
2014-07-23 16:24:05 +02:00
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|
2014-08-12 11:51:59 +03:00
|
|
|
|
2015-04-13 16:47:07 +02:00
|
|
|
# Abilities for not signed in users (guests)
|
|
|
|
|
def not_signed_in
|
|
|
|
|
can [:index], Conference
|
|
|
|
|
can [:show], Conference do |conference|
|
2018-05-08 14:17:30 -07:00
|
|
|
conference.splashpage&.public == true
|
2015-04-13 16:47:07 +02:00
|
|
|
end
|
2026-03-02 13:09:08 +05:30
|
|
|
can :code_of_conduct, Conference
|
2015-04-13 16:47:07 +02:00
|
|
|
# Can view the schedule
|
2016-06-30 16:53:15 +02:00
|
|
|
can [:schedule, :events], Conference do |conference|
|
2015-10-25 13:29:02 +02:00
|
|
|
conference.program.cfp && conference.program.schedule_public
|
2015-04-13 16:47:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
can :show, Event do |event|
|
|
|
|
|
event.state == 'confirmed'
|
|
|
|
|
end
|
|
|
|
|
|
2019-05-24 15:11:53 +02:00
|
|
|
can [:show, :events, :app], Schedule do |schedule|
|
2019-03-05 21:00:38 +01:00
|
|
|
schedule.program.schedule_public
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-13 16:47:07 +02:00
|
|
|
# can view Commercials of confirmed Events
|
2019-07-16 22:12:13 -07:00
|
|
|
can :show, Commercial, commercialable: Event.where(state: 'confirmed')
|
2016-03-24 17:42:00 +05:30
|
|
|
can [:show, :create], User
|
2019-03-05 21:17:52 +01:00
|
|
|
|
2019-03-05 21:23:14 +01:00
|
|
|
can [:index, :show], Survey, surveyable_type: 'Conference'
|
|
|
|
|
|
2019-03-05 21:17:52 +01:00
|
|
|
# Things that are possible without ichain enabled that are **not*+ possible with ichain mode enabled.
|
2022-05-06 14:27:15 +02:00
|
|
|
if ENV.fetch('OSEM_ICHAIN_ENABLED', nil) != 'true'
|
2019-03-05 21:17:52 +01:00
|
|
|
# There is no reliable way for this workflow (enable not logged in users to fill out a form, then telling
|
|
|
|
|
# them to sign up once they submit) in ichain. So enable it only without ichain.
|
|
|
|
|
|
|
|
|
|
# FIXME: The following abilities need to be checked. Are they about the type of workflow mentioned above? Or are
|
|
|
|
|
# they just here because they worked in development mode (without ichain). We are suspicious that it's the latter!
|
2016-03-17 14:54:35 +05:30
|
|
|
can :show, Registration do |registration|
|
2015-04-23 11:50:22 +02:00
|
|
|
registration.new_record?
|
|
|
|
|
end
|
2016-03-17 14:54:35 +05:30
|
|
|
|
|
|
|
|
can [:new, :create], Registration do |registration|
|
2016-05-04 23:46:52 +02:00
|
|
|
conference = registration.conference
|
|
|
|
|
conference.registration_open? && registration.new_record? && !conference.registration_limit_exceeded?
|
2016-03-17 14:54:35 +05:30
|
|
|
end
|
|
|
|
|
|
2015-10-25 13:29:02 +02:00
|
|
|
can :show, Event do |event|
|
2015-04-23 11:50:22 +02:00
|
|
|
event.new_record?
|
|
|
|
|
end
|
2015-10-25 13:29:02 +02:00
|
|
|
|
|
|
|
|
can [:new, :create], Event do |event|
|
|
|
|
|
event.program.cfp_open? && event.new_record?
|
|
|
|
|
end
|
2015-04-16 18:34:41 +03:00
|
|
|
end
|
2015-04-13 16:47:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Abilities for signed in users
|
|
|
|
|
def signed_in(user)
|
|
|
|
|
# Abilities from not_signed_in user are also inherited
|
|
|
|
|
not_signed_in
|
|
|
|
|
can :manage, User, id: user.id
|
|
|
|
|
|
|
|
|
|
can :manage, Registration, user_id: user.id
|
|
|
|
|
|
2016-03-17 14:54:35 +05:30
|
|
|
can [:new, :create], Registration do |registration|
|
2016-05-04 23:46:52 +02:00
|
|
|
conference = registration.conference
|
2017-08-08 05:19:02 +05:30
|
|
|
if conference.user_registered? user
|
|
|
|
|
false
|
|
|
|
|
elsif conference.program.speakers.confirmed.include?(user) && conference.registration_period
|
|
|
|
|
true
|
|
|
|
|
else
|
|
|
|
|
conference.registration_open? && !conference.registration_limit_exceeded?
|
|
|
|
|
end
|
2016-03-17 14:54:35 +05:30
|
|
|
end
|
|
|
|
|
|
2015-04-13 16:47:07 +02:00
|
|
|
can :index, Ticket
|
|
|
|
|
can :manage, TicketPurchase, user_id: user.id
|
2016-08-05 20:17:27 +05:30
|
|
|
can [:new, :create], Payment, user_id: user.id
|
2017-06-29 19:25:10 +05:30
|
|
|
can [:index, :show], PhysicalTicket, user: user
|
2015-04-13 16:47:07 +02:00
|
|
|
|
2017-08-16 11:42:57 +03:00
|
|
|
can [:new, :create], Booth do |booth|
|
|
|
|
|
booth.new_record? && booth.conference.program.cfps.for_booths.try(:open?)
|
|
|
|
|
end
|
2017-07-20 14:20:46 +03:00
|
|
|
|
|
|
|
|
can [:edit, :update, :index, :show], Booth do |booth|
|
|
|
|
|
booth.users.include?(user)
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-13 16:47:07 +02:00
|
|
|
can [:create, :destroy], Subscription, user_id: user.id
|
|
|
|
|
|
2016-05-19 11:47:41 +02:00
|
|
|
can [:new, :create], Event do |event|
|
|
|
|
|
event.program.cfp_open? && event.new_record?
|
2015-04-13 16:47:07 +02:00
|
|
|
end
|
2016-03-12 21:08:43 +05:30
|
|
|
|
2017-08-09 13:26:38 +05:30
|
|
|
can [:update, :show, :index], Event do |event|
|
2016-05-19 11:47:41 +02:00
|
|
|
event.users.include?(user)
|
2016-03-12 21:08:43 +05:30
|
|
|
end
|
2015-04-13 16:47:07 +02:00
|
|
|
|
|
|
|
|
# can manage the commercials of their own events
|
|
|
|
|
can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id)
|
2017-06-10 19:36:12 +03:00
|
|
|
|
2018-02-09 19:07:10 +02:00
|
|
|
# can view and reply to a survey
|
|
|
|
|
can [:index, :show, :reply], Survey, surveyable_type: 'Conference'
|
|
|
|
|
can [:index, :show, :reply], Survey, surveyable_type: 'Registration', surveyable_id: user.registrations.pluck(:conference_id)
|
|
|
|
|
|
|
|
|
|
# TODO: this needs to check for more, eg.
|
|
|
|
|
# if survey target is after_conference, check whether or not the conference is over
|
|
|
|
|
# if not, do not allow replies.
|
|
|
|
|
|
|
|
|
|
# do not allow replies before the start_date or after the end_date of survey
|
2022-03-11 11:44:48 -08:00
|
|
|
cannot :reply, Survey, &:closed?
|
2016-06-28 18:16:06 +03:00
|
|
|
|
2017-06-10 19:36:12 +03:00
|
|
|
can [:destroy], Openid
|
2017-07-12 16:35:09 +03:00
|
|
|
|
|
|
|
|
can [:new, :create], Track do |track|
|
|
|
|
|
track.new_record? && track.program.cfps.for_tracks.try(:open?)
|
|
|
|
|
end
|
|
|
|
|
|
2017-07-14 15:57:34 +03:00
|
|
|
can [:index, :show, :restart, :confirm, :withdraw], Track, submitter_id: user.id
|
|
|
|
|
|
|
|
|
|
can [:edit, :update], Track do |track|
|
|
|
|
|
user == track.submitter && !(track.accepted? || track.confirmed?)
|
2017-07-12 16:35:09 +03:00
|
|
|
end
|
2015-04-13 16:47:07 +02:00
|
|
|
end
|
2017-07-13 01:23:48 +05:30
|
|
|
|
|
|
|
|
# Abilities for users with roles wandering around in non-admin views.
|
|
|
|
|
def common_abilities_for_admins(user)
|
|
|
|
|
can :access, Admin
|
|
|
|
|
can :manage, :all if user.is_admin?
|
|
|
|
|
|
|
|
|
|
conf_ids_for_organizer = Conference.with_role(:organizer, user).pluck(:id)
|
|
|
|
|
conf_ids_for_cfp = Conference.with_role(:cfp, user).pluck(:id)
|
|
|
|
|
conf_ids_for_info_desk = Conference.with_role(:info_desk, user).pluck(:id)
|
|
|
|
|
|
|
|
|
|
if conf_ids_for_organizer
|
|
|
|
|
# To access splashpage of their conference if it is not public
|
|
|
|
|
can :show, Conference, id: conf_ids_for_organizer
|
|
|
|
|
# To access conference/proposals/registrations
|
|
|
|
|
can :manage, Registration, conference_id: conf_ids_for_organizer
|
|
|
|
|
# To access conference/proposals
|
|
|
|
|
can :manage, Event, program: { conference_id: conf_ids_for_organizer }
|
2026-05-31 21:23:54 +05:30
|
|
|
can :manage, Commercial, commercialable_type: 'Event',
|
|
|
|
|
commercialable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organizer).pluck(:id)).pluck(:id)
|
2017-07-13 01:23:48 +05:30
|
|
|
# To access comment link in menu bar
|
|
|
|
|
can :index, Comment, commentable_type: 'Event',
|
2018-11-13 18:01:49 -08:00
|
|
|
commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organizer).pluck(:id)).pluck(:id)
|
2017-07-13 01:23:48 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if conf_ids_for_cfp
|
|
|
|
|
# To access comment link in menu bar
|
|
|
|
|
can :index, Comment, commentable_type: 'Event',
|
2018-11-13 18:01:49 -08:00
|
|
|
commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_cfp).pluck(:id)).pluck(:id)
|
2017-07-13 01:23:48 +05:30
|
|
|
# To access conference/proposals
|
|
|
|
|
can :manage, Event, program: { conference_id: conf_ids_for_cfp }
|
2026-05-31 21:23:54 +05:30
|
|
|
can :manage, Commercial, commercialable_type: 'Event',
|
|
|
|
|
commercialable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_cfp).pluck(:id)).pluck(:id)
|
2017-07-13 01:23:48 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if conf_ids_for_info_desk
|
|
|
|
|
# To access conference/proposals/registrations
|
|
|
|
|
can :manage, Registration, conference_id: conf_ids_for_info_desk
|
|
|
|
|
end
|
|
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|