From 1e73fb699bcf146ad9725e39876fa755f2da1a98 Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Mon, 14 Oct 2024 16:35:25 -0400 Subject: [PATCH 1/2] Remove reliance on noid for find MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Switches from using noids to using a fallback... look first by id, and then by alternate_identifier instead. I created a work in dassie with VALKYRIE_TRANSITION=true and then I was unable to edit the work because I don’t have an alternative identifier. --- lib/hyrax/valkyrie_can_can_adapter.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/hyrax/valkyrie_can_can_adapter.rb b/lib/hyrax/valkyrie_can_can_adapter.rb index 70a4786f4f..fbbf26d79c 100644 --- a/lib/hyrax/valkyrie_can_can_adapter.rb +++ b/lib/hyrax/valkyrie_can_can_adapter.rb @@ -19,8 +19,8 @@ def self.for_class?(member_class) # # @raise Hyrax::ObjectNotFoundError def self.find(_model_class, id) - return Hyrax.query_service.find_by(id: id) unless Hyrax.config.enable_noids? - Hyrax.query_service.find_by_alternate_identifier(alternate_identifier: id) + Hyrax.query_service.find_by(id: id) || + Hyrax.query_service.find_by_alternate_identifier(alternate_identifier: id) rescue Valkyrie::Persistence::ObjectNotFoundError => err raise Hyrax::ObjectNotFoundError, err.message end From 5bee72d07bc02f0ac44475faad9006434203877a Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Mon, 14 Oct 2024 18:56:15 -0400 Subject: [PATCH 2/2] Rearrange code to allow fallback to alternative_id --- lib/hyrax/valkyrie_can_can_adapter.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/hyrax/valkyrie_can_can_adapter.rb b/lib/hyrax/valkyrie_can_can_adapter.rb index fbbf26d79c..471106bd11 100644 --- a/lib/hyrax/valkyrie_can_can_adapter.rb +++ b/lib/hyrax/valkyrie_can_can_adapter.rb @@ -19,10 +19,17 @@ def self.for_class?(member_class) # # @raise Hyrax::ObjectNotFoundError def self.find(_model_class, id) - Hyrax.query_service.find_by(id: id) || - Hyrax.query_service.find_by_alternate_identifier(alternate_identifier: id) + self.find_by(id:) || + Hyrax.query_service.find_by_alternate_identifier(alternate_identifier: id) rescue Valkyrie::Persistence::ObjectNotFoundError => err raise Hyrax::ObjectNotFoundError, err.message end + + private + + def self.find_by(id:) + Hyrax.query_service.find_by(id:) + rescue Valkyrie::Persistence::ObjectNotFoundError + end end end