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.
-
#has_admin_root_path? ⇒ Boolean
Does this workflow manifest has an admin engine associated?.
-
#initialize(manifest) ⇒ Adapter
constructor
A new instance of Adapter.
-
#renew_path(redirect_url: nil) ⇒ Object
In the case of renewable authorizations, route to renew an authorization process.
-
#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.
62 63 64 |
# File 'lib/decidim/verifications/adapter.rb', line 62 def initialize(manifest) @manifest = manifest end |
Class Method Details
.from_collection(collection) ⇒ Object
50 51 52 |
# File 'lib/decidim/verifications/adapter.rb', line 50 def self.from_collection(collection) collection.map { |e| from_element(e) } end |
.from_element(element) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/decidim/verifications/adapter.rb', line 54 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
107 108 109 110 111 |
# File 'lib/decidim/verifications/adapter.rb', line 107 def admin_root_path raise InvalidVerificationRoute.new(route: "admin_route_path") if manifest.type == "direct" admin_engine.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.
133 134 135 136 |
# File 'lib/decidim/verifications/adapter.rb', line 133 def (, , component, resource) @action_authorizer = @manifest..new(, (), component, resource) @action_authorizer. end |
#has_admin_root_path? ⇒ Boolean
Does this workflow manifest has an admin engine associated?
Returns a boolean value.
118 119 120 |
# File 'lib/decidim/verifications/adapter.rb', line 118 def has_admin_root_path? respond_to?("decidim_admin_#{name}") end |
#renew_path(redirect_url: nil) ⇒ Object
In the case of renewable authorizations, route to renew an authorization process.
94 95 96 97 98 99 100 101 102 |
# File 'lib/decidim/verifications/adapter.rb', line 94 def renew_path(redirect_url: nil) if manifest.type == "direct" decidim_verifications.(redirect_params(handler: name, redirect_url:)) else raise MissingVerificationRoute.new(handler: name, route: "renew_authorization_path", action: "renew") unless main_engine.respond_to?(:renew_authorization_path) main_engine.send(:renew_authorization_path, redirect_params(redirect_url:)) end end |
#resume_authorization_path(redirect_url: nil) ⇒ Object
In the case of deferred authorizations, route to resume an authorization process. Otherwise it rises
83 84 85 86 87 88 |
# File 'lib/decidim/verifications/adapter.rb', line 83 def (redirect_url: nil) raise InvalidVerificationRoute.new(route: "edit_authorization_path") if manifest.type == "direct" raise MissingVerificationRoute.new(handler: name, route: "edit_authorization_path", action: "resume") unless main_engine.respond_to?(:edit_authorization_path) main_engine.send(:edit_authorization_path, redirect_params(redirect_url:)) end |
#root_path(redirect_url: nil) ⇒ Object
Main entry point for the verification engine
71 72 73 74 75 76 77 |
# File 'lib/decidim/verifications/adapter.rb', line 71 def root_path(redirect_url: nil) if manifest.type == "direct" decidim_verifications.(redirect_params(handler: name, redirect_url:)) else main_engine.send(:root_path, redirect_params(redirect_url:)) end end |