Sha256: fcfe4574632a4c04302b6c1e7b674330f3fe617f1cdfb3ad1803b30fb7f4173d

Contents?: true

Size: 1.16 KB

Versions: 12

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require "csv"

module Decidim
  module Admin
    # A command with all the business logic when processing the CSV to verify
    # user groups.
    class ProcessUserGroupVerificationCsv < Decidim::Command
      include Decidim::ProcessesFileLocally

      # Public: Initializes the command.
      #
      # form - the form object containing the uploaded file
      def initialize(form)
        @form = form
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid.
      # - :invalid if the form wasn't valid and we couldn't proceed.
      #
      # Returns nothing.
      def call
        return broadcast(:invalid) unless @form.valid?

        process_csv
        broadcast(:ok)
      end

      private

      def process_csv
        verifier = @form.current_user
        organization = @form.current_organization

        process_file_locally(@form.file) do |file_path|
          CSV.foreach(file_path) do |row|
            email = row[0]
            VerifyUserGroupFromCsvJob.perform_later(email, verifier, organization) if email.present?
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-admin-0.27.9 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.27.8 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.27.7 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.27.6 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.27.5 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.27.4 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.27.3 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.27.2 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.27.1 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.27.0 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.27.0.rc2 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.27.0.rc1 app/commands/decidim/admin/process_user_group_verification_csv.rb