Sha256: fb3bb3c60e5ccf6d8dc88175ccf41e3515040159c797875cfe3d805ce78c9094

Contents?: true

Size: 1.18 KB

Versions: 19

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

require "csv"

module Decidim
  module Admin
    class ProcessParticipatorySpacePrivateUserImportCsv < Rectify::Command
      # Public: Initializes the command.
      #
      # form - the form object containing the uploaded file
      # current_user - the user performing the action
      # private_users_to - The private_users_to that will hold the user role
      def initialize(form, current_user, private_users_to)
        @form = form
        @current_user = current_user
        @private_users_to = private_users_to
      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
        CSV.foreach(@form.file.path, encoding: "BOM|UTF-8") do |email, user_name|
          ImportParticipatorySpacePrivateUserCsvJob.perform_later(email, user_name, @private_users_to, @current_user) if email.present? && user_name.present?
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
decidim-admin-0.26.10 app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb
decidim-admin-0.26.9 app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb
decidim-admin-0.26.8 app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb
decidim-admin-0.26.7 app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb
decidim-admin-0.26.5 app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb
decidim-admin-0.26.4 app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb
decidim-admin-0.26.3 app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb
decidim-admin-0.26.2 app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb
decidim-admin-0.26.1 app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb
decidim-admin-0.26.0 app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb
decidim-admin-0.26.0.rc2 app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb
decidim-admin-0.26.0.rc1 app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb
decidim-admin-0.25.2 app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb
decidim-admin-0.25.1 app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb
decidim-admin-0.25.0 app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb
decidim-admin-0.25.0.rc4 app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb
decidim-admin-0.25.0.rc3 app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb
decidim-admin-0.25.0.rc2 app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb
decidim-admin-0.25.0.rc1 app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb