Fixes #3514 - csv import example file download (organizations) is empty.
This commit is contained in:
parent
e5d9fb37dd
commit
2d6d15f9be
6 changed files with 32 additions and 17 deletions
|
@ -176,7 +176,7 @@ returns
|
|||
|
||||
=end
|
||||
|
||||
def attributes_with_association_names
|
||||
def attributes_with_association_names(empty_keys: false)
|
||||
|
||||
# get relations
|
||||
attributes = attributes_with_association_ids
|
||||
|
@ -185,6 +185,9 @@ returns
|
|||
next if association_attributes_ignored.include?(assoc.name)
|
||||
|
||||
ref = send(assoc.name)
|
||||
if empty_keys
|
||||
attributes[assoc.name.to_s] = nil
|
||||
end
|
||||
next if !ref
|
||||
|
||||
if ref.respond_to?(:first)
|
||||
|
|
|
@ -246,20 +246,20 @@ returns
|
|||
records.each do |record|
|
||||
record_attributes_with_association_names = record.attributes_with_association_names
|
||||
records_attributes_with_association_names.push record_attributes_with_association_names
|
||||
record_attributes_with_association_names.each do |key, value|
|
||||
next if value.instance_of?(ActiveSupport::HashWithIndifferentAccess)
|
||||
next if value.instance_of?(Hash)
|
||||
next if csv_attributes_ignored&.include?(key.to_sym)
|
||||
next if key.end_with?('_id')
|
||||
next if key.end_with?('_ids')
|
||||
next if key == 'created_by'
|
||||
next if key == 'updated_by'
|
||||
next if key == 'created_at'
|
||||
next if key == 'updated_at'
|
||||
next if header.include?(key)
|
||||
end
|
||||
new.attributes_with_association_names(empty_keys: true).each do |key, value|
|
||||
next if value.instance_of?(ActiveSupport::HashWithIndifferentAccess)
|
||||
next if value.instance_of?(Hash)
|
||||
next if csv_attributes_ignored&.include?(key.to_sym)
|
||||
next if key.end_with?('_id')
|
||||
next if key.end_with?('_ids')
|
||||
next if key == 'created_by'
|
||||
next if key == 'updated_by'
|
||||
next if key == 'created_at'
|
||||
next if key == 'updated_at'
|
||||
next if header.include?(key)
|
||||
|
||||
header.push key
|
||||
end
|
||||
header.push key
|
||||
end
|
||||
|
||||
rows = []
|
||||
|
|
|
@ -27,7 +27,7 @@ class KnowledgeBase::Answer::Translation::Content < ApplicationModel
|
|||
add_attachments_to_attributes(attrs)
|
||||
end
|
||||
|
||||
def attributes_with_association_names
|
||||
def attributes_with_association_names(empty_keys: false)
|
||||
attrs = super
|
||||
add_attachments_to_attributes(attrs)
|
||||
end
|
||||
|
|
|
@ -44,7 +44,7 @@ class Taskbar < ApplicationModel
|
|||
false
|
||||
end
|
||||
|
||||
def attributes_with_association_names
|
||||
def attributes_with_association_names(empty_keys: false)
|
||||
add_attachments_to_attributes(super)
|
||||
end
|
||||
|
||||
|
|
|
@ -270,7 +270,7 @@ returns
|
|||
|
||||
=end
|
||||
|
||||
def attributes_with_association_names
|
||||
def attributes_with_association_names(empty_keys: false)
|
||||
attributes = super
|
||||
add_attachments_to_attributes(attributes)
|
||||
Ticket::Article.insert_urls(attributes)
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
RSpec.shared_examples 'CanCsvImport' do |unique_attributes: []|
|
||||
describe '.csv_example' do
|
||||
before do
|
||||
described_class.destroy_all
|
||||
end
|
||||
|
||||
context 'when no data avaiable' do
|
||||
it 'still returns the header for the csv example' do
|
||||
expect(described_class.csv_example).to include('id')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.csv_import' do
|
||||
let!(:params) { { string: <<~CSV, parse_params: { col_sep: ',' } } }
|
||||
#{described_class.attribute_names.join(',')}
|
||||
|
|
Loading…
Reference in a new issue