Sha256: f187a0b3fe9971099e8061ebc12bfb87e6778124158cb59209c012342639286c

Contents?: true

Size: 1.83 KB

Versions: 14

Compression:

Stored size: 1.83 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

        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

        private

        def document_types
          Decidim::Verifications.document_types
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
decidim-verifications-0.29.1 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.28.4 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.27.9 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.29.0 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.28.3 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.27.8 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.29.0.rc4 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.29.0.rc3 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.29.0.rc2 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.29.0.rc1 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.28.2 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.27.7 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.28.1 app/forms/decidim/verifications/id_documents/information_form.rb
decidim-verifications-0.27.6 app/forms/decidim/verifications/id_documents/information_form.rb