Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/protector/adapters/active_record/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ def exec_queries_with_protector(*args)
relation = protector_relation.unrestrict!
relation = protector_substitute_includes(subject, relation)

# inmmutable relation in cached Arel
# prevents deprecation warning and error raises in newer versions
# https://github.com/rails/rails/commit/1b7aa62b184c4410c99208f71b59bbac5c5f03be
# https://github.com/rails/rails/commit/3ae98181433dda1b5e19910e107494762512a86c
# https://github.com/rails/rails/issues/14848
relation = relation.clone
# Preserve associations from internal loading. We are going to handle that
# ourselves respecting security scopes FTW!
associations, relation.preload_values = relation.preload_values, []
Expand All @@ -159,6 +165,12 @@ def exec_queries_with_protector(*args)
# Swaps `includes` with `preload` if it's not referenced or merges
# security scope of proper class otherwise
def protector_substitute_includes(subject, relation)
# inmmutable relation in cached Arel
# prevents deprecation warning and error raises in newer versions
# https://github.com/rails/rails/commit/1b7aa62b184c4410c99208f71b59bbac5c5f03be
# https://github.com/rails/rails/commit/3ae98181433dda1b5e19910e107494762512a86c
# https://github.com/rails/rails/issues/14848
relation = relation.clone
if relation.eager_loading?
protector_expand_inclusion(relation.includes_values + relation.eager_load_values).each do |klass, path|
# AR drops default_scope for eagerly loadable associations
Expand All @@ -179,6 +191,12 @@ def protector_substitute_includes(subject, relation)
end
end
else
# inmmutable relation in cached Arel
# prevents deprecation warning and error raises in newer versions
# https://github.com/rails/rails/commit/1b7aa62b184c4410c99208f71b59bbac5c5f03be
# https://github.com/rails/rails/commit/3ae98181433dda1b5e19910e107494762512a86c
# https://github.com/rails/rails/issues/14848
relation = relation.clone
relation.preload_values += includes_values
relation.includes_values = []
end
Expand Down