Sha256: 493d01bbdb7362854c2821619e0e3000c725c4cbaff21a23408d053c6db7c924
Contents?: true
Size: 951 Bytes
Versions: 9
Compression:
Stored size: 951 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::ProcessesFileLocally 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_file_locally(file) do |file_path| CSV.foreach(file_path, encoding: "BOM|UTF-8") do |_email, user_name| errors.add(:user_name, :invalid) unless user_name.match?(UserBaseEntity::REGEXP_NAME) end end rescue CSV::MalformedCSVError errors.add(:file, :malformed) end end end end
Version data entries
9 entries across 9 versions & 1 rubygems