forest_liana 9.6.3 → 9.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ba2b1f8d8557f9d5627817377b70bb733804ab8cba4f8f5c63868261f9e00ad
4
- data.tar.gz: 8d493de4d0148d02e826338b6bb2287c1015094333dfe9891de39be17cc7de8b
3
+ metadata.gz: 8b9d6bfea5beec2a6a055816e4314893627e12c6be2edf1fdd6d94b1f7c01773
4
+ data.tar.gz: c335c707ec38d536cf260bf8e5c84108206424d49e48212132451ff805667e0b
5
5
  SHA512:
6
- metadata.gz: 1e136b9bfe6ba3bb94a5c525f04c6db27a88989fa8b2bff0b2a4341266b8ae901c5cac8c53111d4d0e1b443a9b4dfffdb5954f40a72ac31d1a62ff89a8f2a83b
7
- data.tar.gz: a8e80f6812a1146af8f3faaa5c20733d3cb731f9a0cd79e63bf93118daa1daadb4e6e5e18d5ae6c54d8f09c4bb567b953af474e63b29ffac365c89424c8fcc92
6
+ metadata.gz: e3831c01431c740f1b924875a7c8b7a6abe694d77f51a98934eb19c2fbc240d2f5d04d2fc089fc3f940eaaa0faf3c03de762606c0cce273d6bcfc7912dbd544d
7
+ data.tar.gz: a8bdf701edf00bb1188fdd986ee33dd13d0b89280dc3684a37bf32c2af4b636c3ae4f93f2f1f13f5bf4f6e476a78c9499e1691590562dd69cd7deec3d6755195
@@ -9,11 +9,10 @@ module ForestLiana
9
9
  headers: base_headers.merge(headers),
10
10
  query: query,
11
11
  }).response
12
- rescue
13
- message = "Cannot reach Forest API at #{forest_api_url}#{route}, it seems to be down right now."
14
- FOREST_LOGGER.error message
15
- FOREST_REPORTER.report message
16
- raise
12
+ rescue => error
13
+ FOREST_LOGGER.error "Cannot reach Forest API at #{forest_api_url}#{route}, it seems to be down right now."
14
+ FOREST_REPORTER.report error
15
+ raise error
17
16
  end
18
17
  end
19
18
 
@@ -31,11 +30,10 @@ module ForestLiana
31
30
  query: query,
32
31
  body: body.to_json,
33
32
  }).response
34
- rescue
35
- message = "Cannot reach Forest API at #{post_route}, it seems to be down right now."
36
- FOREST_LOGGER.error message
37
- FOREST_REPORTER.report message
38
- raise
33
+ rescue => error
34
+ FOREST_LOGGER.error "Cannot reach Forest API at #{post_route}, it seems to be down right now."
35
+ FOREST_REPORTER.report error
36
+ raise error
39
37
  end
40
38
  end
41
39
 
@@ -132,6 +132,8 @@ module ForestLiana
132
132
 
133
133
  begin
134
134
  segment_query = @params[:segmentQuery].gsub(/\;\s*$/, '')
135
+ ScopeManager.inject_context_variables_on_query(segment_query, @user)
136
+
135
137
  @records = @records.where(
136
138
  "#{@resource.table_name}.#{@resource.primary_key} IN (SELECT id FROM (#{segment_query}) as ids)"
137
139
  )
@@ -37,13 +37,19 @@ module ForestLiana
37
37
 
38
38
  def self.inject_context_variables(filter, user, request_context_variables = nil)
39
39
  filter = JSON.parse(filter) if filter.is_a? String
40
-
41
40
  retrieve = fetch_scopes(user['rendering_id'])
42
41
  context_variables = Utils::ContextVariables.new(retrieve['team'], user, request_context_variables)
43
42
 
44
43
  Utils::ContextVariablesInjector.inject_context_in_filter(filter, context_variables)
45
44
  end
46
45
 
46
+ def self.inject_context_variables_on_query(query, user)
47
+ retrieve = fetch_scopes(user['rendering_id'])
48
+ context_variables = Utils::ContextVariables.new(retrieve['team'], user)
49
+
50
+ Utils::ContextVariablesInjector.inject_context_in_value(query, context_variables)
51
+ end
52
+
47
53
  def self.invalidate_scope_cache(rendering_id)
48
54
  Rails.cache.delete('forest.scopes.' + rendering_id.to_s)
49
55
  end
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "9.6.3"
2
+ VERSION = "9.7.0"
3
3
  end
@@ -326,6 +326,32 @@ module ForestLiana
326
326
  expect(filters_parser).to have_received(:apply_filters).once
327
327
  end
328
328
  end
329
+
330
+ describe '#inject_context_variables_on_query' do
331
+ let(:query) { "SELECT id FROM users WHERE email = '{{currentUser.email}}'" }
332
+ let(:filled_scope) {
333
+ JSON.generate(
334
+ {
335
+ 'collections' => {
336
+ 'User' => {}
337
+ },
338
+ 'team' => {'id' => '1', 'name' => 'Operations'}
339
+ }
340
+ )
341
+ }
342
+ let(:api_call_response_success) { Net::HTTPOK.new({}, 200, filled_scope) }
343
+
344
+ before do
345
+ allow(ForestLiana::ForestApiRequester).to receive(:get).and_return(api_call_response_success)
346
+ allow(api_call_response_success).to receive(:body).and_return(filled_scope)
347
+ end
348
+
349
+ it 'should inject the context variables in the query' do
350
+ described_class.inject_context_variables_on_query(query, user)
351
+
352
+ expect(query).to eq "SELECT id FROM users WHERE email = 'jd@forestadmin.com'"
353
+ end
354
+ end
329
355
  end
330
356
  end
331
357
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.6.3
4
+ version: 9.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-24 00:00:00.000000000 Z
11
+ date: 2025-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails