Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Disable multiple identifiers for agents #730

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/agents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ def agent_params
v
end
end
p[:identifiers] = p[:identifiers].reject{ |key, value| value["notation"].empty? }
identifiers_schemaAgency = params[:agentType].eql?('person') ? 'ORCID' : 'ROR'
p[:identifiers]&.each_value do |identifier|
identifier[:schemaAgency] = identifiers_schemaAgency
Expand Down
34 changes: 11 additions & 23 deletions app/views/agents/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
= hidden_field_tag :deletable, deletable if deletable
= hidden_field_tag agent_field_name(:id, name_prefix), agent.id if agent.id

- if is_organization?(agent) && params[:parent_id]
syphax-bouazzouni marked this conversation as resolved.
Show resolved Hide resolved
- if params[:show_affiliations].eql?('false')
= hidden_field_tag agent_field_name(:agentType, name_prefix), agent.agentType
- else
%tr
Expand Down Expand Up @@ -55,31 +55,19 @@
%tr
%th
= t("agents.form.identifiers")
- identifier = agent&.identifiers&.first
%td.top
%div.agents-identifiers{'data-form-options-display-target':"option1", class: is_organization?(agent) && 'd-none'}
= render NestedFormInputsComponent.new do |c|
- c.template do
= agent_identifier_input('NEW_RECORD', name_prefix)

- c.empty_state do
= hidden_field_tag agent_field_name('', name_prefix+"[#{Array(agent.identifiers).size}]")

- Array(agent.identifiers).each_with_index do |identifier, i|
- c.row do
= agent_identifier_input(i.to_s.upcase, name_prefix, identifier.notation)

%div.agents-identifiers{'data-form-options-display-target':"option2", class: !is_organization?(agent) && 'd-none'}
= render NestedFormInputsComponent.new do |c|
- c.template do
= agent_identifier_input('NEW_RECORD', name_prefix, is_organization: false)

- c.empty_state do
= hidden_field_tag agent_field_name('', name_prefix+"[#{Array(agent.identifiers).size}]")

- Array(agent.identifiers).each_with_index do |identifier, i|
- c.row do
= agent_identifier_input(i.to_s.upcase, name_prefix, identifier.notation, is_organization: false)
- if identifier&.schemaAgency&.eql?('ROR')
= agent_identifier_input('0', name_prefix, identifier.notation)
- else
= agent_identifier_input('0', name_prefix)

%div.agents-identifiers{'data-form-options-display-target':"option1", class: is_organization?(agent) && 'd-none'}
- if identifier&.schemaAgency&.eql?('ORCID')
= agent_identifier_input('1', name_prefix, identifier.notation, is_organization: false)
- else
= agent_identifier_input('1', name_prefix, is_organization: false)

- if show_affiliations
%tr{'data-form-options-display-target':"option1", class: is_organization?(agent) && 'd-none'}
Expand Down
16 changes: 10 additions & 6 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def tom_select(selector, values, open_to_add: false)
element = find(ts_wrapper_selector)
element.click


return unless page.has_selector?("#{ts_wrapper_selector} > .ts-dropdown")

if multiple
Expand Down Expand Up @@ -152,10 +151,10 @@ def agent_search(name)
end

def agent_fill(agent, parent_id: nil, is_affiliation: false)
id = agent.id ? "/#{agent.id}": ''
id = agent.id ? "/#{agent.id}" : ''
form = all("form[action=\"/agents#{id}\"]").first
within form do
choose "", option: agent.agentType, allow_label_click: true unless is_affiliation
within form do
choose "", option: agent.agentType, allow_label_click: true unless is_affiliation
fill_in 'name', with: agent.name

if agent.agentType.eql?('organization')
Expand All @@ -168,8 +167,13 @@ def agent_fill(agent, parent_id: nil, is_affiliation: false)
fill_in 'email', with: agent.email
end

list_inputs ".agents-identifiers",
"[identifiers]", agent.identifiers
identifier = agent.identifiers.first

if agent.agentType.eql?('organization')
fill_in "_identifiers_0_notation", with: identifier['notation']
else
fill_in "_identifiers_1_notation", with: identifier['notation']
end

if is_affiliation || agent.agentType.eql?('organization')
refute_selector ".agents-affiliations"
Expand Down
2 changes: 0 additions & 2 deletions test/fixtures/agents.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ agent1:
email: "[email protected]"
identifiers:
- notation: "0000-0001-2345-6789"
- notation: "0000-0001-2345-6788"
- notation: "0000-0001-2345-6788"
affiliations:
- name: "Research Institute X"
agentType: "organization"
Expand Down
Loading