2012-09-02 11:37:34 +00:00
|
|
|
class Ability
|
|
|
|
include CanCan::Ability
|
|
|
|
|
|
|
|
def initialize(user)
|
2013-09-29 02:31:28 +00:00
|
|
|
can :read, Mac # Anonymous can read mac
|
|
|
|
can :scan, Mac # Need anonymous so CRON can scan
|
2014-02-09 12:01:52 +00:00
|
|
|
can :read, Resource
|
2014-02-14 07:02:11 +00:00
|
|
|
can :read, ResourceCategory
|
2013-02-01 10:37:30 +00:00
|
|
|
|
2012-09-16 01:41:55 +00:00
|
|
|
if !user.nil?
|
2013-01-26 01:21:42 +00:00
|
|
|
|
2013-01-25 13:01:02 +00:00
|
|
|
# By default, users can only see their own stuff
|
|
|
|
can :read, Card, :user_id => user.id
|
|
|
|
can :read, Certification
|
2013-09-29 02:31:28 +00:00
|
|
|
can :read_details, Mac
|
2013-02-01 10:37:30 +00:00
|
|
|
can [:update], Mac, :user_id => nil
|
|
|
|
can [:create,:update], Mac, :user_id => user.id
|
2014-02-09 12:13:35 +00:00
|
|
|
can [:create,:update,:destroy], Resource, :user_id => user.id
|
2013-10-11 03:58:19 +00:00
|
|
|
can :read, Payment, :user_id => user.id
|
2013-01-25 13:01:02 +00:00
|
|
|
can :read, UserCertification, :user_id => user.id
|
2014-01-24 00:50:00 +00:00
|
|
|
can :read, User, :id => user.id #TODO: why can users update themselves? Maybe because Devise doesn't check users/edit?
|
2013-12-13 10:34:52 +00:00
|
|
|
can :compose_email, User
|
|
|
|
can :send_email, User
|
2013-01-25 13:01:02 +00:00
|
|
|
|
2013-12-02 09:03:40 +00:00
|
|
|
if user.card_access_enabled
|
|
|
|
can :access_doors_remotely, :door_access
|
2014-02-23 12:55:00 +00:00
|
|
|
can :authorize, Card # used for interlock card/certification auth
|
2013-12-02 09:03:40 +00:00
|
|
|
end
|
|
|
|
|
2013-01-25 13:01:02 +00:00
|
|
|
# Instructors can manage certs and see users
|
2013-01-25 10:12:25 +00:00
|
|
|
if user.instructor?
|
|
|
|
can :manage, Certification
|
2013-01-26 09:21:41 +00:00
|
|
|
can [:create,:read], User, :hidden => [nil,false]
|
2013-05-03 07:16:02 +00:00
|
|
|
can [:create,:read], UserCertification
|
|
|
|
can [:update,:destroy], UserCertification, :created_by => user.id
|
2013-01-25 10:12:25 +00:00
|
|
|
end
|
2013-01-25 13:01:02 +00:00
|
|
|
# Users can see others' stuff if they've been oriented
|
|
|
|
unless user.orientation.blank?
|
2014-01-24 00:50:00 +00:00
|
|
|
can [:read,:new_member_report,:activity], User, :hidden => [nil,false]
|
2013-01-25 13:01:02 +00:00
|
|
|
can :read, UserCertification
|
2014-02-14 07:02:11 +00:00
|
|
|
can [:create,:update], Resource, :user_id => [nil,user.id]
|
|
|
|
can [:create,:update,:destroy], ResourceCategory
|
2013-01-25 13:01:02 +00:00
|
|
|
end
|
2013-01-26 01:21:42 +00:00
|
|
|
|
2013-08-28 15:19:01 +00:00
|
|
|
# Accountants can manage payments
|
2013-02-12 08:58:17 +00:00
|
|
|
if user.accountant?
|
|
|
|
can :manage, Payment
|
2013-08-28 15:19:01 +00:00
|
|
|
can :manage, Ipn
|
|
|
|
can :manage, PaypalCsv
|
2013-02-12 08:58:17 +00:00
|
|
|
end
|
|
|
|
|
2013-02-09 09:51:35 +00:00
|
|
|
# Admins can manage all
|
|
|
|
if user.admin?
|
|
|
|
can :manage, :all
|
|
|
|
end
|
|
|
|
|
2014-03-03 02:06:39 +00:00
|
|
|
# Prevent most destruction for now
|
2013-05-24 06:25:09 +00:00
|
|
|
#cannot :destroy, User
|
|
|
|
#cannot :destroy, Card
|
2013-01-26 01:21:42 +00:00
|
|
|
cannot :destroy, Certification
|
2013-02-01 10:37:30 +00:00
|
|
|
cannot :destroy, Mac
|
|
|
|
cannot :destroy, MacLog
|
2013-05-03 07:16:02 +00:00
|
|
|
#cannot :destroy, UserCertification
|
2013-01-26 01:21:42 +00:00
|
|
|
cannot :destroy, DoorLog
|
2013-02-12 08:58:17 +00:00
|
|
|
# no exception for destroying payments
|
2012-09-16 01:41:55 +00:00
|
|
|
end
|
2012-09-02 11:37:34 +00:00
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# The second argument is the resource the user can perform the action on. If you pass
|
|
|
|
# :all it will apply to every resource. Otherwise pass a Ruby class of the resource.
|
|
|
|
#
|
|
|
|
# The third argument is an optional hash of conditions to further filter the objects.
|
|
|
|
# For example, here the user can only update published articles.
|
|
|
|
#
|
|
|
|
# can :update, Article, :published => true
|
|
|
|
#
|
|
|
|
# See the wiki for details: https://github.com/ryanb/cancan/wiki/Defining-Abilities
|
|
|
|
end
|
|
|
|
end
|