forest_liana 7.0.0.beta.2 → 7.0.0.beta.6
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 +4 -4
- data/app/controllers/forest_liana/actions_controller.rb +20 -18
- data/app/controllers/forest_liana/application_controller.rb +0 -9
- data/app/controllers/forest_liana/associations_controller.rb +2 -2
- data/app/controllers/forest_liana/resources_controller.rb +16 -6
- data/app/controllers/forest_liana/scopes_controller.rb +20 -0
- data/app/controllers/forest_liana/smart_actions_controller.rb +39 -6
- data/app/controllers/forest_liana/stats_controller.rb +5 -5
- data/app/services/forest_liana/apimap_sorter.rb +1 -0
- data/app/services/forest_liana/filters_parser.rb +8 -4
- data/app/services/forest_liana/has_many_dissociator.rb +2 -2
- data/app/services/forest_liana/has_many_getter.rb +2 -2
- data/app/services/forest_liana/leaderboard_stat_getter.rb +20 -14
- data/app/services/forest_liana/line_stat_getter.rb +5 -3
- data/app/services/forest_liana/permissions_checker.rb +42 -37
- data/app/services/forest_liana/permissions_formatter.rb +1 -1
- data/app/services/forest_liana/permissions_getter.rb +3 -6
- data/app/services/forest_liana/pie_stat_getter.rb +6 -3
- data/app/services/forest_liana/resource_getter.rb +6 -3
- data/app/services/forest_liana/resource_updater.rb +5 -2
- data/app/services/forest_liana/resources_getter.rb +6 -5
- data/app/services/forest_liana/scope_manager.rb +102 -0
- data/app/services/forest_liana/search_query_builder.rb +6 -3
- data/app/services/forest_liana/stat_getter.rb +2 -1
- data/app/services/forest_liana/token.rb +1 -0
- data/app/services/forest_liana/utils/beta_schema_utils.rb +1 -1
- data/app/services/forest_liana/value_stat_getter.rb +4 -2
- data/config/routes.rb +3 -1
- data/lib/forest_liana/bootstrapper.rb +4 -2
- data/lib/forest_liana/version.rb +1 -1
- data/spec/dummy/app/controllers/forest/islands_controller.rb +5 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/lib/forest_liana/collections/island.rb +7 -0
- data/spec/lib/forest_liana/bootstrapper_spec.rb +12 -0
- data/spec/requests/actions_controller_spec.rb +144 -23
- data/spec/requests/authentications_spec.rb +2 -1
- data/spec/requests/resources_spec.rb +2 -0
- data/spec/services/forest_liana/apimap_sorter_spec.rb +6 -4
- data/spec/services/forest_liana/filters_parser_spec.rb +1 -1
- data/spec/services/forest_liana/has_many_getter_spec.rb +116 -0
- data/spec/services/forest_liana/line_stat_getter_spec.rb +14 -6
- data/spec/services/forest_liana/permissions_checker_acl_disabled_spec.rb +45 -71
- data/spec/services/forest_liana/permissions_checker_acl_enabled_spec.rb +39 -63
- data/spec/services/forest_liana/permissions_checker_live_queries_spec.rb +3 -3
- data/spec/services/forest_liana/permissions_formatter_spec.rb +11 -11
- data/spec/services/forest_liana/pie_stat_getter_spec.rb +114 -0
- data/spec/services/forest_liana/resource_updater_spec.rb +116 -0
- data/spec/services/forest_liana/resources_getter_spec.rb +68 -1
- data/spec/services/forest_liana/scope_manager_spec.rb +232 -0
- data/spec/services/forest_liana/value_stat_getter_spec.rb +96 -0
- metadata +125 -118
- data/app/services/forest_liana/scope_validator.rb +0 -98
- data/test/services/forest_liana/has_many_getter_test.rb +0 -75
- data/test/services/forest_liana/pie_stat_getter_test.rb +0 -29
- data/test/services/forest_liana/resource_updater_test.rb +0 -86
- data/test/services/forest_liana/scope_validator_test.rb +0 -185
- data/test/services/forest_liana/value_stat_getter_test.rb +0 -71
@@ -1,12 +1,21 @@
|
|
1
1
|
module ForestLiana
|
2
2
|
describe LineStatGetter do
|
3
|
+
let(:rendering_id) { 13 }
|
4
|
+
let(:user) { { 'id' => '1', 'rendering_id' => rendering_id } }
|
5
|
+
let(:scopes) { { } }
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
ForestLiana::ScopeManager.invalidate_scope_cache(rendering_id)
|
9
|
+
allow(ForestLiana::ScopeManager).to receive(:fetch_scopes).and_return(scopes)
|
10
|
+
end
|
11
|
+
|
3
12
|
describe 'Check client_timezone function' do
|
4
13
|
describe 'with a SQLite database' do
|
5
14
|
it 'should return false' do
|
6
15
|
expect(LineStatGetter.new(Owner, {
|
7
16
|
timezone: "Europe/Paris",
|
8
17
|
aggregate: "Count",
|
9
|
-
}).client_timezone).to eq(false)
|
18
|
+
}, user).client_timezone).to eq(false)
|
10
19
|
end
|
11
20
|
end
|
12
21
|
|
@@ -16,7 +25,7 @@ module ForestLiana
|
|
16
25
|
expect(LineStatGetter.new(Owner, {
|
17
26
|
timezone: "Europe/Paris",
|
18
27
|
aggregate: "Count",
|
19
|
-
}).client_timezone).to eq('Europe/Paris')
|
28
|
+
}, user).client_timezone).to eq('Europe/Paris')
|
20
29
|
end
|
21
30
|
end
|
22
31
|
end
|
@@ -25,7 +34,6 @@ module ForestLiana
|
|
25
34
|
describe 'Using a Count aggregation' do
|
26
35
|
describe 'Using a Week time range' do
|
27
36
|
it 'should return consistent data based on monday as week_start ' do
|
28
|
-
|
29
37
|
# Week should start on monday
|
30
38
|
# 08-05-2021 was a Saturday
|
31
39
|
Owner.create(name: 'Michel', hired_at: Date.parse('08-05-2021'));
|
@@ -38,8 +46,8 @@ module ForestLiana
|
|
38
46
|
aggregate: "Count",
|
39
47
|
time_range: "Week",
|
40
48
|
group_by_date_field: "hired_at",
|
41
|
-
}).perform
|
42
|
-
|
49
|
+
}, user).perform
|
50
|
+
|
43
51
|
expect(stat.value.find { |item| item[:label] == "W18-2021" }[:values][:value]).to eq(2)
|
44
52
|
expect(stat.value.find { |item| item[:label] == "W19-2021" }[:values][:value]).to eq(2)
|
45
53
|
end
|
@@ -47,4 +55,4 @@ module ForestLiana
|
|
47
55
|
end
|
48
56
|
end
|
49
57
|
end
|
50
|
-
end
|
58
|
+
end
|
@@ -75,7 +75,7 @@ module ForestLiana
|
|
75
75
|
"users" => nil
|
76
76
|
},
|
77
77
|
},
|
78
|
-
"
|
78
|
+
"segments" => nil
|
79
79
|
},
|
80
80
|
"no_rights_collection" => {
|
81
81
|
"collection" => {
|
@@ -93,7 +93,7 @@ module ForestLiana
|
|
93
93
|
"users" => nil
|
94
94
|
}
|
95
95
|
},
|
96
|
-
"
|
96
|
+
"segments" => nil
|
97
97
|
},
|
98
98
|
},
|
99
99
|
"meta" => {
|
@@ -146,6 +146,8 @@ module ForestLiana
|
|
146
146
|
|
147
147
|
context 'with permissions coming from 2 different renderings' do
|
148
148
|
let(:collection_name) { 'custom' }
|
149
|
+
|
150
|
+
let(:segments_permissions) { nil }
|
149
151
|
let(:api_permissions_rendering_1) {
|
150
152
|
{
|
151
153
|
"data" => {
|
@@ -160,7 +162,7 @@ module ForestLiana
|
|
160
162
|
"searchToEdit" => true
|
161
163
|
},
|
162
164
|
"actions" => { },
|
163
|
-
"
|
165
|
+
"segments" => segments_permissions
|
164
166
|
},
|
165
167
|
},
|
166
168
|
"meta" => {
|
@@ -189,12 +191,11 @@ module ForestLiana
|
|
189
191
|
end
|
190
192
|
end
|
191
193
|
|
192
|
-
|
193
|
-
context 'scopes cache' do
|
194
|
+
context 'renderings cache' do
|
194
195
|
let(:fake_ressource) { collection_name }
|
195
196
|
let(:rendering_id) { 1 }
|
196
197
|
let(:collection_name) { 'custom' }
|
197
|
-
let(:
|
198
|
+
let(:segments_permissions) { { rendering_id => { 'custom' => nil } } }
|
198
199
|
let(:api_permissions) {
|
199
200
|
{
|
200
201
|
"data" => {
|
@@ -209,7 +210,7 @@ module ForestLiana
|
|
209
210
|
"searchToEdit" => true
|
210
211
|
},
|
211
212
|
"actions" => { },
|
212
|
-
"
|
213
|
+
"segments" => nil
|
213
214
|
},
|
214
215
|
},
|
215
216
|
"meta" => {
|
@@ -217,11 +218,11 @@ module ForestLiana
|
|
217
218
|
}
|
218
219
|
}
|
219
220
|
}
|
220
|
-
let(:
|
221
|
+
let(:api_permissions_rendering_only) {
|
221
222
|
{
|
222
223
|
"data" => {
|
223
224
|
'collections' => { },
|
224
|
-
'renderings' =>
|
225
|
+
'renderings' => segments_permissions
|
225
226
|
},
|
226
227
|
"meta" => {
|
227
228
|
"rolesACLActivated" => false
|
@@ -233,13 +234,13 @@ module ForestLiana
|
|
233
234
|
# clones is called to duplicate the returned value and not use to same (which results in an error
|
234
235
|
# as the permissions is edited through the formatter)
|
235
236
|
allow(ForestLiana::PermissionsGetter).to receive(:get_permissions_for_rendering).with(rendering_id) { api_permissions.clone }
|
236
|
-
allow(ForestLiana::PermissionsGetter).to receive(:get_permissions_for_rendering).with(rendering_id, rendering_specific_only: true).and_return(
|
237
|
+
allow(ForestLiana::PermissionsGetter).to receive(:get_permissions_for_rendering).with(rendering_id, rendering_specific_only: true).and_return(api_permissions_rendering_only)
|
237
238
|
end
|
238
239
|
|
239
240
|
context 'when checking once for authorization' do
|
240
241
|
context 'when checking browseEnabled' do
|
241
242
|
context 'when expiration value is set to its default' do
|
242
|
-
it 'should not call the API to refresh the
|
243
|
+
it 'should not call the API to refresh the renderings cache' do
|
243
244
|
described_class.new(fake_ressource, 'browseEnabled', rendering_id, user_id: user_id).is_authorized?
|
244
245
|
|
245
246
|
expect(ForestLiana::PermissionsGetter).to have_received(:get_permissions_for_rendering).with(rendering_id).once
|
@@ -254,7 +255,7 @@ module ForestLiana
|
|
254
255
|
described_class.empty_cache
|
255
256
|
end
|
256
257
|
|
257
|
-
it 'should call the API to refresh the
|
258
|
+
it 'should call the API to refresh the renderings cache' do
|
258
259
|
described_class.new(fake_ressource, 'browseEnabled', rendering_id, user_id: user_id).is_authorized?
|
259
260
|
|
260
261
|
expect(ForestLiana::PermissionsGetter).to have_received(:get_permissions_for_rendering).with(rendering_id).once
|
@@ -263,7 +264,7 @@ module ForestLiana
|
|
263
264
|
end
|
264
265
|
end
|
265
266
|
|
266
|
-
# Only browse permission requires
|
267
|
+
# Only browse permission requires segments
|
267
268
|
context 'when checking exportEnabled' do
|
268
269
|
context 'when expiration value is set in the past' do
|
269
270
|
before do
|
@@ -273,7 +274,7 @@ module ForestLiana
|
|
273
274
|
end
|
274
275
|
end
|
275
276
|
|
276
|
-
it 'should NOT call the API to refresh the
|
277
|
+
it 'should NOT call the API to refresh the renderings cache' do
|
277
278
|
described_class.new(fake_ressource, 'exportEnabled', rendering_id, user_id: user_id).is_authorized?
|
278
279
|
|
279
280
|
expect(ForestLiana::PermissionsGetter).to have_received(:get_permissions_for_rendering).with(rendering_id).once
|
@@ -284,8 +285,8 @@ module ForestLiana
|
|
284
285
|
|
285
286
|
context 'when checking twice for authorization' do
|
286
287
|
context 'on the same rendering' do
|
287
|
-
context 'when
|
288
|
-
it 'should NOT call the API to refresh the
|
288
|
+
context 'when renderings permission has NOT expired' do
|
289
|
+
it 'should NOT call the API to refresh the renderings permissions' do
|
289
290
|
described_class.new(fake_ressource, 'browseEnabled', rendering_id, user_id: user_id).is_authorized?
|
290
291
|
described_class.new(fake_ressource, 'browseEnabled', rendering_id, user_id: user_id).is_authorized?
|
291
292
|
|
@@ -294,14 +295,14 @@ module ForestLiana
|
|
294
295
|
end
|
295
296
|
end
|
296
297
|
|
297
|
-
context 'when
|
298
|
+
context 'when renderings permission has expired' do
|
298
299
|
before do
|
299
300
|
allow(ENV).to receive(:[]).with('FOREST_PERMISSIONS_EXPIRATION_IN_SECONDS').and_return('-1')
|
300
301
|
# Needed to enforce ENV stub
|
301
302
|
described_class.empty_cache
|
302
303
|
end
|
303
304
|
|
304
|
-
it 'should call the API to refresh the
|
305
|
+
it 'should call the API to refresh the renderings permissions' do
|
305
306
|
described_class.new(fake_ressource, 'browseEnabled', rendering_id, user_id: user_id).is_authorized?
|
306
307
|
described_class.new(fake_ressource, 'browseEnabled', rendering_id, user_id: user_id).is_authorized?
|
307
308
|
|
@@ -313,7 +314,7 @@ module ForestLiana
|
|
313
314
|
|
314
315
|
context 'on two different renderings' do
|
315
316
|
let(:other_rendering_id) { 2 }
|
316
|
-
let(:
|
317
|
+
let(:api_permissions_rendering_only) {
|
317
318
|
{
|
318
319
|
"data" => {
|
319
320
|
'collections' => { },
|
@@ -330,10 +331,10 @@ module ForestLiana
|
|
330
331
|
|
331
332
|
before do
|
332
333
|
allow(ForestLiana::PermissionsGetter).to receive(:get_permissions_for_rendering).with(other_rendering_id).and_return(api_permissions_copy)
|
333
|
-
allow(ForestLiana::PermissionsGetter).to receive(:get_permissions_for_rendering).with(other_rendering_id, rendering_specific_only: true).and_return(
|
334
|
+
allow(ForestLiana::PermissionsGetter).to receive(:get_permissions_for_rendering).with(other_rendering_id, rendering_specific_only: true).and_return(api_permissions_rendering_only)
|
334
335
|
end
|
335
336
|
|
336
|
-
it 'should not call the API to refresh the
|
337
|
+
it 'should not call the API to refresh the rederings permissions' do
|
337
338
|
described_class.new(fake_ressource, 'browseEnabled', rendering_id, user_id: user_id).is_authorized?
|
338
339
|
described_class.new(fake_ressource, 'browseEnabled', other_rendering_id, user_id: user_id).is_authorized?
|
339
340
|
|
@@ -350,7 +351,7 @@ module ForestLiana
|
|
350
351
|
# Resource is only used to retrieve the collection name as it's stubbed it does not
|
351
352
|
# need to be defined
|
352
353
|
let(:fake_ressource) { collection_name }
|
353
|
-
let(:default_rendering_id) {
|
354
|
+
let(:default_rendering_id) { 1 }
|
354
355
|
let(:api_permissions) { default_api_permissions }
|
355
356
|
let(:collection_name) { 'all_rights_collection' }
|
356
357
|
|
@@ -380,14 +381,14 @@ module ForestLiana
|
|
380
381
|
describe 'browseEnabled permission' do
|
381
382
|
let(:collection_name) { 'custom' }
|
382
383
|
subject { described_class.new(fake_ressource, 'browseEnabled', default_rendering_id, user_id: user_id) }
|
383
|
-
let(:
|
384
|
+
let(:segments_permissions) { nil }
|
384
385
|
let(:default_api_permissions) {
|
385
386
|
{
|
386
387
|
"data" => {
|
387
388
|
"custom" => {
|
388
389
|
"collection" => collection_permissions,
|
389
390
|
"actions" => { },
|
390
|
-
"
|
391
|
+
"segments" => segments_permissions
|
391
392
|
},
|
392
393
|
},
|
393
394
|
"meta" => {
|
@@ -480,6 +481,26 @@ module ForestLiana
|
|
480
481
|
end
|
481
482
|
end
|
482
483
|
|
484
|
+
context 'when segments are defined' do
|
485
|
+
let(:segments_permissions) { ['SELECT * FROM products;', 'SELECT * FROM sellers;'] }
|
486
|
+
let(:collection_list_parameters) { { :user_id => "1", :segmentQuery => segmentQuery } }
|
487
|
+
|
488
|
+
context 'when segments are passing validation' do
|
489
|
+
let(:segmentQuery) { 'SELECT * FROM products;' }
|
490
|
+
it 'should return true' do
|
491
|
+
expect(subject.is_authorized?).to be true
|
492
|
+
end
|
493
|
+
end
|
494
|
+
|
495
|
+
context 'when segments are NOT passing validation' do
|
496
|
+
let(:segmentQuery) { 'SELECT * FROM rockets WHERE name = "Starship";' }
|
497
|
+
it 'should return false' do
|
498
|
+
expect(subject.is_authorized?).to be false
|
499
|
+
end
|
500
|
+
end
|
501
|
+
|
502
|
+
end
|
503
|
+
|
483
504
|
context 'when user has not the required permission' do
|
484
505
|
let(:collection_permissions) {
|
485
506
|
{
|
@@ -497,53 +518,6 @@ module ForestLiana
|
|
497
518
|
expect(subject.is_authorized?).to be false
|
498
519
|
end
|
499
520
|
end
|
500
|
-
|
501
|
-
context 'when scopes are defined' do
|
502
|
-
let(:scope_permissions) { { 'dynamicScopesValues' => {}, 'filter' => { 'aggregator' => 'and', 'conditions' => [condition] } }}
|
503
|
-
let(:collection_list_parameters) { { :user_id => "1", :filters => JSON.generate(condition) } }
|
504
|
-
|
505
|
-
context 'when scopes are passing validation' do
|
506
|
-
context 'when scope value is a string' do
|
507
|
-
let(:condition) { { 'field' => 'field_1', 'operator' => 'equal', 'value' => true } }
|
508
|
-
|
509
|
-
it 'should return true' do
|
510
|
-
expect(subject.is_authorized?).to be true
|
511
|
-
end
|
512
|
-
end
|
513
|
-
|
514
|
-
context 'when scope value is a boolean' do
|
515
|
-
let(:condition) { { 'field' => 'field_1', 'operator' => 'equal', 'value' => 'true' } }
|
516
|
-
|
517
|
-
it 'should return true' do
|
518
|
-
expect(subject.is_authorized?).to be true
|
519
|
-
end
|
520
|
-
end
|
521
|
-
end
|
522
|
-
|
523
|
-
context 'when scopes are NOT passing validation' do
|
524
|
-
let(:condition) { { 'field' => 'field_1', 'operator' => 'equal', 'value' => true } }
|
525
|
-
let(:other_condition) {
|
526
|
-
{
|
527
|
-
aggregator: 'and',
|
528
|
-
conditions: [
|
529
|
-
{ field: 'name', value: 'john', operator: 'equal' },
|
530
|
-
{ field: 'price', value: '2500', operator: 'equal' }
|
531
|
-
]
|
532
|
-
}
|
533
|
-
}
|
534
|
-
let(:collection_list_parameters) {
|
535
|
-
{
|
536
|
-
:user_id => "1",
|
537
|
-
:filters => JSON.generate(other_condition)
|
538
|
-
}
|
539
|
-
}
|
540
|
-
|
541
|
-
|
542
|
-
it 'should return false' do
|
543
|
-
expect(subject.is_authorized?).to be false
|
544
|
-
end
|
545
|
-
end
|
546
|
-
end
|
547
521
|
end
|
548
522
|
end
|
549
523
|
|
@@ -50,7 +50,8 @@ module ForestLiana
|
|
50
50
|
})
|
51
51
|
]
|
52
52
|
}
|
53
|
-
let(:
|
53
|
+
let(:default_rendering_id) { 1 }
|
54
|
+
let(:segments_permissions) { { default_rendering_id => { 'segments' => nil } } }
|
54
55
|
let(:default_api_permissions) {
|
55
56
|
{
|
56
57
|
"data" => {
|
@@ -116,14 +117,16 @@ module ForestLiana
|
|
116
117
|
}
|
117
118
|
},
|
118
119
|
},
|
119
|
-
'renderings' =>
|
120
|
+
'renderings' => segments_permissions
|
121
|
+
},
|
122
|
+
"stats" => {
|
123
|
+
"queries"=>[],
|
120
124
|
},
|
121
125
|
"meta" => {
|
122
126
|
"rolesACLActivated" => true
|
123
127
|
}
|
124
128
|
}
|
125
129
|
}
|
126
|
-
let(:default_rendering_id) { 1 }
|
127
130
|
|
128
131
|
before do
|
129
132
|
allow(ForestLiana).to receive(:apimap).and_return(schema)
|
@@ -174,7 +177,7 @@ module ForestLiana
|
|
174
177
|
end
|
175
178
|
|
176
179
|
let(:collection_name) { 'custom' }
|
177
|
-
let(:
|
180
|
+
let(:segments_permissions) { { default_rendering_id => { 'custom' => nil }, 2 => { 'custom' => nil } } }
|
178
181
|
let(:api_permissions_rendering_1) {
|
179
182
|
{
|
180
183
|
"data" => {
|
@@ -191,7 +194,7 @@ module ForestLiana
|
|
191
194
|
"actions" => { }
|
192
195
|
},
|
193
196
|
},
|
194
|
-
'renderings' =>
|
197
|
+
'renderings' => segments_permissions
|
195
198
|
},
|
196
199
|
"meta" => {
|
197
200
|
"rolesACLActivated" => true
|
@@ -242,10 +245,10 @@ module ForestLiana
|
|
242
245
|
end
|
243
246
|
end
|
244
247
|
|
245
|
-
context '
|
248
|
+
context 'renderings cache' do
|
246
249
|
let(:rendering_id) { 1 }
|
247
250
|
let(:collection_name) { 'custom' }
|
248
|
-
let(:
|
251
|
+
let(:segments_permissions) { { rendering_id => { 'custom' => nil } } }
|
249
252
|
let(:api_permissions) {
|
250
253
|
{
|
251
254
|
"data" => {
|
@@ -262,18 +265,18 @@ module ForestLiana
|
|
262
265
|
"actions" => { }
|
263
266
|
},
|
264
267
|
},
|
265
|
-
'renderings' =>
|
268
|
+
'renderings' => segments_permissions
|
266
269
|
},
|
267
270
|
"meta" => {
|
268
271
|
"rolesACLActivated" => true
|
269
272
|
}
|
270
273
|
}
|
271
274
|
}
|
272
|
-
let(:
|
275
|
+
let(:api_permissions_rendering_only) {
|
273
276
|
{
|
274
277
|
"data" => {
|
275
278
|
'collections' => { },
|
276
|
-
'renderings' =>
|
279
|
+
'renderings' => segments_permissions
|
277
280
|
},
|
278
281
|
"meta" => {
|
279
282
|
"rolesACLActivated" => true
|
@@ -283,13 +286,13 @@ module ForestLiana
|
|
283
286
|
|
284
287
|
before do
|
285
288
|
allow(ForestLiana::PermissionsGetter).to receive(:get_permissions_for_rendering).with(rendering_id).and_return(api_permissions)
|
286
|
-
allow(ForestLiana::PermissionsGetter).to receive(:get_permissions_for_rendering).with(rendering_id, rendering_specific_only: true).and_return(
|
289
|
+
allow(ForestLiana::PermissionsGetter).to receive(:get_permissions_for_rendering).with(rendering_id, rendering_specific_only: true).and_return(api_permissions_rendering_only)
|
287
290
|
end
|
288
291
|
|
289
292
|
context 'when checking once for authorization' do
|
290
293
|
context 'when checking browseEnabled' do
|
291
294
|
context 'when expiration value is set to its default' do
|
292
|
-
it 'should not call the API to refresh the
|
295
|
+
it 'should not call the API to refresh the renderings cache' do
|
293
296
|
described_class.new(fake_ressource, 'browseEnabled', rendering_id, user_id: user_id).is_authorized?
|
294
297
|
|
295
298
|
expect(ForestLiana::PermissionsGetter).to have_received(:get_permissions_for_rendering).with(rendering_id).once
|
@@ -304,7 +307,7 @@ module ForestLiana
|
|
304
307
|
described_class.empty_cache
|
305
308
|
end
|
306
309
|
|
307
|
-
it 'should call the API to refresh the
|
310
|
+
it 'should call the API to refresh the renderings cache' do
|
308
311
|
described_class.new(fake_ressource, 'browseEnabled', rendering_id, user_id: user_id).is_authorized?
|
309
312
|
|
310
313
|
expect(ForestLiana::PermissionsGetter).to have_received(:get_permissions_for_rendering).with(rendering_id).once
|
@@ -313,7 +316,7 @@ module ForestLiana
|
|
313
316
|
end
|
314
317
|
end
|
315
318
|
|
316
|
-
# Only browse permission requires
|
319
|
+
# Only browse permission requires segments
|
317
320
|
context 'when checking exportEnabled' do
|
318
321
|
context 'when expiration value is set in the past' do
|
319
322
|
before do
|
@@ -323,7 +326,7 @@ module ForestLiana
|
|
323
326
|
end
|
324
327
|
end
|
325
328
|
|
326
|
-
it 'should NOT call the API to refresh the
|
329
|
+
it 'should NOT call the API to refresh the rendering cache' do
|
327
330
|
described_class.new(fake_ressource, 'exportEnabled', rendering_id, user_id: user_id).is_authorized?
|
328
331
|
|
329
332
|
expect(ForestLiana::PermissionsGetter).to have_received(:get_permissions_for_rendering).with(rendering_id).once
|
@@ -334,8 +337,8 @@ module ForestLiana
|
|
334
337
|
|
335
338
|
context 'when checking twice for authorization' do
|
336
339
|
context 'on the same rendering' do
|
337
|
-
context 'when
|
338
|
-
it 'should NOT call the API to refresh the
|
340
|
+
context 'when rendering permission has NOT expired' do
|
341
|
+
it 'should NOT call the API to refresh the rendering permissions' do
|
339
342
|
described_class.new(fake_ressource, 'browseEnabled', rendering_id, user_id: user_id).is_authorized?
|
340
343
|
described_class.new(fake_ressource, 'browseEnabled', rendering_id, user_id: user_id).is_authorized?
|
341
344
|
|
@@ -344,14 +347,14 @@ module ForestLiana
|
|
344
347
|
end
|
345
348
|
end
|
346
349
|
|
347
|
-
context 'when
|
350
|
+
context 'when renderings permission has expired' do
|
348
351
|
before do
|
349
352
|
allow(ENV).to receive(:[]).with('FOREST_PERMISSIONS_EXPIRATION_IN_SECONDS').and_return('-1')
|
350
353
|
# Needed to enforce ENV stub
|
351
354
|
described_class.empty_cache
|
352
355
|
end
|
353
356
|
|
354
|
-
it 'should call the API to refresh the
|
357
|
+
it 'should call the API to refresh the rendering permissions' do
|
355
358
|
described_class.new(fake_ressource, 'browseEnabled', rendering_id, user_id: user_id).is_authorized?
|
356
359
|
described_class.new(fake_ressource, 'browseEnabled', rendering_id, user_id: user_id).is_authorized?
|
357
360
|
|
@@ -363,14 +366,17 @@ module ForestLiana
|
|
363
366
|
|
364
367
|
context 'on two different renderings' do
|
365
368
|
let(:other_rendering_id) { 2 }
|
366
|
-
let(:
|
369
|
+
let(:api_permissions_rendering_only) {
|
367
370
|
{
|
368
371
|
"data" => {
|
369
372
|
'collections' => { },
|
370
373
|
'renderings' => {
|
371
|
-
|
374
|
+
other_rendering_id => { 'custom' => nil }
|
372
375
|
}
|
373
376
|
},
|
377
|
+
"stats" => {
|
378
|
+
"somestats" => [],
|
379
|
+
},
|
374
380
|
"meta" => {
|
375
381
|
"rolesACLActivated" => true
|
376
382
|
}
|
@@ -378,10 +384,10 @@ module ForestLiana
|
|
378
384
|
}
|
379
385
|
|
380
386
|
before do
|
381
|
-
allow(ForestLiana::PermissionsGetter).to receive(:get_permissions_for_rendering).with(other_rendering_id, rendering_specific_only: true).and_return(
|
387
|
+
allow(ForestLiana::PermissionsGetter).to receive(:get_permissions_for_rendering).with(other_rendering_id, rendering_specific_only: true).and_return(api_permissions_rendering_only)
|
382
388
|
end
|
383
389
|
|
384
|
-
it 'should call the API to refresh the
|
390
|
+
it 'should call the API to refresh the rendering permissions' do
|
385
391
|
described_class.new(fake_ressource, 'browseEnabled', rendering_id, user_id: user_id).is_authorized?
|
386
392
|
described_class.new(fake_ressource, 'browseEnabled', other_rendering_id, user_id: user_id).is_authorized?
|
387
393
|
|
@@ -452,58 +458,28 @@ module ForestLiana
|
|
452
458
|
end
|
453
459
|
end
|
454
460
|
|
455
|
-
context 'when
|
461
|
+
context 'when segments are defined' do
|
456
462
|
let(:default_rendering_id) { 1 }
|
457
|
-
let(:
|
463
|
+
let(:segments_permissions) {
|
458
464
|
{
|
459
465
|
default_rendering_id => {
|
460
466
|
collection_name => {
|
461
|
-
'
|
462
|
-
'dynamicScopesValues' => {},
|
463
|
-
'filter' => { 'aggregator' => 'and', 'conditions' => [condition] }
|
464
|
-
}
|
467
|
+
'segments' => ['SELECT * FROM products;', 'SELECT * FROM sellers;']
|
465
468
|
}
|
466
469
|
}
|
467
470
|
}
|
468
471
|
}
|
469
|
-
let(:collection_list_parameters) { { :user_id => "1", :
|
472
|
+
let(:collection_list_parameters) { { :user_id => "1", :segmentQuery => segmentQuery } }
|
470
473
|
|
471
|
-
context 'when
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
it 'should return true' do
|
476
|
-
expect(subject.is_authorized?).to be true
|
477
|
-
end
|
478
|
-
end
|
479
|
-
|
480
|
-
context 'when scope value is a boolean' do
|
481
|
-
let(:condition) { { 'field' => 'field_1', 'operator' => 'equal', 'value' => 'true' } }
|
482
|
-
|
483
|
-
it 'should return true' do
|
484
|
-
expect(subject.is_authorized?).to be true
|
485
|
-
end
|
474
|
+
context 'when segments are passing validation' do
|
475
|
+
let(:segmentQuery) { 'SELECT * FROM products;' }
|
476
|
+
it 'should return true' do
|
477
|
+
expect(subject.is_authorized?).to be true
|
486
478
|
end
|
487
479
|
end
|
488
480
|
|
489
|
-
context 'when
|
490
|
-
let(:
|
491
|
-
let(:other_condition) {
|
492
|
-
{
|
493
|
-
aggregator: 'and',
|
494
|
-
conditions: [
|
495
|
-
{ field: 'name', value: 'john', operator: 'equal' },
|
496
|
-
{ field: 'price', value: '2500', operator: 'equal' }
|
497
|
-
]
|
498
|
-
}
|
499
|
-
}
|
500
|
-
let(:collection_list_parameters) {
|
501
|
-
{
|
502
|
-
:user_id => "1",
|
503
|
-
:filters => JSON.generate(other_condition)
|
504
|
-
}
|
505
|
-
}
|
506
|
-
|
481
|
+
context 'when segments are NOT passing validation' do
|
482
|
+
let(:segmentQuery) { 'SELECT * FROM rockets WHERE name = "Starship";' }
|
507
483
|
it 'should return false' do
|
508
484
|
expect(subject.is_authorized?).to be false
|
509
485
|
end
|