Sha256: 4bfe75c63a67647562cf41831ffa65613c6dbd4a44da46cb537013c9bca6e022
Contents?: true
Size: 1.29 KB
Versions: 5
Compression:
Stored size: 1.29 KB
Contents
# frozen_string_literal: true module Decidim module Verifications # A command to confirm a previous partial authorization. class ConfirmUserAuthorization < Rectify::Command # Public: Initializes the command. # # authorization - An Authorization to be confirmed. # form - A form object with the verification data to confirm it. def initialize(authorization, form) @authorization = authorization @form = form end # Executes the command. Broadcasts these events: # # - :ok when everything is valid. # - :invalid if the handler wasn't valid and we couldn't proceed. # # Returns nothing. def call return broadcast(:already_confirmed) if authorization.granted? return broadcast(:invalid) unless form.valid? if confirmation_successful? authorization.grant! broadcast(:ok) else broadcast(:invalid) end rescue StandardError => e broadcast(:invalid, e.message) end protected def confirmation_successful? form.verification_metadata.all? do |key, value| authorization.verification_metadata[key] == value end end private attr_reader :authorization, :form end end end
Version data entries
5 entries across 5 versions & 1 rubygems