Class: Decidim::ActionAuthorizer::AuthorizationStatusCollection
- Inherits:
-
Object
- Object
- Decidim::ActionAuthorizer::AuthorizationStatusCollection
- Defined in:
- app/services/decidim/action_authorizer.rb
Instance Attribute Summary collapse
-
#statuses ⇒ Object
readonly
Returns the value of attribute statuses.
Instance Method Summary collapse
- #codes ⇒ Object
- #global_code ⇒ Object
-
#initialize(authorization_handlers, user, component, resource) ⇒ AuthorizationStatusCollection
constructor
A new instance of AuthorizationStatusCollection.
- #ok? ⇒ Boolean
- #status_for(handler_name) ⇒ Object
Constructor Details
#initialize(authorization_handlers, user, component, resource) ⇒ AuthorizationStatusCollection
Returns a new instance of AuthorizationStatusCollection.
96 97 98 99 100 101 102 103 104 |
# File 'app/services/decidim/action_authorizer.rb', line 96 def initialize(, user, component, resource) @authorization_handlers = @statuses = &.map do |name, opts| handler = Verifications::Adapter.from_element(name) = user ? Verifications::Authorizations.new(organization: user.organization, user:, name:).first : nil status_code, data = handler.(, opts["options"], component, resource) AuthorizationStatus.new(status_code, handler, data) end end |
Instance Attribute Details
#statuses ⇒ Object (readonly)
Returns the value of attribute statuses.
94 95 96 |
# File 'app/services/decidim/action_authorizer.rb', line 94 def statuses @statuses end |
Instance Method Details
#codes ⇒ Object
126 127 128 |
# File 'app/services/decidim/action_authorizer.rb', line 126 def codes @codes ||= statuses.map(&:code) end |
#global_code ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'app/services/decidim/action_authorizer.rb', line 112 def global_code return :ok if ok? [:unauthorized, :pending].each do |code| return code if statuses.any? { |status| status.code == code } end false end |
#ok? ⇒ Boolean
106 107 108 109 110 |
# File 'app/services/decidim/action_authorizer.rb', line 106 def ok? return true if statuses.blank? statuses.all?(&:ok?) end |
#status_for(handler_name) ⇒ Object
122 123 124 |
# File 'app/services/decidim/action_authorizer.rb', line 122 def status_for(handler_name) statuses.find { |status| status.handler_name == handler_name } end |