deep_unrest 0.1.72 → 0.1.73
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/deep_unrest/read.rb +8 -26
- data/lib/deep_unrest/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8dc811b66aacee9eef482287d03e975dc75dbd0844d5b198ff3cff8d3acb4a6d
|
4
|
+
data.tar.gz: 3302fe2dfde86ab590d4e430b2a5ced5c3d97bdfcad6fe770aff1201600b6f07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5b98c8dd8a70c97d5858f4f3b2ac8cfc4f106a4109d96302e7a1cb3ae492edaf244934beec3b646975f20e1d13dfbdc8b32b8a85de609f07761b37df2531812
|
7
|
+
data.tar.gz: 312a209f70086b73cbf636aeefcb318e49c87b5134bc20987612e49d10fe7dae292be6216624b7b1270cd8b0c5f3253eec138b565dbc582e96b32a899818b8da
|
data/lib/deep_unrest/read.rb
CHANGED
@@ -116,27 +116,14 @@ module DeepUnrest
|
|
116
116
|
paginator = get_paginator(query, parent)
|
117
117
|
resource = item[:resource]
|
118
118
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
alias_method :records_original, :records
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
# TODO: find a way to do this that doesn't blow out the original :records method
|
127
|
-
resource.define_singleton_method(:records) { |ctx|
|
128
|
-
full_scope = if self.respond_to? :records_original
|
129
|
-
records_original(ctx)
|
130
|
-
else
|
131
|
-
super(ctx)
|
132
|
-
end
|
133
|
-
|
134
|
-
item[:scope].merge(full_scope)
|
135
|
-
}
|
119
|
+
# monkey patch the resource to only show authorized records
|
120
|
+
old_records = resource.method(:records)
|
121
|
+
resource.define_singleton_method(:records) { |ctx| item[:scope].merge(old_records.call(ctx)) }
|
136
122
|
|
137
123
|
# transform sort value casing for rails
|
138
124
|
sort_criteria = query[:sort]&.map { |s| s.clone.merge(field: s[:field].underscore) }
|
139
125
|
serializer = JSONAPI::ResourceSerializer.new(resource)
|
126
|
+
|
140
127
|
processor = JSONAPI::Processor.new(resource,
|
141
128
|
:find,
|
142
129
|
filters: query[:filter] || {},
|
@@ -146,8 +133,12 @@ module DeepUnrest
|
|
146
133
|
paginator: paginator)
|
147
134
|
|
148
135
|
jsonapi_result = processor.process
|
136
|
+
|
149
137
|
resource_results = format_processor_results(resource, jsonapi_result)
|
150
138
|
|
139
|
+
# un-monkey patch the resource :records method
|
140
|
+
resource.define_singleton_method(:records) { |ctx| old_records.call(ctx) }
|
141
|
+
|
151
142
|
meta << {
|
152
143
|
addr: [*addr, item[:key], 'meta'],
|
153
144
|
serialized_result: {
|
@@ -178,15 +169,6 @@ module DeepUnrest
|
|
178
169
|
included << result
|
179
170
|
recurse_included_queries(ctx, result, mappings, parent_context, included, meta, [*next_addr, :include])
|
180
171
|
end
|
181
|
-
ensure
|
182
|
-
# un-monkey patch the resource :records method
|
183
|
-
if r_metaclass.method_defined? :records_original
|
184
|
-
r_metaclass.class_eval do
|
185
|
-
alias_method :records, :records_original
|
186
|
-
end
|
187
|
-
else
|
188
|
-
r_metaclass.undef_method :records
|
189
|
-
end
|
190
172
|
end
|
191
173
|
|
192
174
|
def self.get_query_type(item)
|
data/lib/deep_unrest/version.rb
CHANGED