set up abilities

This commit is contained in:
Stella Rouzi 2014-07-13 08:50:46 +03:00
parent c3ed57e3e9
commit 40098183e4
4 changed files with 152 additions and 12 deletions

View file

@ -2,15 +2,6 @@ class Ability
include CanCan::Ability
def initialize(user)
# Define abilities for the passed in user here. For example:
#
user ||= User.new # guest user (not logged in)
# if user.admin?
# can :manage, :all
# else
# can :read, :all
# end
#
# The first argument to `can` is the action you are giving the user permission to do.
# If you pass :manage it will apply to every action. Other common actions here are
# :read, :create, :update and :destroy.
@ -24,5 +15,49 @@ class Ability
# can :update, Article, :published => true
#
# See the wiki for details: https://github.com/ryanb/cancan/wiki/Defining-Abilities
# Order Abilities
# (Check https://github.com/CanCanCommunity/cancancan/wiki/Ability-Precedence)
user ||= User.new # guest user (not logged in)
# Abilities per role
# Abilities for signed in users
unless user.new_record?
# Can manage any conference for which user is organizer
# We need this so that the user menus will properly display admin options
can :manage, Conference, id: Conference.with_role(:organizer, user).map(&:id)
# Conference Registration
can :manage, :conference_registration
# Proposals
# Users can edit their own proposals
# Organizer and CfP team can edit any proposal they want
# Can manage an event if the user is a speaker or a submitter of that event
can :manage, Event do |event|
event.event_users.where(:user_id => user.id).present?
end
# Also an organizer can manage that Event
# With the following ability organizers can access the event/proposal directly from
# the same link as submitters: /conference/conference_id/proposal/id/edit
can :manage, Event, conference_id: Conference.with_role(:organizer, user).map(&:id)
can :manage, Event, conference_id: Conference.with_role(:cfp, user).map(&:id)
can :create, Event
can :manage, EventAttachment do |ea|
Event.find(ea.event_id).event_users.where(user_id: user.id).present?
end
can :create, EventAttachment
end
# Abilities for everyone, even guests (not logged in users)
can :show, Conference#, make_conference_public: true
can :show, Event # if confirmed...?
can :index, :schedule # show?
end
end