Merge pull request #551 from ZmagoD/zd_SCI_1189

fixes the user_name field in csv export [fixes SCI-1189]
This commit is contained in:
Zmago Devetak 2017-04-13 14:36:44 +02:00 committed by GitHub
commit 40af0df882

View file

@ -1,6 +1,20 @@
require 'zip'
require 'fileutils'
# To use ZipExport you have to define the generate_( type )_zip method!
# Example:
# def generate_(type)_zip(tmp_dir, data, options = {})
# attributes = options.fetch(:attributes) { :attributes_missing }
# file = FileUtils.touch("#{tmp_dir}/export.csv").first
# records = data
# CSV.open(file, 'wb') do |csv|
# csv << attributes
# records.find_each do |entity|
# csv << entity.values_at(*attributes.map(&:to_sym))
# end
# end
# end
class ZipExport < ActiveRecord::Base
belongs_to :user
has_attached_file :zip_file
@ -50,21 +64,18 @@ class ZipExport < ActiveRecord::Base
private
def fill_content(dir, data, type, options = {})
generate_papertrail_csv(dir, data, options) if type == :papertrail
def method_missing(m, *args, &block)
puts 'Method is missing! To use this zip_export you have to ' \
'define a method: generate_( type )_zip.'
object.public_send(m, *args, &block)
end
def generate_papertrail_csv(tmp_dir, data, options = {})
attributes = options.fetch(:attributes) { :attributes_missing }
file = FileUtils.touch("#{tmp_dir}/export.csv").first
records = PaperTrail::Version.where(data)
.order(created_at: :desc)
CSV.open(file, 'wb') do |csv|
csv << attributes
records.find_each do |entity|
csv << entity.audit_record.values_at(*attributes.map(&:to_sym))
end
end
def respond_to_missing?(method_name, include_private = false)
method_name.to_s.start_with?(' generate_') || super
end
def fill_content(dir, data, type, options = {})
eval("generate_#{type}_zip(dir, data, options)")
end
def generate_notification(user)