Class: Ability
- Inherits:
-
Object
- Object
- Ability
- Includes:
- Adminpanel::ApplicationHelper, CanCan::Ability
- Defined in:
- app/models/ability.rb
Instance Method Summary collapse
-
#initialize(user) ⇒ Ability
constructor
A new instance of Ability.
Methods included from Adminpanel::ApplicationHelper
#adminpanel_form_for, #full_title, #is_current_section?, #link_to_add_fields, #main_root_path, #route_symbol, #symbol_class
Methods included from Adminpanel::SharedPagesHelper
#active_tab, #belong_to_object_name, #class_name_downcase, #demodulize_class, #field_value, #get_oauth_link, #is_customized_field?, #pluralize_model, #relationship_ids, #table_type
Methods included from Adminpanel::BreadcrumbsHelper
#breadcrumb_add, #render_breadcrumb
Methods included from Adminpanel::SessionsHelper
#current_user, #current_user=, #sign_in, #sign_out, #signed_in?
Constructor Details
#initialize(user) ⇒ Ability
Returns a new instance of Ability.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/ability.rb', line 5 def initialize(user) if user.nil? elsif user.role.name == 'Admin' can :manage, :all else user.role..each do || if .to_read? can :read, symbol_class(.resource) elsif .to_publish? can :publish, symbol_class(.resource) elsif .to_create? can :create, symbol_class(.resource) elsif .to_update? can :update, symbol_class(.resource) elsif .to_destroy? can :destroy, symbol_class(.resource) elsif .to_manage? can :manage, symbol_class(.resource) end end 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 end |