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)
|
2014-08-12 11:51:59 +03:00
|
|
|
# Order Abilities
|
|
|
|
|
# (Check https://github.com/CanCanCommunity/cancancan/wiki/Ability-Precedence)
|
|
|
|
|
# Check roles of user, using rolify. Role name is *case sensitive*
|
|
|
|
|
# user.is_organizer? or user.has_role? :organizer
|
|
|
|
|
# user.is_cfp_of? Conference or user.has_role? :cfp, Conference
|
|
|
|
|
# user.is_info_desk_of? Conference
|
2016-04-03 13:24:07 +05:30
|
|
|
# user.is_volunteers_coordinator_of? Conference
|
2014-08-12 11:51:59 +03:00
|
|
|
# user.is_attendee_of? Conference
|
|
|
|
|
# The following is wrong because a user will only have 'cfp' role for a specific conference
|
|
|
|
|
# user.is_cfp? # This is always false
|
|
|
|
|
|
2015-04-13 16:47:07 +02:00
|
|
|
user ||= User.new
|
2014-08-12 11:51:59 +03:00
|
|
|
|
2015-04-13 16:47:07 +02:00
|
|
|
# This is what sets up the different abilities
|
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
|
|
|
# Checks if the user does not have any role and is not an admin
|
|
|
|
|
elsif user.roles.any? || user.is_admin
|
|
|
|
|
signed_in_with_roles(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
|
|
|
|
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|
|
|
|
|
|
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-03 16:05:59 +05:30
|
|
|
can [:index, :show], PhysicalTicket, user_id: user.id
|
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
|
|
|
|
|
|
|
|
|
|
# Abilities for signed in users with roles
|
|
|
|
|
def signed_in_with_roles(user)
|
|
|
|
|
# Abilities from not_signed_in and signed_in are also inherited
|
|
|
|
|
signed_in(user)
|
|
|
|
|
|
2017-06-13 04:39:47 +05:30
|
|
|
signed_in_with_organization_admin_role(user) if user.has_role? :organization_admin, :any
|
2015-09-01 13:01:57 +02:00
|
|
|
signed_in_with_organizer_role(user) if user.has_role? :organizer, :any
|
|
|
|
|
signed_in_with_cfp_role(user) if user.has_role? :cfp, :any
|
|
|
|
|
signed_in_with_info_desk_role(user) if user.has_role? :info_desk, :any
|
2016-04-03 13:24:07 +05:30
|
|
|
signed_in_with_volunteers_coordinator_role(user) if user.has_role? :volunteers_coordinator, :any
|
2015-04-14 17:33:59 +02:00
|
|
|
|
|
|
|
|
# for users with any role
|
2015-09-15 12:39:36 +02:00
|
|
|
can :access, Admin
|
2015-04-14 17:33:59 +02:00
|
|
|
can [:show], Conference
|
|
|
|
|
can :index, Commercial, commercialable_type: 'Conference'
|
|
|
|
|
cannot [:edit, :update, :destroy], Question, global: true
|
|
|
|
|
# for admins
|
|
|
|
|
can :manage, :all if user.is_admin
|
2015-10-25 13:29:02 +02:00
|
|
|
|
2017-01-10 17:07:28 +02:00
|
|
|
# even admin cannot create new users with ICHAIN enabled
|
|
|
|
|
cannot [:new, :create], User if ENV['OSEM_ICHAIN_ENABLED'] == 'true'
|
|
|
|
|
|
2016-05-24 23:54:46 +05:30
|
|
|
cannot :revert_object, PaperTrail::Version do |version|
|
|
|
|
|
(version.event == 'create' && %w(Conference User Event).include?(version.item_type))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
cannot :revert_attribute, PaperTrail::Version do |version|
|
|
|
|
|
version.event != 'update' || version.item.nil?
|
|
|
|
|
end
|
|
|
|
|
|
2015-10-25 13:29:02 +02:00
|
|
|
cannot :destroy, Program
|
2015-11-07 11:43:36 +02:00
|
|
|
# Do not delete venue, when there are rooms being used
|
|
|
|
|
cannot :destroy, Venue do |venue|
|
|
|
|
|
venue.conference.program.events.where.not(room_id: nil).any?
|
|
|
|
|
end
|
2017-06-19 17:35:46 +03:00
|
|
|
|
|
|
|
|
# Can't create cfp if there are no available cfp types
|
|
|
|
|
cannot [:new, :create], Cfp do |cfp|
|
|
|
|
|
cfp.program.remaining_cfp_types.empty?
|
|
|
|
|
end
|
2015-04-14 17:33:59 +02:00
|
|
|
end
|
2014-08-12 11:51:59 +03:00
|
|
|
|
2017-06-13 04:39:47 +05:30
|
|
|
def signed_in_with_organization_admin_role(user)
|
|
|
|
|
org_ids_for_organization_admin = Organization.with_role(:organization_admin, user).pluck(:id)
|
2014-08-12 11:51:59 +03:00
|
|
|
|
2017-06-13 04:39:47 +05:30
|
|
|
can :manage, Organization, id: org_ids_for_organization_admin
|
|
|
|
|
can :manage, Conference, organization_id: org_ids_for_organization_admin
|
|
|
|
|
conf_ids_for_organization_admin = []
|
|
|
|
|
org_ids_for_organization_admin.each do |org_id|
|
|
|
|
|
conf_ids_for_organization_admin += Organization.find(org_id).conferences.pluck(:id)
|
|
|
|
|
end
|
|
|
|
|
can [:index, :show], Role
|
|
|
|
|
can [:edit, :update], Role do |role|
|
|
|
|
|
role.resource_type == 'Organization' && (org_ids_for_organization_admin.include? role.resource_id)
|
|
|
|
|
end
|
|
|
|
|
signed_in_with_organizer_role(user, conf_ids_for_organization_admin)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def signed_in_with_organizer_role(user, conf_ids_for_organization_admin = [])
|
|
|
|
|
# ids of all the conferences for which the user has the 'organizer' role and
|
|
|
|
|
# conferences that belong to organizations for which user is 'organization_admin'
|
|
|
|
|
conf_ids_for_organization_admin_and_organizer = conf_ids_for_organization_admin.concat(Conference.with_role(:organizer, user).pluck(:id)).uniq
|
|
|
|
|
can :manage, Resource, conference_id: conf_ids_for_organization_admin_and_organizer
|
2015-04-14 17:33:59 +02:00
|
|
|
can [:new, :create], Conference if user.has_role?(:organizer, :any)
|
2017-06-13 04:39:47 +05:30
|
|
|
can :manage, Conference, id: conf_ids_for_organization_admin_and_organizer
|
|
|
|
|
can :manage, Splashpage, conference_id: conf_ids_for_organization_admin_and_organizer
|
|
|
|
|
can :manage, Contact, conference_id: conf_ids_for_organization_admin_and_organizer
|
|
|
|
|
can :manage, EmailSettings, conference_id: conf_ids_for_organization_admin_and_organizer
|
|
|
|
|
can :manage, Campaign, conference_id: conf_ids_for_organization_admin_and_organizer
|
|
|
|
|
can :manage, Target, conference_id: conf_ids_for_organization_admin_and_organizer
|
2015-04-14 17:33:59 +02:00
|
|
|
can :manage, Commercial, commercialable_type: 'Conference',
|
2017-06-13 04:39:47 +05:30
|
|
|
commercialable_id: conf_ids_for_organization_admin_and_organizer
|
|
|
|
|
can :manage, Registration, conference_id: conf_ids_for_organization_admin_and_organizer
|
|
|
|
|
can :manage, RegistrationPeriod, conference_id: conf_ids_for_organization_admin_and_organizer
|
|
|
|
|
can :manage, Question, conference_id: conf_ids_for_organization_admin_and_organizer
|
2015-04-14 17:33:59 +02:00
|
|
|
can :manage, Question do |question|
|
2017-06-13 04:39:47 +05:30
|
|
|
!(question.conferences.pluck(:id) & conf_ids_for_organization_admin_and_organizer).empty?
|
|
|
|
|
end
|
|
|
|
|
can :manage, Vposition, conference_id: conf_ids_for_organization_admin_and_organizer
|
|
|
|
|
can :manage, Vday, conference_id: conf_ids_for_organization_admin_and_organizer
|
|
|
|
|
can :manage, Program, conference_id: conf_ids_for_organization_admin_and_organizer
|
|
|
|
|
can :manage, Schedule, program: { conference_id: conf_ids_for_organization_admin_and_organizer }
|
|
|
|
|
can :manage, EventSchedule, schedule: { program: { conference_id: conf_ids_for_organization_admin_and_organizer } }
|
|
|
|
|
can :manage, Cfp, program: { conference_id: conf_ids_for_organization_admin_and_organizer}
|
|
|
|
|
can :manage, Event, program: { conference_id: conf_ids_for_organization_admin_and_organizer}
|
|
|
|
|
can :manage, EventType, program: { conference_id: conf_ids_for_organization_admin_and_organizer}
|
|
|
|
|
can :manage, Track, program: { conference_id: conf_ids_for_organization_admin_and_organizer}
|
|
|
|
|
can :manage, DifficultyLevel, program: { conference_id: conf_ids_for_organization_admin_and_organizer}
|
2015-04-14 17:33:59 +02:00
|
|
|
can :manage, Commercial, commercialable_type: 'Event',
|
2017-06-13 04:39:47 +05:30
|
|
|
commercialable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organization_admin_and_organizer).pluck(:id)).pluck(:id)
|
|
|
|
|
can :manage, Venue, conference_id: conf_ids_for_organization_admin_and_organizer
|
2016-04-09 02:00:32 +05:30
|
|
|
can :manage, Commercial, commercialable_type: 'Venue',
|
2017-06-13 04:39:47 +05:30
|
|
|
commercialable_id: Venue.where(conference_id: conf_ids_for_organization_admin_and_organizer).pluck(:id)
|
|
|
|
|
can :manage, Lodging, conference_id: conf_ids_for_organization_admin_and_organizer
|
|
|
|
|
can :manage, Room, venue: { conference_id: conf_ids_for_organization_admin_and_organizer}
|
|
|
|
|
can :manage, Sponsor, conference_id: conf_ids_for_organization_admin_and_organizer
|
|
|
|
|
can :manage, SponsorshipLevel, conference_id: conf_ids_for_organization_admin_and_organizer
|
|
|
|
|
can :manage, Ticket, conference_id: conf_ids_for_organization_admin_and_organizer
|
2015-08-26 22:09:36 +02:00
|
|
|
can :index, Comment, commentable_type: 'Event',
|
2017-06-13 04:39:47 +05:30
|
|
|
commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organization_admin_and_organizer).pluck(:id)).pluck(:id)
|
2015-01-12 23:13:10 +02:00
|
|
|
|
|
|
|
|
# Abilities for Role (Conference resource)
|
2016-04-03 20:26:00 +05:30
|
|
|
can [:index, :show], Role
|
|
|
|
|
can [:edit, :update, :toggle_user], Role do |role|
|
2017-06-13 04:39:47 +05:30
|
|
|
role.resource_type == 'Conference' && (conf_ids_for_organization_admin_and_organizer.include? role.resource_id)
|
2015-01-12 23:13:10 +02:00
|
|
|
end
|
2016-05-24 23:54:46 +05:30
|
|
|
|
|
|
|
|
can [:index, :revert_object, :revert_attribute], PaperTrail::Version do |version|
|
2017-06-13 04:39:47 +05:30
|
|
|
version.item_type == 'User' || (conf_ids_for_organization_admin_and_organizer.include? version.conference_id)
|
2016-05-24 23:54:46 +05:30
|
|
|
end
|
2015-04-14 17:33:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def signed_in_with_cfp_role(user)
|
|
|
|
|
# ids of all the conferences for which the user has the 'cfp' role
|
2016-04-03 20:26:00 +05:30
|
|
|
conf_ids_for_cfp = Conference.with_role(:cfp, user).pluck(:id)
|
2015-04-14 17:33:59 +02:00
|
|
|
|
2017-02-06 16:11:22 +05:30
|
|
|
can [:index, :show, :update], Resource, conference_id: conf_ids_for_cfp
|
2015-10-25 13:29:02 +02:00
|
|
|
can :manage, Event, program: { conference_id: conf_ids_for_cfp }
|
|
|
|
|
can :manage, EventType, program: { conference_id: conf_ids_for_cfp }
|
|
|
|
|
can :manage, Track, program: { conference_id: conf_ids_for_cfp }
|
|
|
|
|
can :manage, DifficultyLevel, program: { conference_id: conf_ids_for_cfp }
|
2015-04-14 17:33:59 +02:00
|
|
|
can :manage, EmailSettings, conference_id: conf_ids_for_cfp
|
2017-04-07 14:36:18 +03:00
|
|
|
can :manage, Schedule, program: { conference_id: conf_ids_for_cfp }
|
2015-11-07 11:43:36 +02:00
|
|
|
can :manage, Room, venue: { conference_id: conf_ids_for_cfp }
|
2016-02-08 12:50:58 +01:00
|
|
|
can :show, Venue, conference_id: conf_ids_for_cfp
|
2016-04-09 02:00:32 +05:30
|
|
|
can :show, Commercial, commercialable_type: 'Venue', commercialable_id: Venue.where(conference_id: conf_ids_for_cfp).pluck(:id)
|
2015-10-25 13:29:02 +02:00
|
|
|
can :manage, Cfp, program: { conference_id: conf_ids_for_cfp }
|
|
|
|
|
can :manage, Program, conference_id: conf_ids_for_cfp
|
2015-04-14 17:33:59 +02:00
|
|
|
can :manage, Commercial, commercialable_type: 'Event',
|
2015-10-25 13:29:02 +02:00
|
|
|
commercialable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_cfp).pluck(:id)).pluck(:id)
|
2015-08-26 22:09:36 +02:00
|
|
|
can :index, Comment, commentable_type: 'Event',
|
2015-10-25 13:29:02 +02:00
|
|
|
commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_cfp).pluck(:id)).pluck(:id)
|
2015-01-12 23:13:10 +02:00
|
|
|
|
|
|
|
|
# Abilities for Role (Conference resource)
|
2016-04-03 20:26:00 +05:30
|
|
|
can [:index, :show], Role
|
2015-01-12 23:13:10 +02:00
|
|
|
|
|
|
|
|
# Can add or remove users from role, when user has that same role for the conference
|
|
|
|
|
# Eg. If you are member of the CfP team, you can add more CfP team members (add users to the role 'CfP')
|
|
|
|
|
can :toggle_user, Role do |role|
|
2016-04-03 20:26:00 +05:30
|
|
|
role.resource_type == 'Conference' && role.name == 'cfp' &&
|
|
|
|
|
(Conference.with_role(:cfp, user).pluck(:id).include? role.resource_id)
|
2015-01-12 23:13:10 +02:00
|
|
|
end
|
2016-08-10 20:42:18 +05:30
|
|
|
|
2016-08-16 18:56:54 +05:30
|
|
|
can [:index, :revert_object, :revert_attribute], PaperTrail::Version, item_type: 'Event', conference_id: conf_ids_for_cfp
|
2017-03-02 17:07:19 +05:30
|
|
|
can [:index, :revert_object, :revert_attribute], PaperTrail::Version, item_type: 'Vote', conference_id: conf_ids_for_cfp
|
2016-08-10 20:42:18 +05:30
|
|
|
can [:index, :revert_object, :revert_attribute], PaperTrail::Version do |version|
|
2016-08-16 18:56:54 +05:30
|
|
|
version.item_type == 'Commercial' && conf_ids_for_cfp.include?(version.conference_id) &&
|
|
|
|
|
(version.object.to_s.include?('Event') || version.object_changes.to_s.include?('Event'))
|
2016-08-10 20:42:18 +05:30
|
|
|
end
|
2015-04-14 17:33:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def signed_in_with_info_desk_role(user)
|
|
|
|
|
# ids of all the conferences for which the user has the 'info_desk' role
|
2016-04-03 20:26:00 +05:30
|
|
|
conf_ids_for_info_desk = Conference.with_role(:info_desk, user).pluck(:id)
|
2015-04-14 17:33:59 +02:00
|
|
|
|
2017-02-06 16:11:22 +05:30
|
|
|
can [:index, :show, :update], Resource, conference_id: conf_ids_for_info_desk
|
2015-04-14 17:33:59 +02:00
|
|
|
can :manage, Registration, conference_id: conf_ids_for_info_desk
|
|
|
|
|
can :manage, Question, conference_id: conf_ids_for_info_desk
|
|
|
|
|
can :manage, Question do |question|
|
|
|
|
|
!(question.conferences.pluck(:id) & conf_ids_for_info_desk).empty?
|
|
|
|
|
end
|
2015-01-12 23:13:10 +02:00
|
|
|
|
2016-04-03 20:26:00 +05:30
|
|
|
# Abilities for Role (Conference resource)
|
|
|
|
|
can [:index, :show], Role
|
2015-01-12 23:13:10 +02:00
|
|
|
|
|
|
|
|
# Can add or remove users from role, when user has that same role for the conference
|
|
|
|
|
# Eg. If you are member of the CfP team, you can add more CfP team members (add users to the role 'CfP')
|
|
|
|
|
can :toggle_user, Role do |role|
|
2016-04-03 20:26:00 +05:30
|
|
|
role.resource_type == 'Conference' && role.name == 'info_desk' &&
|
|
|
|
|
(Conference.with_role(:info_desk, user).pluck(:id).include? role.resource_id)
|
2015-01-12 23:13:10 +02:00
|
|
|
end
|
2015-04-14 17:33:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def signed_in_with_volunteers_coordinator_role(user)
|
|
|
|
|
# ids of all the conferences for which the user has the 'volunteers_coordinator' role
|
2016-04-03 20:26:00 +05:30
|
|
|
conf_ids_for_volunteers_coordinator = Conference.with_role(:volunteers_coordinator, user).pluck(:id)
|
2015-04-14 17:33:59 +02:00
|
|
|
|
2017-02-06 16:11:22 +05:30
|
|
|
can [:index, :show, :update], Resource, conference_id: conf_ids_for_volunteers_coordinator
|
2015-04-14 17:33:59 +02:00
|
|
|
can :manage, Vposition, conference_id: conf_ids_for_volunteers_coordinator
|
|
|
|
|
can :manage, Vday, conference_id: conf_ids_for_volunteers_coordinator
|
2015-01-12 23:13:10 +02:00
|
|
|
|
2016-04-03 20:26:00 +05:30
|
|
|
# Abilities for Role (Conference resource)
|
|
|
|
|
can [:index, :show], Role
|
2015-01-12 23:13:10 +02:00
|
|
|
|
|
|
|
|
# Can add or remove users from role, when user has that same role for the conference
|
|
|
|
|
# Eg. If you are member of the CfP team, you can add more CfP team members (add users to the role 'CfP')
|
|
|
|
|
can :toggle_user, Role do |role|
|
2016-04-03 20:26:00 +05:30
|
|
|
role.resource_type == 'Conference' && role.name == 'volunteers_coordinator' &&
|
|
|
|
|
(Conference.with_role(:volunteers_coordinator, user).pluck(:id).include? role.resource_id)
|
2015-01-12 23:13:10 +02:00
|
|
|
end
|
2014-08-12 11:51:59 +03:00
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|