Skip to content

Commit

Permalink
Fix: Disable multiple identifiers for agents (#730)
Browse files Browse the repository at this point in the history
* fix: identifier for organizations is ror and for persons is orcid

* disable multiple identifiers for agents in agents form

* remove the restriction for certain submission fields to create only organization type or person type agents

* fix agent tests after changing agent identifier to not be a list

---------

Co-authored-by: Syphax <[email protected]>
  • Loading branch information
Bilelkihal and syphax-bouazzouni committed Aug 8, 2024
1 parent be29543 commit 563b2b4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 31 deletions.
1 change: 1 addition & 0 deletions app/controllers/agents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,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]
- 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

0 comments on commit 563b2b4

Please sign in to comment.