Class: Decidim::PermissionAction
- Inherits:
-
Object
- Object
- Decidim::PermissionAction
- Defined in:
- app/models/decidim/permission_action.rb
Overview
This class encapsulates an action, which will be used by the permissions system to check if the user is allowed to perform it.
It consists of a ‘scope` (which will typically be either `:public` or `:admin`), the name of the `:action` that is being performed and the `:subject` of the action.
Defined Under Namespace
Classes: PermissionCannotBeDisallowedError, PermissionNotSetError
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#backtrace ⇒ Object
readonly
Returns the value of attribute backtrace.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
- #allow! ⇒ Object
- #allowed? ⇒ Boolean
- #disallow! ⇒ Object
-
#initialize(action:, scope:, subject:) ⇒ PermissionAction
constructor
action - a Symbol representing the action being performed scope - a Symbol representing the scope of the action subject - a Symbol representing the subject of the action.
- #trace(class_name, state) ⇒ Object
Constructor Details
#initialize(action:, scope:, subject:) ⇒ PermissionAction
action - a Symbol representing the action being performed scope - a Symbol representing the scope of the action subject - a Symbol representing the subject of the action
14 15 16 17 18 19 20 |
# File 'app/models/decidim/permission_action.rb', line 14 def initialize(action:, scope:, subject:) @action = action @scope = scope @subject = subject @state = nil @backtrace = [] end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
22 23 24 |
# File 'app/models/decidim/permission_action.rb', line 22 def action @action end |
#backtrace ⇒ Object (readonly)
Returns the value of attribute backtrace.
22 23 24 |
# File 'app/models/decidim/permission_action.rb', line 22 def backtrace @backtrace end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
22 23 24 |
# File 'app/models/decidim/permission_action.rb', line 22 def scope @scope end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
22 23 24 |
# File 'app/models/decidim/permission_action.rb', line 22 def subject @subject end |
Instance Method Details
#allow! ⇒ Object
24 25 26 27 |
# File 'app/models/decidim/permission_action.rb', line 24 def allow! raise PermissionCannotBeDisallowedError, "Allowing a previously disallowed action is not permitted: #{inspect}" if @state == :disallowed @state = :allowed end |
#allowed? ⇒ Boolean
33 34 35 36 |
# File 'app/models/decidim/permission_action.rb', line 33 def allowed? raise PermissionNotSetError, "Permission hasn't been allowed or disallowed yet: #{inspect}" if @state.blank? @state == :allowed end |
#disallow! ⇒ Object
29 30 31 |
# File 'app/models/decidim/permission_action.rb', line 29 def disallow! @state = :disallowed end |
#trace(class_name, state) ⇒ Object
38 39 40 |
# File 'app/models/decidim/permission_action.rb', line 38 def trace(class_name, state) @backtrace << [class_name, state] end |