deep_unrest 0.1.75 → 0.1.76

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd904080ca3e663bf6e313f0b7c865cab32121f2f22ed02b89ebe28886092232
4
- data.tar.gz: 2de79ffc0cefad4e403b60981f306fb4ca05d1485c88ba4a0396373f2f46c920
3
+ metadata.gz: 5414c5023858644639737c10519236d5d27d7d5f645a65c1a47f784b5c0f1cdc
4
+ data.tar.gz: e36e32772f0e662881f2d29acbbff47634d6f8cb2f214394a52aa72937a43262
5
5
  SHA512:
6
- metadata.gz: 92304e27f64f7c15dd870e65f814a0ad690230a324d801680f69e9b3103025afdfdd873c69a9511dc8fda133d1527625986b38a652bcd61867d15d866375277e
7
- data.tar.gz: a879168e0ac312802e28dfbdc71f8e4851f0a462e32c00ea0c3898865dbd37c72bddabd6940e7c8c225e8cb93204c0ff68e7a3e6844239cc2abf67d9025b5f51
6
+ metadata.gz: afd8b1351ecfc59ae5c4ce9834cdabe02ad3fd4cf89b9e9c955b92512d2a12ca7f1b0a779b649cdc3cc538a8711d8e8071d5199a383ac7f9e11806c9add4e4fe
7
+ data.tar.gz: 5cc341b7eb963ad418a813087c44a24d28aef45548babc7bd35f1f150fba14dc6b804fd501cfc533c950ae7d143224de0422546414241751880b68bc542e8968
@@ -0,0 +1,13 @@
1
+ module DeepUnrest
2
+ module Concerns
3
+ module ResourceScope
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ def records_base(opts)
8
+ opts[:scope] || super(opts)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -4,6 +4,7 @@ require 'deep_unrest/authorization/pundit_strategy'
4
4
  require 'deep_unrest/paginators/basic'
5
5
  require 'deep_unrest/concerns/null_concern'
6
6
  require 'deep_unrest/concerns/map_temp_ids'
7
+ require 'deep_unrest/concerns/resource_scope'
7
8
 
8
9
  module DeepUnrest
9
10
  class Engine < ::Rails::Engine
@@ -116,9 +116,7 @@ module DeepUnrest
116
116
  paginator = get_paginator(query, parent)
117
117
  resource = item[:resource]
118
118
 
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)) }
119
+ resource_scope = item[:scope]
122
120
 
123
121
  # transform sort value casing for rails
124
122
  sort_criteria = query[:sort]&.map { |s| s.clone.merge(field: s[:field].underscore) }
@@ -127,7 +125,7 @@ module DeepUnrest
127
125
  processor = JSONAPI::Processor.new(resource,
128
126
  :find,
129
127
  filters: query[:filter] || {},
130
- context: ctx,
128
+ context: ctx.clone.merge(scope: resource_scope),
131
129
  sort_criteria: sort_criteria,
132
130
  serializer: serializer,
133
131
  paginator: paginator)
@@ -136,9 +134,6 @@ module DeepUnrest
136
134
 
137
135
  resource_results = format_processor_results(resource, jsonapi_result)
138
136
 
139
- # un-monkey patch the resource :records method
140
- resource.define_singleton_method(:records, old_records)
141
-
142
137
  meta << {
143
138
  addr: [*addr, item[:key], 'meta'],
144
139
  serialized_result: {
@@ -169,9 +164,6 @@ module DeepUnrest
169
164
  included << result
170
165
  recurse_included_queries(ctx, result, mappings, parent_context, included, meta, [*next_addr, :include])
171
166
  end
172
- rescue StandardError => e
173
- # un-monkey patch the resource :records method
174
- resource.define_singleton_method(:records, old_records)
175
167
  end
176
168
 
177
169
  def self.get_query_type(item)
@@ -224,3 +216,4 @@ module DeepUnrest
224
216
  end
225
217
  end
226
218
  end
219
+
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeepUnrest
4
- VERSION = '0.1.75'
4
+ VERSION = '0.1.76'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deep_unrest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.75
4
+ version: 0.1.76
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lynn Hurley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-25 00:00:00.000000000 Z
11
+ date: 2021-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -147,6 +147,7 @@ files:
147
147
  - lib/deep_unrest/authorization/pundit_strategy.rb
148
148
  - lib/deep_unrest/concerns/map_temp_ids.rb
149
149
  - lib/deep_unrest/concerns/null_concern.rb
150
+ - lib/deep_unrest/concerns/resource_scope.rb
150
151
  - lib/deep_unrest/engine.rb
151
152
  - lib/deep_unrest/paginators/basic.rb
152
153
  - lib/deep_unrest/read.rb