Skip to content

Commit

Permalink
Merge pull request #2548 from archivesspace/ANW-1148
Browse files Browse the repository at this point in the history
ANW-1148: bugfix for not being able to set an enumeration default
  • Loading branch information
Brian Hoffman committed Jan 18, 2022
2 parents 6925d39 + be90faf commit 08b11a1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/app/model/enumeration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def self.apply_values(obj, json, opts = {})

# if it's not editable, we cannot add or remove values, but we can set the
# default...
if ( !is_editable and added_values.length > 0 ) or ( !is_editable and removed_values.length > 0 )
if (( !is_editable and added_values.length > 0 ) or ( !is_editable and removed_values.length > 0 )) and opts[:default_value].nil?
raise AccessDeniedException.new("Cannot modify a non-editable enumeration: #{obj.name} with #{ json['values'].join(' , ') }. Only allowed values are : #{ obj.enumeration_value.join(' , ')} ")
end

Expand Down
8 changes: 7 additions & 1 deletion frontend/app/views/enumerations/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,14 @@
</td>
<td>
<div class="btn-group">
<% if enum_value['suppressed'] %>
<% disable_set_default = true %>
<% else %>
<% disable_set_default = false %>
<% end %>
<% if enum_value['value'] != @enumeration['default_value'] %>
<%= link_to I18n.t("actions.set_default"), {:controller => :enumerations, :action => :set_default, :id => JSONModel(:enumeration).id_for(@enumeration["uri"]), :value => enum_value["value"]}, :method => :post, :class=> "btn btn-xs btn-default" %>
<%= link_to I18n.t("actions.set_default"), {:controller => :enumerations, :action => :set_default, :id => JSONModel(:enumeration).id_for(@enumeration["uri"]), :value => enum_value["value"]}, :method => :post, :class=> "btn btn-xs btn-default", :disabled => disable_set_default %>
<% else %>
<%= link_to I18n.t("actions.unset_default"), {:controller => :enumerations, :action => :set_default, :id => JSONModel(:enumeration).id_for(@enumeration["uri"]), :value => nil}, :method => :post, :class=> "btn btn-xs btn-default" %>
<% end%>
Expand Down
23 changes: 23 additions & 0 deletions frontend/spec/selenium/spec/enumeration_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,27 @@

@driver.click_and_wait_until_gone(css: "form#delete_enumeration button[type='submit']")
end

it 'lets you set a default value with another value suppressed' do
@driver.go_home
@driver.get($frontend)
@driver.find_element(:link, 'System').click
@driver.wait_for_dropdown
@driver.click_and_wait_until_gone(:link, 'Manage Controlled Value Lists')

enum_select = @driver.find_element(id: 'enum_selector')
enum_select.select_option_with_text('Record Control Level of Detail (level_of_detail)')

# Wait for the table of enumerations to load
@driver.find_element(:css, '.enumeration-list')

topical = @driver.find_element_with_text('//tr', /natc/)
@driver.click_and_wait_until_element_gone(topical.find_element(:link, 'Suppress'))

temporal = @driver.find_element_with_text('//tr', /not_applicable/)

@driver.click_and_wait_until_element_gone(temporal.find_element(:link, 'Set as Default'))

@driver.find_element(:link, 'Unset Default')
end
end

0 comments on commit 08b11a1

Please sign in to comment.