Class: Decidim::Verifications::Adapter
- Inherits:
-
Object
- Object
- Decidim::Verifications::Adapter
- Defined in:
- lib/decidim/verifications/adapter.rb
Overview
Provides a unified interface for direct and deferred authorizations, so they can be used transparently
Class Method Summary collapse
Instance Method Summary collapse
-
#admin_root_path ⇒ Object
Administrational entry point for the verification engine.
-
#authorize(authorization, options, component, resource) ⇒ Object
Authorize user to perform an action using the authorization handler action authorizer.
-
#initialize(manifest) ⇒ Adapter
constructor
A new instance of Adapter.
-
#resume_authorization_path(redirect_url: nil) ⇒ Object
In the case of deferred authorizations, route to resume an authorization process.
-
#root_path(redirect_url: nil) ⇒ Object
Main entry point for the verification engine.
Constructor Details
#initialize(manifest) ⇒ Adapter
Returns a new instance of Adapter.
39 40 41 |
# File 'lib/decidim/verifications/adapter.rb', line 39 def initialize(manifest) @manifest = manifest end |
Class Method Details
.from_collection(collection) ⇒ Object
27 28 29 |
# File 'lib/decidim/verifications/adapter.rb', line 27 def self.from_collection(collection) collection.map { |e| from_element(e) } end |
.from_element(element) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/decidim/verifications/adapter.rb', line 31 def self.from_element(element) manifest = Verifications.find_workflow_manifest(element) raise UnregisteredVerificationManifest unless manifest new(manifest) end |
Instance Method Details
#admin_root_path ⇒ Object
Administrational entry point for the verification engine
69 70 71 72 73 |
# File 'lib/decidim/verifications/adapter.rb', line 69 def admin_root_path raise InvalidDirectVerificationRoute.new(route: "admin_route_path") if manifest.type == "direct" public_send(:"decidim_admin_#{name}").send(:root_path, redirect_params) end |
#authorize(authorization, options, component, resource) ⇒ Object
Authorize user to perform an action using the authorization handler action authorizer. Saves the action_authorizer object with its context for subsequent methods calls.
authorization - The existing authorization record to be evaluated. Can be nil. options - A hash with options related only to the current authorization process. component - The component where the authorization is taking place. resource - The resource where the authorization is taking place. Can be nil.
Returns the result of authorization handler check. Check Decidim::Verifications::DefaultActionAuthorizer class docs.
86 87 88 89 |
# File 'lib/decidim/verifications/adapter.rb', line 86 def (, , component, resource) @action_authorizer = @manifest..new(, , component, resource) @action_authorizer. end |
#resume_authorization_path(redirect_url: nil) ⇒ Object
In the case of deferred authorizations, route to resume an authorization process. Otherwise it rises
60 61 62 63 64 |
# File 'lib/decidim/verifications/adapter.rb', line 60 def (redirect_url: nil) raise InvalidDirectVerificationRoute.new(route: "edit_authorization_path") if manifest.type == "direct" main_engine.send(:edit_authorization_path, redirect_params(redirect_url: redirect_url)) end |
#root_path(redirect_url: nil) ⇒ Object
Main entry point for the verification engine
48 49 50 51 52 53 54 |
# File 'lib/decidim/verifications/adapter.rb', line 48 def root_path(redirect_url: nil) if manifest.type == "direct" decidim_verifications.(redirect_params(handler: name, redirect_url: redirect_url)) else main_engine.send(:root_path, redirect_params(redirect_url: redirect_url)) end end |