Sha256: 31204df86ee6a4b5c95578dc9b677e61c325b809e70e1c95859bda023038705c

Contents?: true

Size: 881 Bytes

Versions: 13

Compression:

Stored size: 881 Bytes

Contents

# frozen_string_literal: true

require "csv"

module Decidim
  module Admin
    # A form object used to upload CSV to batch participatory space private users.
    #
    class ParticipatorySpacePrivateUserCsvImportForm < Form
      include Decidim::HasUploadValidations
      include Decidim::Admin::CustomImport

      attribute :file, Decidim::Attributes::Blob
      attribute :user_name, String
      attribute :email, String

      validates :file, presence: true, file_content_type: { allow: ["text/csv"] }
      validate :validate_csv

      def validate_csv
        return if file.blank?

        process_import_file(file) do |(_email, user_name)|
          errors.add(:user_name, :invalid) if user_name.blank? || !user_name.match?(UserBaseEntity::REGEXP_NAME)
        end
      rescue CSV::MalformedCSVError
        errors.add(:file, :malformed)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

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