From fa9c4045d9e9192a4732c52483d45ca62fc66a65 Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Fri, 23 Apr 2021 09:13:20 -0400 Subject: [PATCH] Compacting array building logic This commit serves two purposes: 1) First, and most important, it fixes #4833 2) Second, it unifies the logic for determining the ids More on 4833 (in case you don't have access to Github) The observed error is as follows: > Depositing a work with past embargo gives no id error > > Depositing a work with an embargo date in the past gives an "No ID > provided for ActiveFedora::Base" error. > > Expected Behavior: Depositing a work with a past embargo should fail > to be created and entered information should be preserved In debugging the application, the `@object.member_of_collection_ids` was the following: `["", "admin_set/default"]` That appears to come from the form submitting a select box that has no selected value (e.g., the `""` value). I verified this logic change by UI interaction. --- app/services/hyrax/edit_permissions_service.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/services/hyrax/edit_permissions_service.rb b/app/services/hyrax/edit_permissions_service.rb index 548aab3208..814153334a 100644 --- a/app/services/hyrax/edit_permissions_service.rb +++ b/app/services/hyrax/edit_permissions_service.rb @@ -183,13 +183,7 @@ def object_unauthorized_collection_ids # find all of the collection ids an object is a member of # @return [Array] array of collection ids def object_member_of_ids - @object_member_of_ids ||= begin - belongs_to = [] - # get all of work's collection ids from the form - belongs_to += @object.member_of_collection_ids - belongs_to << @object.admin_set_id if @object.admin_set_id.present? - belongs_to - end + @object_member_of_ids ||= (@object.member_of_collection_ids + [@object.admin_set_id]).select(&:present?) end # The list of all collections this user has manage rights on