Class: Integral::BasePolicy
- Inherits:
-
Object
- Object
- Integral::BasePolicy
- Defined in:
- app/policies/integral/base_policy.rb
Overview
Sets base policy for all objects to inherit
Direct Known Subclasses
CategoryPolicy, ListPolicy, PagePolicy, PostPolicy, SettingsPolicy, Storage::FilePolicy, UserPolicy, VersionPolicy
Instance Attribute Summary collapse
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(user, instance) ⇒ BasePolicy
constructor
Initializes a policy instance which is used to handle authorization.
-
#manager? ⇒ Boolean
Whether or not user has manager role.
- #permitted_attribute?(attribute) ⇒ Boolean
-
#permitted_attributes ⇒ Array
Attributes the user is authorized to edit.
- #unpermitted_attribute?(attribute) ⇒ Boolean
Constructor Details
#initialize(user, instance) ⇒ BasePolicy
Initializes a policy instance which is used to handle authorization
10 11 12 13 |
# File 'app/policies/integral/base_policy.rb', line 10 def initialize(user, instance) @user = user @instance = instance end |
Instance Attribute Details
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
4 5 6 |
# File 'app/policies/integral/base_policy.rb', line 4 def instance @instance end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
4 5 6 |
# File 'app/policies/integral/base_policy.rb', line 4 def user @user end |
Instance Method Details
#manager? ⇒ Boolean
Returns whether or not user has manager role.
16 17 18 |
# File 'app/policies/integral/base_policy.rb', line 16 def manager? user.role?(role_name) || user.admin? end |
#permitted_attribute?(attribute) ⇒ Boolean
20 21 22 |
# File 'app/policies/integral/base_policy.rb', line 20 def permitted_attribute?(attribute) permitted_attributes.include?(attribute) end |
#permitted_attributes ⇒ Array
Returns attributes the user is authorized to edit.
29 30 31 |
# File 'app/policies/integral/base_policy.rb', line 29 def permitted_attributes raise NotImplementedError end |
#unpermitted_attribute?(attribute) ⇒ Boolean
24 25 26 |
# File 'app/policies/integral/base_policy.rb', line 24 def unpermitted_attribute?(attribute) !permitted_attribute?(attribute) end |