Module: Authorized::ModelMethods::InstanceMethods
- Defined in:
- lib/authorized.rb
Instance Method Summary (collapse)
-
- (Object) container_permissions(container_id, container)
Method returning the workspace permissions list.
-
- (Object) has_container_permission(container_id, controller, action, container)
Method returning true if user has the workspace permission, false else.
-
- (Object) has_container_role(container_id, container, role_name)
Method returning true if the user has the workspace role passed in params, false else.
-
- (Object) has_system_permission(controller, action)
Method returning true if user has the system permission, false else.
-
- (Object) has_system_role(role_name)
Method returning true if the user has the system role passed in params, false else.
-
- (Object) system_permissions
Method returning the system permissions list.
-
- (Object) system_role
Method returning the system role.
Instance Method Details
- (Object) container_permissions(container_id, container)
Method returning the workspace permissions list
Parameters :
-
workspace_id: Integer defining the workspace id
Usage : user.workspace_permissions(2)
69 70 71 72 73 74 75 |
# File 'lib/authorized.rb', line 69 def (container_id, container) if @users_container = UsersContainer.find(:first, :conditions => {:user_id => self.id, :containerable_id => container_id, :containerable_type => container}) return @permissions = @users_container.role. else return [] end end |
- (Object) has_container_permission(container_id, controller, action, container)
Method returning true if user has the workspace permission, false else
Parameters :
-
workspace_id: Integer for workspace id
-
controller: String defining the controller defining the first part of the permission
-
action: String defining the action defining the second part of the permission
Usage : user.has_workspace_permission('workspace_id','articles','new')
99 100 101 102 |
# File 'lib/authorized.rb', line 99 def (container_id, controller, action, container) = controller+'_'+action return self.has_system_role('superadmin') || !self.(container_id,container).delete_if{ |e| e.name != }.blank? end |
- (Object) has_container_role(container_id, container, role_name)
Method returning true if the user has the workspace role passed in params, false else
Parameters :
-
workspace_id: Integer for workspace id
-
role_name: String defining the role
Usage: user.has_workspace_role('ws_admin')
50 51 52 |
# File 'lib/authorized.rb', line 50 def has_container_role(container_id, container, role_name) UsersContainer.exists?(:user_id => self.id, :containerable_id => container_id, :containerable_type => container.capitalize, :role_id => Role.find_by_name(role_name).id) || self.system_role.name == 'superadmin' end |
- (Object) has_system_permission(controller, action)
Method returning true if user has the system permission, false else
Parameters :
-
controller: String defining the controller defining the first part of the permission
-
action: String defining the action defining the second part of the permission
Usage : user.has_system_permission('workspaces','new')
85 86 87 88 |
# File 'lib/authorized.rb', line 85 def (controller, action) = controller+'_'+action return self.has_system_role('superadmin')|| !self..delete_if{ |e| e.name != }.blank? end |
- (Object) has_system_role(role_name)
Method returning true if the user has the system role passed in params, false else
Parameters :
-
role_name: String defining the role
Usage : user.has_system_role('admin')
38 39 40 |
# File 'lib/authorized.rb', line 38 def has_system_role(role_name) (self.system_role.name == 'superadmin') || (self.system_role.name == role_name) end |
- (Object) system_permissions
Method returning the system permissions list
Usage : user.system_permissions
58 59 60 |
# File 'lib/authorized.rb', line 58 def @permissions ||= self.system_role. end |
- (Object) system_role
Method returning the system role
Usage : user.system_role
27 28 29 |
# File 'lib/authorized.rb', line 27 def system_role @role ||= Role.find(self.system_role_id) end |