Class: Decidim::Verifications::Adapter

Inherits:
Object
  • Object
show all
Defined in:
decidim-verifications/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.


39
40
41
# File 'decidim-verifications/lib/decidim/verifications/adapter.rb', line 39

def initialize(manifest)
  @manifest = manifest
end

Class Method Details

.from_collection(collection) ⇒ Object


27
28
29
# File 'decidim-verifications/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 'decidim-verifications/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_pathObject

Administrational entry point for the verification engine

Raises:

  • (InvalidDirectVerificationRoute)

81
82
83
84
85
# File 'decidim-verifications/lib/decidim/verifications/adapter.rb', line 81

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.


98
99
100
101
# File 'decidim-verifications/lib/decidim/verifications/adapter.rb', line 98

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

#renew_path(redirect_url: nil) ⇒ Object

In the case of renewable authorizations, route to renew an authorization process.


70
71
72
73
74
75
76
# File 'decidim-verifications/lib/decidim/verifications/adapter.rb', line 70

def renew_path(redirect_url: nil)
  if manifest.type == "direct"
    decidim_verifications.renew_authorizations_path(redirect_params(handler: name, redirect_url: redirect_url))
  else
    main_engine.send(:renew_authorization_path, redirect_params(redirect_url: 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

Raises:

  • (InvalidDirectVerificationRoute)

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

def resume_authorization_path(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 'decidim-verifications/lib/decidim/verifications/adapter.rb', line 48

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