From 16d50db896305fd5ce1f2adc2c0ef2ebced75055 Mon Sep 17 00:00:00 2001 From: Alex Skrenchuk Date: Wed, 25 Sep 2024 21:36:21 -0700 Subject: [PATCH 1/2] replace delete_if with select to avoid modifying the original array, which prevents issues with frozen arrays, fixes #161 "FrozenError - can't modify frozen Array" --- helpers/slices_helper.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/helpers/slices_helper.rb b/helpers/slices_helper.rb index d17db53e..6f527f29 100644 --- a/helpers/slices_helper.rb +++ b/helpers/slices_helper.rb @@ -10,10 +10,8 @@ def filter_for_slice(obj) slice = current_slice() - if obj.is_a?(Enumerable) - if obj.first.is_a?(LinkedData::Models::Ontology) - obj.delete_if {|o| !slice.ontology_id_set.include?(o.id.to_s)} - end + if obj.is_a?(Enumerable) && obj.first.is_a?(LinkedData::Models::Ontology) + obj = obj.select { |o| slice.ontology_id_set.include?(o.id.to_s) } end obj end @@ -35,4 +33,4 @@ def current_slice_acronyms end end -helpers Sinatra::Helpers::SlicesHelper \ No newline at end of file +helpers Sinatra::Helpers::SlicesHelper From f98beadeecea22463590f460145356f232543736 Mon Sep 17 00:00:00 2001 From: Alex Skrenchuk Date: Thu, 26 Sep 2024 20:32:53 -0700 Subject: [PATCH 2/2] replace delete_if with select to avoid modifying the original array, which prevents issues with frozen arrays, fixes #161 "FrozenError - can't modify frozen Array" (part 2) --- helpers/application_helper.rb | 8 ++++---- helpers/users_helper.rb | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/helpers/application_helper.rb b/helpers/application_helper.rb index 04999f65..ad813e31 100644 --- a/helpers/application_helper.rb +++ b/helpers/application_helper.rb @@ -125,10 +125,10 @@ def reply(*response) check_access(obj) if LinkedData.settings.enable_security # Slice or set check - filter_for_slice(obj) if LinkedData.settings.enable_slices + obj = filter_for_slice(obj) if LinkedData.settings.enable_slices # Check for custom ontologies set by user - filter_for_user_onts(obj) + obj = filter_for_user_onts(obj) LinkedData::Serializer.build_response(@env, status: status, ld_object: obj) end @@ -211,8 +211,8 @@ def restricted_ontologies(params=nil) found_onts = onts.length > 0 - filter_for_slice(onts) - filter_for_user_onts(onts) + onts = filter_for_slice(onts) + onts = filter_for_user_onts(onts) end onts = filter_access(onts) diff --git a/helpers/users_helper.rb b/helpers/users_helper.rb index 5d4266c1..eeb6f800 100644 --- a/helpers/users_helper.rb +++ b/helpers/users_helper.rb @@ -12,7 +12,7 @@ def filter_for_user_onts(obj) user = env["REMOTE_USER"] if obj.first.is_a?(LinkedData::Models::Ontology) - obj.delete_if {|o| !user.custom_ontology_id_set.include?(o.id.to_s)} + obj = obj.select {|o| user.custom_ontology_id_set.include?(o.id.to_s)} end obj @@ -21,4 +21,4 @@ def filter_for_user_onts(obj) end end -helpers Sinatra::Helpers::UsersHelper \ No newline at end of file +helpers Sinatra::Helpers::UsersHelper