Skip to content

Commit

Permalink
replace delete_if with select
Browse files Browse the repository at this point in the history
to avoid modifying the original array, which prevents issues with frozen arrays,
fixes #161 "FrozenError - can't modify frozen Array" (part 2)
  • Loading branch information
alexskr committed Sep 27, 2024
1 parent 16d50db commit f98bead
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions helpers/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,4 +21,4 @@ def filter_for_user_onts(obj)
end
end

helpers Sinatra::Helpers::UsersHelper
helpers Sinatra::Helpers::UsersHelper

0 comments on commit f98bead

Please sign in to comment.