-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2384 from samvera/i286-add-per-tenant-bulkrax-fie…
…ld-mapping-editor Add per-tenant Bulkrax field mappings
- Loading branch information
Showing
9 changed files
with
161 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,31 @@ | ||
<% if value[:type] == 'array' %> | ||
<%# FIXME: | ||
I think current_account here should be @account. @account is present both within the tenant | ||
as well as in the proprietor views, while current_account is only present within a tenant. | ||
Changing it to @account causes a spec in spec/features/accounts_spec.rb to fail, I think due | ||
to the form sending inputs that should be treated as arrays as strings. | ||
@see AccountSettings#validate_email_format | ||
%> | ||
<% current_account.send(key).each do |sub_value| %> | ||
<%= f.input key, value: sub_value %> | ||
<% end %> | ||
<% elsif value[:type] == 'hash' %> | ||
<% elsif value[:type] == 'json_editor' %> | ||
<%= f.input key, as: :text, required: false, input_html: { value: @account.send(key) }, label: key.to_s.titleize %> | ||
<script> | ||
document.addEventListener('turbolinks:load', () => { | ||
const input_textarea = document.getElementById('<%= "account_#{key}" %>') | ||
if (input_textarea) { | ||
CodeMirror.fromTextArea(input_textarea, { | ||
mode: 'application/json', | ||
autofocus: true, | ||
lineNumbers: true, | ||
theme: 'neat', | ||
autoRefresh: true | ||
}); | ||
}; | ||
}); | ||
</script> | ||
<% else %> | ||
<%= f.input key, as: value[:type] %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module PerTenantFieldMappings | ||
# OVERRIDE: [Bulkrax v8.2.0] Use tenant-specific field mappings if present | ||
def field_mappings | ||
if Site.account.present? && Site.account.bulkrax_field_mappings.present? | ||
JSON.parse(Site.account.bulkrax_field_mappings).with_indifferent_access | ||
else | ||
super | ||
end | ||
end | ||
end | ||
|
||
Bulkrax.singleton_class.send(:prepend, PerTenantFieldMappings) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe PerTenantFieldMappings, type: :decorator do | ||
before do | ||
allow(Site).to receive(:account).and_return(account) | ||
end | ||
|
||
context 'when the current Account does not have any tenant-specific field mappings' do | ||
let(:account) { build(:account) } | ||
|
||
it "returns Bulkrax's default field mappings" do | ||
default_bulkrax_mapping_keys = ['Bulkrax::OaiDcParser', 'Bulkrax::OaiQualifiedDcParser', 'Bulkrax::CsvParser', 'Bulkrax::BagitParser', 'Bulkrax::XmlParser'] | ||
|
||
expect(Site.account.settings['bulkrax_field_mappings']).to be_nil | ||
expect(Bulkrax.field_mappings).to be_a(Hash) | ||
expect(Bulkrax.field_mappings.keys.sort).to eq(default_bulkrax_mapping_keys.sort) | ||
end | ||
end | ||
|
||
context 'when the current Account has tenant-specific field mappings' do | ||
let(:account) { build(:account, settings: { bulkrax_field_mappings: field_mapping_json }) } | ||
let(:field_mapping_json) do | ||
{ | ||
'Bulkrax::CsvParser' => { | ||
'fake_field' => { from: %w[fake_column], split: /\s*[|]\s*/ } | ||
} | ||
}.to_json | ||
end | ||
|
||
it "returns the tenant's custom field mappings" do | ||
expect(Bulkrax.field_mappings).to eq(JSON.parse(Site.account.bulkrax_field_mappings)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters