Class: Spree::RoleConfiguration
- Inherits:
-
Object
- Object
- Spree::RoleConfiguration
- Defined in:
- lib/spree/core/role_configuration.rb
Overview
A class responsible for associating Role with a list of permission sets.
Defined Under Namespace
Classes: Role
Instance Attribute Summary collapse
-
#roles ⇒ Object
Returns the value of attribute roles.
Class Method Summary collapse
-
.configure {|Spree::Config.roles| ... } ⇒ Object
Yields the instance of the singleton, used for configuration.
- .instance ⇒ Object
Instance Method Summary collapse
-
#activate_permissions!(ability, user) ⇒ Object
Given a CanCan::Ability, and a user, determine what permissions sets can be activated on the ability, then activate them.
-
#assign_permissions(role_name, permission_sets) ⇒ Object
Assign permission sets for a Role that has the name of role_name.
Instance Attribute Details
#roles ⇒ Object
Returns the value of attribute roles.
30 31 32 |
# File 'lib/spree/core/role_configuration.rb', line 30 def roles @roles end |
Class Method Details
.configure {|Spree::Config.roles| ... } ⇒ Object
Yields the instance of the singleton, used for configuration
40 41 42 43 |
# File 'lib/spree/core/role_configuration.rb', line 40 def configure Spree::Deprecation.warn "Spree::RoleConfiguration.configure is deprecated. Call Spree::Config.roles.assign_permissions instead" yield(Spree::Config.roles) end |
.instance ⇒ Object
33 34 35 36 |
# File 'lib/spree/core/role_configuration.rb', line 33 def instance Spree::Deprecation.warn "Spree::RoleConfiguration.instance is DEPRECATED use Spree::Config.roles instead" Spree::Config.roles end |
Instance Method Details
#activate_permissions!(ability, user) ⇒ Object
Given a CanCan::Ability, and a user, determine what permissions sets can be activated on the ability, then activate them.
This performs can/cannot declarations on the ability, and can modify its internal permissions.
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/spree/core/role_configuration.rb', line 54 def (ability, user) spree_roles = ['default'] | user.spree_roles.map(&:name) = Set.new spree_roles.each do |role_name| |= roles[role_name]. end .each do || .new(ability).activate! end end |
#assign_permissions(role_name, permission_sets) ⇒ Object
Assign permission sets for a Spree::Role that has the name of role_name
79 80 81 82 83 84 |
# File 'lib/spree/core/role_configuration.rb', line 79 def (role_name, ) name = role_name.to_s roles[name]..concat roles[name] end |