Class: Decidim::VerifyWoRegistration::VerifyWoRegistrationForm

Inherits:
Form
  • Object
show all
Defined in:
app/forms/decidim/verify_wo_registration/verify_wo_registration_form.rb

Overview

A form object used to wrap and validate params from the controller to the command.

Instance Method Summary collapse

Instance Method Details

#authorization_handlersObject

Returns authorization_handlers that were configured for the current component



16
17
18
19
20
21
22
# File 'app/forms/decidim/verify_wo_registration/verify_wo_registration_form.rb', line 16

def authorization_handlers
  @authorization_handlers ||= begin
    ::Decidim::VerifyWoRegistration::ApplicationHelper.workflow_manifests(component).map do |workflow_manifest|
      Decidim::AuthorizationHandler.handler_for(workflow_manifest.name, handler_params(workflow_manifest.name))
    end
  end
end

#componentObject



57
58
59
60
61
62
63
64
# File 'app/forms/decidim/verify_wo_registration/verify_wo_registration_form.rb', line 57

def component
  @component ||= begin
    c = Decidim::Component.find(component_id)
    raise ArgumentError unless c.participatory_space.organization.id == current_organization.id

    c
  end
end

#default_handler_paramsObject



40
41
42
# File 'app/forms/decidim/verify_wo_registration/verify_wo_registration_form.rb', line 40

def default_handler_params
  { user: new_verified_user }
end

#handler_params(handler_name) ⇒ Object

The authorizations from the params may be in the following format:

“‘ “document_number”=>“00000000X”, “postal_code”=>“00000”, “birthday”=>“23/06/6”} “`



30
31
32
33
34
35
36
37
38
# File 'app/forms/decidim/verify_wo_registration/verify_wo_registration_form.rb', line 30

def handler_params(handler_name)
  authorization_params = authorizations
  return default_handler_params if authorization_params.nil?

  authorization_params = authorization_params.values.find { |h| h.with_indifferent_access[:handler_name] == handler_name }
  return default_handler_params if authorization_params.nil?

  authorization_params.merge(default_handler_params)
end

#new_verified_userObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/forms/decidim/verify_wo_registration/verify_wo_registration_form.rb', line 44

def new_verified_user
  @new_verified_user ||= Decidim::User.new(
    organization: current_organization,
    admin: false,
    managed: true,
    name: Time.current.utc.to_s(:number)
  ) do |u|
    u.nickname = UserBaseEntity.nicknamize(u.name, organization: current_organization)
    u.tos_agreement = true
    u.skip_confirmation!
  end
end