Sha256: 4a785cda4dd96dc5ab739a17f0c5b9c32b240c297a4e50435dc6609509087af9

Contents?: true

Size: 1.78 KB

Versions: 57

Compression:

Stored size: 1.78 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
        attribute :verification_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

        validates :verification_type,
                  presence: true,
                  inclusion: { in: %w(offline online) }

        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"]
          self.verification_type = model.verification_metadata["verification_type"].presence || "online"
        end

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

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

        def uses_online_method?
          verification_type == "online"
        end
      end
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
decidim-verifications-0.26.10 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.26.9 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.28.0 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.27.5 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.28.0.rc5 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.28.0.rc4 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.26.8 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.27.4 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.27.3 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.26.7 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.26.5 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.27.2 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.27.1 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.26.4 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.27.0 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.26.3 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.27.0.rc2 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.27.0.rc1 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.26.2 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.26.1 app/forms/decidim/verifications/id_documents/information_form.rb