Created
August 23, 2011 09:30
-
-
Save philsmy/1164741 to your computer and use it in GitHub Desktop.
our ability class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Ability | |
include CanCan::Ability | |
def initialize(user) | |
user ||= User.new # guest user | |
if user.role? :super_admin | |
can :manage, :all | |
else | |
if user.role? :live_trader | |
can :admin, LiveEvent | |
end | |
if user.role? :horse_trader | |
can :horse_admin, Event | |
end | |
if user.role? :channel_admin | |
can :manage, Channel | |
end | |
if user.role? :device_admin | |
can :manage, Device | |
end | |
if user.role? :ost | |
can :read, Customer.first | |
end | |
can do |action, subject_class, subject| | |
# Rails.logger.debug "action: #{action}" | |
user.roles.find_all_by_action(aliases_for_action(action)).any? do |role| | |
role.authorizable_type == subject_class.to_s && | |
(subject.nil? || role.authorizable_id.nil? || role.authorizable_id == subject.id) | |
end | |
end | |
# can always manage ourselves | |
can :manage, user | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment