class Decidim::Verifications::DefaultActionAuthorizer
Attributes
component[R]
options[R]
resource[R]
Public Class Methods
new(authorization, options, component, resource)
click to toggle source
Initializes the DefaultActionAuthorizer
class.
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. resouce - The resource where the authorization is taking place. Can be nil.
# File lib/decidim/verifications/default_action_authorizer.rb, line 14 def initialize(authorization, options, component, resource) @authorization = authorization @options = options.deep_dup || {} # options hash is cloned to allow changes applied to it without risks @component = resource.try(:component) || component @resource = resource end
Public Instance Methods
redirect_params()
click to toggle source
Allow to add params to redirect URLs, to modify forms behaviour based on the authorization process options.
Returns a hash with keys added to redirect URLs.
# File lib/decidim/verifications/default_action_authorizer.rb, line 64 def redirect_params {} end
Protected Instance Methods
missing_fields()
click to toggle source
# File lib/decidim/verifications/default_action_authorizer.rb, line 80 def missing_fields @missing_fields ||= valid_options_keys.each_with_object([]) do |field, missing| missing << field if authorization.metadata[field].blank? missing end end
unmatched_fields()
click to toggle source
# File lib/decidim/verifications/default_action_authorizer.rb, line 72 def unmatched_fields @unmatched_fields ||= (valued_options_keys & authorization.metadata.to_h.keys).each_with_object({}) do |field, unmatched| required_value = options[field].respond_to?(:value) ? options[field].value : options[field] unmatched[field] = required_value if authorization.metadata[field] != required_value unmatched end end
valid_options_keys()
click to toggle source
# File lib/decidim/verifications/default_action_authorizer.rb, line 87 def valid_options_keys @valid_options_keys ||= options.map do |key, value| key if value.present? || value.try(:required_for_authorization?) end.compact end
valued_options_keys()
click to toggle source
# File lib/decidim/verifications/default_action_authorizer.rb, line 93 def valued_options_keys @valued_options_keys ||= options.map do |key, value| key if value.respond_to?(:value) ? value.value.present? : value.present? end.compact end