Class: Decidim::ViaOberta::Verifications::ViaObertaHandler
- Inherits:
-
AuthorizationHandler
- Object
- AuthorizationHandler
- Decidim::ViaOberta::Verifications::ViaObertaHandler
- Defined in:
- app/forms/decidim/via_oberta/verifications/via_oberta_handler.rb
Constant Summary collapse
- DOCUMENT_TYPE =
VALID: 1=NIF, 2=NIE, 3=Passaport, 4=Altres VIAOBERTA: 1=NIF, 2=passaport, 3=permÃs residència, 4=NIE
{ 1 => :nif, 2 => :nie, 3 => :passport, 4 => :others }.freeze
Instance Attribute Summary collapse
-
#response_code ⇒ Object
readonly
Returns the value of attribute response_code.
-
#response_error ⇒ Object
readonly
Returns the value of attribute response_error.
Instance Method Summary collapse
- #census_response ⇒ Object
-
#document_id ⇒ Object
use from previous authorization metadata.
-
#document_type ⇒ Object
use from previous authorization metadata or use the one from the form as a fallback not memoized because @document_id would be defined if sent via form.
- #document_type_from_metadata ⇒ Object
- #document_type_string ⇒ Object
- #document_types ⇒ Object
- #existing_via_oberta_identity ⇒ Object
-
#form_attributes ⇒ Object
no public attributes.
- #to_partial_path ⇒ Object
- #unique_id ⇒ Object
Instance Attribute Details
#response_code ⇒ Object (readonly)
Returns the value of attribute response_code.
24 25 26 |
# File 'app/forms/decidim/via_oberta/verifications/via_oberta_handler.rb', line 24 def response_code @response_code end |
#response_error ⇒ Object (readonly)
Returns the value of attribute response_error.
24 25 26 |
# File 'app/forms/decidim/via_oberta/verifications/via_oberta_handler.rb', line 24 def response_error @response_error end |
Instance Method Details
#census_response ⇒ Object
61 62 63 |
# File 'app/forms/decidim/via_oberta/verifications/via_oberta_handler.rb', line 61 def census_response @census_response ||= ViaOberta::Api::Request.new(document_id: document_id, document_type: document_type, organization: organization).response end |
#document_id ⇒ Object
use from previous authorization metadata. We don't allow user input here to prevent spoofing not memoized because @document_id would be defined if sent via form
37 38 39 |
# File 'app/forms/decidim/via_oberta/verifications/via_oberta_handler.rb', line 37 def document_id &.&.dig("uid") || impersonated_document_id end |
#document_type ⇒ Object
use from previous authorization metadata or use the one from the form as a fallback not memoized because @document_id would be defined if sent via form
43 44 45 |
# File 'app/forms/decidim/via_oberta/verifications/via_oberta_handler.rb', line 43 def document_type || DOCUMENT_TYPE[attributes[:document_type]] end |
#document_type_from_metadata ⇒ Object
47 48 49 |
# File 'app/forms/decidim/via_oberta/verifications/via_oberta_handler.rb', line 47 def @document_type_from_metadata ||= DOCUMENT_TYPE[&.&.dig("extra", "identifier_type").to_i] end |
#document_type_string ⇒ Object
55 56 57 58 59 |
# File 'app/forms/decidim/via_oberta/verifications/via_oberta_handler.rb', line 55 def document_type_string return "" unless document_type I18n.t("decidim.via_oberta.verifications.document_type.#{document_type}", default: document_type.to_s) end |
#document_types ⇒ Object
51 52 53 |
# File 'app/forms/decidim/via_oberta/verifications/via_oberta_handler.rb', line 51 def document_types @document_types ||= DOCUMENT_TYPE.map { |k, v| [I18n.t("decidim.via_oberta.verifications.document_type.#{v}", default: v.to_s), k] } end |
#existing_via_oberta_identity ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/forms/decidim/via_oberta/verifications/via_oberta_handler.rb', line 65 def existing_via_oberta_identity return unless tos_agreement return errors.add(:base, I18n.t("decidim.verifications.trusted_ids.errors.invalid_id")) if document_id.blank? return errors.add(:base, I18n.t("decidim.verifications.trusted_ids.errors.invalid_type")) if document_type.blank? return if census_response.found? errors.add(:base, I18n.t("decidim.verifications.trusted_ids.errors.invalid_census")) @response_error = census_response.error @response_code = census_response.code end |
#form_attributes ⇒ Object
no public attributes
79 80 81 |
# File 'app/forms/decidim/via_oberta/verifications/via_oberta_handler.rb', line 79 def form_attributes attributes.except(:id, :user, :document_id, :document_type).keys end |
#to_partial_path ⇒ Object
83 84 85 |
# File 'app/forms/decidim/via_oberta/verifications/via_oberta_handler.rb', line 83 def to_partial_path "decidim/via_oberta/verifications/form" end |
#unique_id ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'app/forms/decidim/via_oberta/verifications/via_oberta_handler.rb', line 26 def unique_id return unless organization return unless census_response.success? Digest::SHA256.hexdigest( "#{document_id}-#{user&.decidim_organization_id}-#{Rails.application.secret_key_base}" ) end |