Sha256: a8f7391c75875d76d95fd7689e028ce078ea2673a3f88b7549dd8c2977307560

Contents?: true

Size: 1.08 KB

Versions: 6

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Decidim
  module DirectVerifications
    class RevokeUser
      def initialize(email, organization, instrumenter, authorization_handler)
        @email = email
        @organization = organization
        @instrumenter = instrumenter
        @authorization_handler = authorization_handler
      end

      def call
        unless user
          instrumenter.add_error :revoked, email
          return
        end

        return unless valid_authorization?

        Verification::DestroyUserAuthorization.call(authorization) do
          on(:ok) do
            instrumenter.add_processed :revoked, email
          end
        end
      end

      private

      attr_reader :email, :organization, :instrumenter, :authorization_handler

      def user
        @user ||= User.find_by(email: email, decidim_organization_id: organization.id)
      end

      def authorization
        @authorization ||= Authorization.find_by(user: user, name: authorization_handler)
      end

      def valid_authorization?
        authorization&.granted?
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-direct_verifications-1.2.1 lib/decidim/direct_verifications/revoke_user.rb
decidim-direct_verifications-1.2 lib/decidim/direct_verifications/revoke_user.rb
decidim-direct_verifications-1.0.2 lib/decidim/direct_verifications/revoke_user.rb
decidim-direct_verifications-1.0.1 lib/decidim/direct_verifications/revoke_user.rb
decidim-direct_verifications-1.1 lib/decidim/direct_verifications/revoke_user.rb
decidim-direct_verifications-1.0 lib/decidim/direct_verifications/revoke_user.rb