Class: Decidim::Verifications::Adapter

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(manifest) ⇒ Adapter

Returns a new instance of Adapter.



73
74
75
# File 'lib/decidim/verifications/adapter.rb', line 73

def initialize(manifest)
  @manifest = manifest
end

Class Method Details

.from_collection(collection) ⇒ Object



61
62
63
# File 'lib/decidim/verifications/adapter.rb', line 61

def self.from_collection(collection)
  collection.map { |e| from_element(e) }
end

.from_element(element) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/decidim/verifications/adapter.rb', line 65

def self.from_element(element)
  manifest = Verifications.find_workflow_manifest(element)

  raise UnregisteredVerificationManifest.new(name: element) unless manifest

  new(manifest)
end

Instance Method Details

#admin_root_pathObject

Administrational entry point for the verification engine



118
119
120
121
122
# File 'lib/decidim/verifications/adapter.rb', line 118

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.



144
145
146
147
# File 'lib/decidim/verifications/adapter.rb', line 144

def authorize(authorization, options, component, resource)
  @action_authorizer = @manifest.action_authorizer_class.new(authorization, options_for_authorizer_class(options), component, resource)
  @action_authorizer.authorize
end

#has_admin_root_path?Boolean

Does this workflow manifest has an admin engine associated?

Returns a boolean value.

Returns:

  • (Boolean)


129
130
131
# File 'lib/decidim/verifications/adapter.rb', line 129

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.



105
106
107
108
109
110
111
112
113
# File 'lib/decidim/verifications/adapter.rb', line 105

def renew_path(redirect_url: nil)
  if manifest.type == "direct"
    decidim_verifications.renew_authorizations_path(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



94
95
96
97
98
99
# File 'lib/decidim/verifications/adapter.rb', line 94

def resume_authorization_path(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



82
83
84
85
86
87
88
# File 'lib/decidim/verifications/adapter.rb', line 82

def root_path(redirect_url: nil)
  if manifest.type == "direct"
    decidim_verifications.new_authorization_path(redirect_params(handler: name, redirect_url:))
  else
    main_engine.send(:root_path, redirect_params(redirect_url:))
  end
end