Sha256: dbc1e5e41d08fbfcce1ab6432fd0fb5ad2fd254dc8ef3137c8bfca83358b6e37

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module Decidim
  module ActionDelegator
    module Admin
      class InviteParticipantsJob < ApplicationJob
        queue_as :invite_participants

        def perform(current_setting, organization)
          @current_setting = current_setting
          @organization = organization

          users_list_to_invite.find_each do |participant|
            form = InvitationParticipantForm.new(
              name: participant.email.split("@").first&.gsub(/\W/, ""),
              email: participant.email.downcase,
              organization: organization,
              admin: false
            )

            Decidim::InviteUser.call(form)
          end
        end

        private

        def users_list_to_invite
          @users_list_to_invite ||= @current_setting.participants.where(decidim_user: nil)
                                                    .where.not(email: @organization.users.select(:email))
                                                    .where.not("MD5(CONCAT(phone,'-',?,'-',?)) IN (?)",
                                                               @organization.id,
                                                               Digest::MD5.hexdigest(Rails.application.secret_key_base),
                                                               Authorization.select(:unique_id)
                                                                            .where.not(unique_id: nil))
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
decidim-action_delegator-0.8.1 app/jobs/decidim/action_delegator/admin/invite_participants_job.rb
decidim-action_delegator-0.7.2 app/jobs/decidim/action_delegator/admin/invite_participants_job.rb
decidim-action_delegator-0.7.1 app/jobs/decidim/action_delegator/admin/invite_participants_job.rb
decidim-action_delegator-0.7.0 app/jobs/decidim/action_delegator/admin/invite_participants_job.rb