diff --git a/Gemfile b/Gemfile index f9b7756a7..7a952fe7a 100644 --- a/Gemfile +++ b/Gemfile @@ -18,7 +18,7 @@ gem 'assembly-objectfile', '~> 1.5' # We don't require this by default, because we need it to load after hydrus models # or we'll get a superclass mismatch for Hydrus::Item gem 'dor-services', '~> 7.1', require: false -gem 'dor-services-client', '~> 1.1' +gem 'dor-services-client', '~> 1.9.2' gem 'rubydora', '~> 2.1' gem 'bagit', '~> 0.4' gem 'blacklight', '~> 6.19' diff --git a/Gemfile.lock b/Gemfile.lock index 8a78216af..6220b7dff 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -196,12 +196,13 @@ GEM stanford-mods (>= 2.3.1) stanford-mods-normalizer (~> 0.1) systemu (~> 2.6) - dor-services-client (1.8.0) + dor-services-client (1.9.2) activesupport (>= 4.2, < 6) deprecation faraday (~> 0.15) moab-versioning (~> 4.0) nokogiri (~> 1.8) + zeitwerk (~> 2.1) dor-workflow-client (3.2.0) activesupport (>= 3.2.1, < 6) deprecation (~> 0) @@ -539,6 +540,7 @@ GEM xml-simple (1.1.5) xpath (3.2.0) nokogiri (~> 1.8) + zeitwerk (2.1.6) PLATFORMS ruby @@ -565,7 +567,7 @@ DEPENDENCIES devise-remote-user (~> 1.0) dlss-capistrano dor-services (~> 7.1) - dor-services-client (~> 1.1) + dor-services-client (~> 1.9.2) dynamic_form equivalent-xml factory_bot_rails diff --git a/app/models/hydrus/item.rb b/app/models/hydrus/item.rb index a9d49b443..d234dd40c 100644 --- a/app/models/hydrus/item.rb +++ b/app/models/hydrus/item.rb @@ -170,7 +170,7 @@ def resubmit # - Other options: # :no_super Used to prevent super() during testing. def open_new_version(opts = {}) - raise "#{cannot_do_message(:open_new_version)}\nItem is not accessioned" unless is_accessioned + raise "#{cannot_do_message(:open_new_version)}\nItem is not accessioned" unless version_openeable? # Store the time when the object was initially published. self.initial_publish_time = publish_time if is_initial_version @@ -179,7 +179,7 @@ def open_new_version(opts = {}) vers_md_upd_info[:significance] = opts[:significance] || :major vers_md_upd_info[:description] = opts[:description] || '' # Use the dor-services-client to open a new version, passing along args needed by Hydrus - Dor::Services::Client.object(pid).open_new_version(assume_accessioned: should_treat_as_accessioned, vers_md_upd_info: vers_md_upd_info) + Dor::Services::Client.object(pid).version.open(assume_accessioned: should_treat_as_accessioned, vers_md_upd_info: vers_md_upd_info) # Varying behavior: remediations vs ordinary user edits. if opts[:is_remediation] # Just log the event. @@ -207,7 +207,7 @@ def close_version(opts = {}) # We want to start accessioning only if ... sa = !!opts[:is_remediation] # ... we are running a remediation and sa = false if should_treat_as_accessioned # ... we are not in development or test - Dor::Services::Client.object(pid).close_version(version_num: version_id, start_accession: sa) + Dor::Services::Client.object(pid).version.close(version_num: version_id, start_accession: sa) end # indicates if this item has an accepted terms of deposit, or if the supplied diff --git a/app/models/hydrus/processable.rb b/app/models/hydrus/processable.rb index 85c582d00..b95f113af 100644 --- a/app/models/hydrus/processable.rb +++ b/app/models/hydrus/processable.rb @@ -64,24 +64,12 @@ def should_start_assembly_wf Dor::Config.hydrus.start_assembly_wf end - # Returns true if the most recent version of the object has been accessioned. - def is_accessioned - # Basic tests: - # - Must be published before it can be accessioned. - # - For local development and automated testing, treat published as - # equivalent to accessioned. + # Returns true if a new version can be opened for the object. + def version_openeable? return false unless is_published - return true if should_treat_as_accessioned - - # Return false unless has been accessioned at least once. - # accessioned lifecyle is set in the last step in the accessionWF. - return false unless workflow_client.lifecycle(REPO, pid, 'accessioned') - - # Return false if accessionWF has been started for most current version and there are there are any incomplete workflow steps. - return false if workflow_client.active_lifecycle(REPO, pid, 'submitted') - - # Accessioned. - true + # For testing, this avoids Dor::Services::Client. + return false if should_treat_as_accessioned + Dor::Services::Client.object(pid).version.openeable?(assume_accessioned: should_treat_as_accessioned) end # Returns a string -- the datetime when the object achived the published diff --git a/app/views/hydrus_items/_actions_box_show.html.erb b/app/views/hydrus_items/_actions_box_show.html.erb index cba42941e..d4ff301b9 100644 --- a/app/views/hydrus_items/_actions_box_show.html.erb +++ b/app/views/hydrus_items/_actions_box_show.html.erb @@ -77,7 +77,7 @@

- <% elsif @fobj.is_accessioned && can?(:edit, @fobj) %> + <% elsif @fobj.version_openeable? && can?(:edit, @fobj) %>

<%= button_to "Open new version", open_new_version_item_path(@fobj), diff --git a/spec/models/hydrus/item_spec.rb b/spec/models/hydrus/item_spec.rb index d6e264144..806558fc5 100644 --- a/spec/models/hydrus/item_spec.rb +++ b/spec/models/hydrus/item_spec.rb @@ -1112,7 +1112,7 @@ # More significant testing is done at the integration level. context 'when the item has not been accessioned' do before do - allow(item).to receive(:is_accessioned).and_return(false) + allow(item).to receive(:version_openeable?).and_return(false) end it 'raises an exception' do @@ -1121,20 +1121,23 @@ end context 'when it has been accessioned' do - let(:object_client) { instance_double(Dor::Services::Client::Object, open_new_version: true) } + let(:object_client) { instance_double(Dor::Services::Client::Object) } + + let(:version_client) { instance_double(Dor::Services::Client::ObjectVersion, open: true) } before do item.submitted_for_publish_time = HyTime.now_datetime item.visibility = 'stanford' - allow(item).to receive(:is_accessioned).and_return(true) + allow(item).to receive(:version_openeable?).and_return(true) allow(Dor::Services::Client).to receive(:object).and_return(object_client) + allow(object_client).to receive(:version).and_return(version_client) allow(item).to receive(:uncomplete_workflow_steps) end it 'calls the client and sets prior_visibility to the old visibility value' do expect(item).to receive(:start_hydrus_wf) item.open_new_version - expect(object_client).to have_received(:open_new_version) + expect(version_client).to have_received(:open) expect(item.prior_visibility).to eq 'stanford' end end @@ -1148,16 +1151,19 @@ end end context 'when item is not initial version' do - let(:object_client) { instance_double(Dor::Services::Client::Object, close_version: true) } + let(:object_client) { instance_double(Dor::Services::Client::Object) } + + let(:version_client) { instance_double(Dor::Services::Client::ObjectVersion, close: true) } before do allow(item).to receive(:is_initial_version).and_return(false) allow(Dor::Services::Client).to receive(:object).and_return(object_client) + allow(object_client).to receive(:version).and_return(version_client) end it 'calls the client and sets prior_visibility to the old visibility value' do item.close_version - expect(object_client).to have_received(:close_version).with(version_num: '1', start_accession: false) + expect(version_client).to have_received(:close).with(version_num: '1', start_accession: false) end end end diff --git a/spec/models/hydrus/processable_spec.rb b/spec/models/hydrus/processable_spec.rb index 6857070b5..5ca86cacd 100644 --- a/spec/models/hydrus/processable_spec.rb +++ b/spec/models/hydrus/processable_spec.rb @@ -88,32 +88,41 @@ end end - describe 'is_accessioned()' do - let(:wfs) { instance_double(Dor::Workflow::Client) } - before do - allow(Dor::Config.workflow).to receive(:client).and_return(wfs) - end + describe 'version_openeable?' do + let(:object_client) { instance_double(Dor::Services::Client::Object) } + let(:version_client) { instance_double(Dor::Services::Client::ObjectVersion) } - it 'can exercise all logic branches' do - # At each stage, we set a stub, call is_accessioned(), and then reverse the stub. - # Not published: false. - allow(@go).to receive(:is_published).and_return(false) - expect(@go.is_accessioned).to eq(false) + before do allow(@go).to receive(:is_published).and_return(true) - # Running in development or test mode: true. - allow(@go).to receive(:should_treat_as_accessioned).and_return(true) - expect(@go.is_accessioned).to eq(true) allow(@go).to receive(:should_treat_as_accessioned).and_return(false) - # Never accessioned: false. - allow(wfs).to receive(:lifecycle).with('dor', @go.pid, 'accessioned').and_return(false) - expect(@go.is_accessioned).to eq(false) - allow(wfs).to receive(:lifecycle).with('dor', @go.pid, 'accessioned').and_return(true) - # AccessionWF active for current version: true - allow(wfs).to receive(:active_lifecycle).with('dor', @go.pid, 'submitted').and_return(true) - expect(@go.is_accessioned).to eq(false) - allow(wfs).to receive(:active_lifecycle).with('dor', @go.pid, 'submitted').and_return(false) - # Survived all tests: true. - expect(@go.is_accessioned).to eq(true) + allow(version_client).to receive(:openeable?).and_return(true) + allow(Dor::Services::Client).to receive(:object).and_return(object_client) + allow(object_client).to receive(:version).and_return(version_client) + end + + context 'when item has not been published' do + before do + allow(@go).to receive(:is_published).and_return(false) + end + + it 'returns false' do + expect(@go.version_openeable?).to eq(false) + end + end + context 'when published, but dor-services-app reports a new version cannot be opened' do + before do + allow(version_client).to receive(:openeable?).and_return(false) + end + + it 'returns false' do + expect(@go.version_openeable?).to eq(false) + end + end + + context 'when published and dor-services-app reports a new version can be opened' do + it 'returns true' do + expect(@go.version_openeable?).to eq(true) + end end end