ability.rb 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. class Ability
  2. include CanCan::Ability
  3. def initialize(user)
  4. # Define abilities for the passed in user here. For example:
  5. #
  6. # user ||= User.new # guest user (not logged in)
  7. # if user.admin?
  8. # can :manage, :all
  9. # else
  10. # can :read, :all
  11. # end
  12. if user
  13. can :dashboard # allow access to dashboard
  14. can :access, :rails_admin # only allow admin users to access Rails Admin
  15. cannot :history, :all
  16. cannot :import, :all
  17. cannot :export, :all
  18. cannot :destroy, :all
  19. if user.email == AdminUser::SUPER_ADMIN
  20. can :manage, :all
  21. # can :export, :all
  22. # can :read, :all
  23. # can :destroy, :all
  24. # can :create, :all
  25. # can :update, :all
  26. else
  27. user.permissions.each do |permission|
  28. eval "can :#{permission.can}, #{permission.model}"
  29. end
  30. can :update, AdminUser, :id => user.id
  31. can :read, AdminUser, :id => user.id
  32. cannot :history, :all
  33. # cannot :destroy, ChannelQrcode
  34. # cannot :refund_at_once, Project
  35. # cannot :destroy, ["ProductAttr", "ProductAttrKey", "ProductAttrValue"]
  36. # cannot :delete, ["ProductAttr", "ProductAttrKey", "ProductAttrValue"]
  37. # cannot :export, ["ProductAttr", "ProductAttrKey", "ProductAttrValue"]
  38. end
  39. #cannot :destroy, DianshiOrder
  40. # cannot :new, DianbiOrder
  41. # cannot :new, VipOrder
  42. # cannot :new, DianshiOrder
  43. # cannot :update, User
  44. # cannot :generate_analyze_report_record, AnalyzeReport
  45. # can :generate_analyze_report_record, AnalyzeReport, :remark => "当前汇总"
  46. end
  47. #
  48. # The first argument to `can` is the action you are giving the user
  49. # permission to do.
  50. # If you pass :manage it will apply to every action. Other common actions
  51. # here are :read, :create, :update and :destroy.
  52. #
  53. # The second argument is the resource the user can perform the action on.
  54. # If you pass :all it will apply to every resource. Otherwise pass a Ruby
  55. # class of the resource.
  56. #
  57. # The third argument is an optional hash of conditions to further filter the
  58. # objects.
  59. # For example, here the user can only update published articles.
  60. #
  61. # can :update, Article, :published => true
  62. #
  63. # See the wiki for details:
  64. # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
  65. end
  66. end