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
|
2015-01-12 23:13:10 +02:00
|
|
|
elsif user.roles.any? || user.is_admin
|
2017-06-24 05:03:24 +05:30
|
|
|
common_abilities_for_admins(user)
|
2014-07-23 16:24:05 +02:00
|
|
|
else
|
2015-01-12 23:13:10 +02:00
|
|
|
signed_in(user)
|
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
|
|
|
|
2017-06-24 05:03:24 +05:30
|
|
|
# Abilities for users with roles wandering around in non-admin views.
|
|
|
|
|
def common_abilities_for_admins(user)
|
|
|
|
|
signed_in(user)
|
|
|
|
|
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 }
|
|
|
|
|
|
|
|
|
|
# To access comment link in menu bar
|
|
|
|
|
can :index, Comment, commentable_type: 'Event',
|
|
|
|
|
commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organizer).pluck(:id)).pluck(:id)
|
|
|
|
|
elsif conf_ids_for_cfp
|
|
|
|
|
|
|
|
|
|
can :index, Comment, commentable_type: 'Event',
|
|
|
|
|
commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_cfp).pluck(:id)).pluck(:id)
|
|
|
|
|
can :manage, Event, program: { conference_id: conf_ids_for_cfp }
|
|
|
|
|
|
|
|
|
|
elsif conf_ids_for_info_desk
|
|
|
|
|
can :manage, Registration, conference_id: conf_ids_for_info_desk
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
can :access, Admin
|
|
|
|
|
can :manage, :all if user.is_admin
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-13 16:47:07 +02:00
|
|
|
# Abilities for not signed in users (guests)
|
|
|
|
|
def not_signed_in
|
2017-06-13 20:57:55 +05:30
|
|
|
can [:index], Organization
|
2015-04-13 16:47:07 +02:00
|
|
|
can [:index], Conference
|
|
|
|
|
can [:show], Conference do |conference|
|
|
|
|
|
conference.splashpage && conference.splashpage.public == true
|
|
|
|
|
end
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
|
|
# can view Commercials of confirmed Events
|
|
|
|
|
can :show, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(state: 'confirmed').pluck(:id)
|
2016-03-24 17:42:00 +05:30
|
|
|
can [:show, :create], User
|
2016-03-22 18:14:40 +01:00
|
|
|
unless ENV['OSEM_ICHAIN_ENABLED'] == 'true'
|
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
|
2017-03-24 20:52:27 +05:30
|
|
|
|
|
|
|
|
can [:show, :events], Schedule do |schedule|
|
|
|
|
|
schedule.program.schedule_public
|
|
|
|
|
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-05-03 23:42:53 +03:00
|
|
|
conference.registration_open? && !conference.registration_limit_exceeded? || conference.program.speakers.confirmed.include?(user)
|
2016-03-17 14:54:35 +05:30
|
|
|
end
|
|
|
|
|
|
2017-06-06 20:04:39 +05:30
|
|
|
can :index, Organization
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-05-19 11:47:41 +02:00
|
|
|
can [:update, :show, :delete, :index], Event do |event|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
can [:destroy], Openid
|
2015-04-13 16:47:07 +02:00
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|