Sha256: 21df71c460b933c68c040227cd852d6c12385ed568035251553954751d695179

Contents?: true

Size: 1.07 KB

Versions: 13

Compression:

Stored size: 1.07 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::Admin::CustomImport

      # 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 was not valid and we could not 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_import_file(@form.file) do |(email)|
          VerifyUserGroupFromCsvJob.perform_later(email, verifier, organization) if email.present?
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-admin-0.29.1 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.28.4 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.29.0 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.28.3 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.29.0.rc4 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.29.0.rc3 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.29.0.rc2 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.29.0.rc1 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.28.2 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.28.1 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.28.0 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.28.0.rc5 app/commands/decidim/admin/process_user_group_verification_csv.rb
decidim-admin-0.28.0.rc4 app/commands/decidim/admin/process_user_group_verification_csv.rb