Sha256: 03f8346de5ebefa938da7beaa50638e02edbd968bced393b6830fee9ee928cf4

Contents?: true

Size: 2 KB

Versions: 6

Compression:

Stored size: 2 KB

Contents

# frozen_string_literal: true

module Decidim
  module AccessRequests
    module Verification
      module Admin
        # A command to confirm a previous partial authorization.
        # This is just a wrapper class to call the ConfirmUserAuthorization
        # command because we add the email notifications here.
        class ConfirmUserAccessRequest < 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
            parent = self

            Decidim::Verifications::ConfirmUserAuthorization.call(authorization, form) do
              on(:ok) do
                send_notification
                parent.send(:broadcast, :ok)
              end

              on(:invalid) do
                parent.send(:broadcast, :invalid)
              end

              on(:already_confirmed) do
                parent.send(:broadcast, :invalid)
              end
            end
          end

          private

          attr_reader :authorization, :form

          def send_notification
            Decidim::EventsManager.publish(
              event: "decidim.events.access_requests.confirmed",
              event_class: AccessRequestConfirmedEvent,
              resource: authorization,
              affected_users: [authorization.user],
              extra: {
                user_name: authorization.user.name,
                user_nickname: authorization.user.nickname,
                handler_name: authorization.name
              }
            )
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-access_requests-0.19.1 app/commands/decidim/access_requests/verification/admin/confirm_user_access_request.rb
decidim-access_requests-0.19.0 app/commands/decidim/access_requests/verification/admin/confirm_user_access_request.rb
decidim-access_requests-0.18.0 app/commands/decidim/access_requests/verification/admin/confirm_user_access_request.rb
decidim-access_requests-0.17.0 app/commands/decidim/access_requests/verification/admin/confirm_user_access_request.rb
decidim-access_requests-0.16.1 app/commands/decidim/access_requests/verification/admin/confirm_user_access_request.rb
decidim-access_requests-0.16.0 app/commands/decidim/access_requests/verification/admin/confirm_user_access_request.rb