Sha256: dd07f8e0430dd88b268c115bfbd52f8876ffeffbbf210329101a11c485a23945

Contents?: true

Size: 1.37 KB

Versions: 28

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Decidim
  module Verifications
    module IdDocuments
      # A form object to be used as the base for identity document verification
      class InformationForm < AuthorizationHandler
        mimic :id_document_information

        DOCUMENT_TYPES = %w(DNI NIE passport).freeze

        attribute :document_number, String
        attribute :document_type, String

        validates :document_type,
                  inclusion: { in: DOCUMENT_TYPES },
                  presence: true

        validates :document_number,
                  format: { with: /\A[A-Z0-9]*\z/, message: I18n.t("errors.messages.uppercase_only_letters_numbers") },
                  presence: true

        def handler_name
          "id_documents"
        end

        def map_model(model)
          self.document_type = model.verification_metadata["document_type"]
          self.document_number = model.verification_metadata["document_number"]
        end

        def verification_metadata
          {
            "document_type" => document_type,
            "document_number" => document_number
          }
        end

        def document_types_for_select
          DOCUMENT_TYPES.map do |type|
            [
              I18n.t(type.downcase, scope: "decidim.verifications.id_documents"),
              type
            ]
          end
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
decidim-verifications-0.15.2 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.15.1 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.15.0 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.14.4 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.14.3 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.14.2 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.14.1 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.13.1 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.12.2 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.13.0 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.12.1 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.13.0.pre1 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.12.0 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.11.2 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.12.0.pre app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.11.1 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.11.0.pre1 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.10.1 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.10.0 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.9.3 app/forms/decidim/verifications/id_documents/information_form.rb