Class: Ability
- Inherits:
-
Object
- Object
- Ability
- Includes:
- CanCan::Ability, Models
- Defined in:
- app/models/ability.rb
Overview
@File Name :ability.rb
@Company Name :Mindfire Solutions Pvt. Ltd.
@Creator Name :Indranil Mukherjee
@Date Created :2012-06-04
@Date Modified :2012-06-14
@Last Modification Details :Making it as mcms project standard
@Purpose :This class is responsible for defining the abilities
of a particular user/current user
Instance Method Summary collapse
-
#initialize(user) ⇒ Ability
constructor
@Params : No parameter @Returns : Nothing is returned @Purpose : Managing user roles.
Methods included from Models
#get_all_plugins, #get_models, get_module_name, #get_relations, #manipulated_array
Constructor Details
#initialize(user) ⇒ Ability
@Params : No parameter
@Returns : Nothing is returned
@Purpose : Managing user roles
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/models/ability.rb', line 35 def initialize(user) #fetching all the roles of current user roles = Role.fetch_roles user #defining abilities of current user roles.each do |role| can :manage, :all if role == "superuser" # plugin access for a particular user role @accessible_plugins = Plugin.find_all_by_role_id(Role.find_by_title(role).id) @accessible_plugins.each do |plugin| # models = get_relations plugin.role_module # getting associated models models = ExistingModel.find_all_by_plugin_name(plugin.role_module.to_s) models.each do |model| # defining access control can :read , model.model_name.constantize if plugin.role_read? # setting read authorization can :create , model.model_name.constantize if plugin.role_create? # setting create authorization can :update , model.model_name.constantize if plugin.role_update? # setting update authorization can :destroy , model.model_name.constantize if plugin.role_destroy? # setting destroy authorization can :manage , model.model_name.constantize if plugin.role_manage? # setting manage authorization end end end end |