forest_liana 9.5.3 → 9.5.5

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: 331a5a4b04f74fad06fa9b8f9443e2a91c27685483fb1bba39bedb1b409c498c
4
- data.tar.gz: 055da277ebd38b2617dbc5b61a24dfb0b0bf474bb65fb8763d50ed694926122a
3
+ metadata.gz: 3d1c39075bf7b59d268ffd575ef52feb25eb8a67a370f08b4f94a1bca39288ac
4
+ data.tar.gz: 3c7e36125001dd9ed399239848260652ea6736b18cf9c93a3bf7a4eba7b2497c
5
5
  SHA512:
6
- metadata.gz: 50c346b60aea696ed3295aa82c51cb92167e94c0a24168f039f1d673f2c9e48bed79b6699004d00b55e35bfb3b1ed55a0465c8f8b824256e645da831ca6b89cd
7
- data.tar.gz: aa3fd7c4133120ff50c0c88a4ab0b5873a6f5a28d1acd83b11a409a3557e15c0f8dbad572a43f44f39e1ba0d142f282a4a9a9ebf68e8496d7cd1425eedd0b5ed
6
+ metadata.gz: f30ea56ebf1e756c17df2398c6746b89165fadda18427b48b3685e5f78276c5994c586f33067c366ddb132245d4a0b0c40e3a562c39a01379319ef8cd7ce84ac
7
+ data.tar.gz: 57b9e0b67ca52e8f5703cd989a627f53e2eea910ba923a62f14b22482cee38ee9d0b22ac91aa38fe2f5b29a1a0244ac50cdad93f50cbfe113c73515c5c4d0cc8
@@ -49,20 +49,15 @@ module ForestLiana
49
49
  end
50
50
 
51
51
  def self.fetch_scopes(rendering_id)
52
- response = ForestLiana::ForestApiRequester.get("/liana/v4/permissions/renderings/#{rendering_id}")
53
-
54
- if response.is_a?(Net::HTTPOK)
55
- Rails.cache.fetch('forest.scopes.' + rendering_id.to_s, expires_in: @@scope_cache_expiration_delta) do
56
- data = {}
57
- parse_response = JSON.parse(response.body)
58
-
59
- data['scopes'] = decode_scope(parse_response['collections'])
60
- data['team'] = parse_response['team']
61
-
62
- data
63
- end
64
- else
65
- raise 'Unable to fetch scopes'
52
+ Rails.cache.fetch("forest.scopes.#{rendering_id}", expires_in: @@scope_cache_expiration_delta) do
53
+ response = ForestLiana::ForestApiRequester.get("/liana/v4/permissions/renderings/#{rendering_id}")
54
+ raise 'Unable to fetch scopes' unless response.is_a?(Net::HTTPOK)
55
+ parsed_response = JSON.parse(response.body)
56
+
57
+ {
58
+ 'scopes' => decode_scope(parsed_response['collections']),
59
+ 'team' => parsed_response['team']
60
+ }
66
61
  end
67
62
  end
68
63
 
@@ -30,6 +30,7 @@ module ForestLiana
30
30
  if field.try(:[], :search)
31
31
  begin
32
32
  @records = field[:search].call(@records, @search)
33
+ (@fields_searched << field[:field].to_s) if field[:type] == 'String'
33
34
  rescue => exception
34
35
  FOREST_REPORTER.report exception
35
36
  FOREST_LOGGER.error "Cannot search properly on Smart Field:\n" \
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "9.5.3"
2
+ VERSION = "9.5.5"
3
3
  end
@@ -8,7 +8,12 @@ class Forest::User
8
8
  "name IS '#{capitalize_name}'"
9
9
  end
10
10
 
11
- field :cap_name, type: 'String', filter: filter_cap_name do
11
+ search_cap_name = lambda do |query, search|
12
+ # Injects your new filter into the query.
13
+ query.or(User.where("name = '#{search}'"))
14
+ end
15
+
16
+ field :cap_name, type: 'String', filter: filter_cap_name, search: search_cap_name do
12
17
  object.name.upcase
13
18
  end
14
19
 
@@ -154,6 +154,100 @@ describe 'Requesting Tree resources', :type => :request do
154
154
  end
155
155
  end
156
156
 
157
+ describe 'Requesting User resources', :type => :request do
158
+ describe 'index' do
159
+ before do
160
+ User.create(name: 'John')
161
+
162
+ Rails.cache.write('forest.users', {'1' => { 'id' => 1, 'roleId' => 1, 'rendering_id' => '1' }})
163
+ Rails.cache.write('forest.has_permission', true)
164
+ Rails.cache.write(
165
+ 'forest.collections',
166
+ {
167
+ 'User' => {
168
+ 'browse' => [1],
169
+ 'read' => [1],
170
+ 'edit' => [1],
171
+ 'add' => [1],
172
+ 'delete' => [1],
173
+ 'export' => [1],
174
+ 'actions' => {}
175
+ }
176
+ }
177
+ )
178
+
179
+ allow(ForestLiana::IpWhitelist).to receive(:retrieve) { true }
180
+ allow(ForestLiana::IpWhitelist).to receive(:is_ip_whitelist_retrieved) { true }
181
+ allow(ForestLiana::IpWhitelist).to receive(:is_ip_valid) { true }
182
+ allow(ForestLiana::ScopeManager).to receive(:fetch_scopes).and_return(
183
+ {'scopes' => {}, 'team' => {'id' => '1', 'name' => 'Operations'}}
184
+ )
185
+ end
186
+
187
+ after do
188
+ User.destroy_all
189
+ end
190
+
191
+ it 'should respond the user data with meta when search apply on simple column and smart field' do
192
+ token = JWT.encode({
193
+ id: 1,
194
+ email: 'michael.kelso@that70.show',
195
+ first_name: 'Michael',
196
+ last_name: 'Kelso',
197
+ team: 'Operations',
198
+ rendering_id: 16,
199
+ exp: Time.now.to_i + 2.weeks.to_i,
200
+ permission_level: 'admin'
201
+ }, ForestLiana.auth_secret, 'HS256')
202
+
203
+ headers = {
204
+ 'Accept' => 'application/json',
205
+ 'Content-Type' => 'application/json',
206
+ 'Authorization' => "Bearer #{token}"
207
+ }
208
+
209
+ params = {
210
+ fields: { 'User' => 'id,name,cap_name' },
211
+ page: { 'number' => '1', 'size' => '10' },
212
+ searchExtended: '0',
213
+ search: 'JOHN',
214
+ sort: '-id',
215
+ timezone: 'Europe/Paris'
216
+ }
217
+
218
+ allow(ForestAdmin::JSONAPI::Serializer).to receive(:serialize).and_return(
219
+ { "data" => [
220
+ {
221
+ "type" => "User",
222
+ "id" => "1",
223
+ "attributes" => { "id" => 1, "name" => "John", "cap_name" => "JOHN" },
224
+ "links" => { "self" => "/forest/user/1" }
225
+ }
226
+ ], "included" => [] }
227
+ )
228
+
229
+ get '/forest/User', params: params, headers: headers
230
+
231
+ expect(JSON.parse(response.body)).to include(
232
+ "data" => [
233
+ {
234
+ "type" => "User",
235
+ "id" => "1",
236
+ "attributes" => {
237
+ "id" => 1,
238
+ "name" => "John",
239
+ "cap_name" => "JOHN"
240
+ },
241
+ "links" => { "self" => "/forest/user/1" },
242
+ }
243
+ ],
244
+ "included" => [],
245
+ "meta" => { 'decorators' => { '0' => { 'id' => "1", 'search' => %w[name cap_name] } } }
246
+ )
247
+ end
248
+ end
249
+ end
250
+
157
251
  describe 'Requesting Address resources', :type => :request do
158
252
  let(:scope_filters) { {'scopes' => {}, 'team' => {'id' => '1', 'name' => 'Operations'}} }
159
253
  before do
@@ -73,6 +73,14 @@ module ForestLiana
73
73
  'team' => {'id' => '1', 'name' => 'Operations'},
74
74
  })
75
75
  end
76
+
77
+ it 'calls the API only once, even with multiple fetch_scopes calls' do
78
+ described_class.fetch_scopes(rendering_id)
79
+ described_class.fetch_scopes(rendering_id)
80
+
81
+ expect(ForestLiana::ForestApiRequester).to have_received(:get).once
82
+ end
83
+
76
84
  end
77
85
 
78
86
  describe 'when scope contains dynamic values' do
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.5.3
4
+ version: 9.5.5
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-11-22 00:00:00.000000000 Z
11
+ date: 2024-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails