Skip to content

Commit 4a85679

Browse files
fix(permission): fix chart permissions to work properly with multiple filter on 8.x.x (#667)
1 parent c32e24e commit 4a85679

File tree

2 files changed

+53
-27
lines changed

2 files changed

+53
-27
lines changed

app/services/forest_liana/ability/permission.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def get_chart_data(rendering_id, force_fetch = false)
9797
Rails.cache.fetch('forest.stats', expires_in: TTL) do
9898
stat_hash = []
9999
get_permissions('/liana/v4/permissions/renderings/' + rendering_id)['stats'].each do |stat|
100-
stat_hash << "#{stat['type']}:#{Digest::SHA1.hexdigest(stat.sort.to_h.to_s)}"
100+
stat_hash << "#{stat['type']}:#{Digest::SHA1.hexdigest(stat.deep_sort.to_s)}"
101101
end
102102

103103
stat_hash

spec/requests/stats_spec.rb

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,8 @@
22
require 'json'
33

44
describe "Stats", type: :request do
5-
6-
token = JWT.encode({
7-
id: 1,
8-
9-
first_name: 'Michael',
10-
last_name: 'Kelso',
11-
team: 'Operations',
12-
rendering_id: '1',
13-
exp: Time.now.to_i + 2.weeks.to_i,
14-
permission_level: 'admin'
15-
}, ForestLiana.auth_secret, 'HS256')
16-
17-
headers = {
18-
'Accept' => 'application/json',
19-
'Content-Type' => 'application/json',
20-
'Authorization' => "Bearer #{token}"
21-
}
22-
5+
let(:rendering_id) { '13' }
6+
let(:scopes) { {'scopes' => {}, 'team' => {'id' => '1', 'name' => 'Operations'}} }
237
let(:schema) {
248
[
259
ForestLiana::Model::Collection.new({
@@ -30,10 +14,31 @@
3014
]
3115
}
3216

17+
let(:token) {
18+
JWT.encode({
19+
id: 1,
20+
21+
first_name: 'Michael',
22+
last_name: 'Kelso',
23+
team: 'Operations',
24+
rendering_id: rendering_id,
25+
exp: Time.now.to_i + 2.weeks.to_i,
26+
permission_level: 'user'
27+
}, ForestLiana.auth_secret, 'HS256')
28+
}
29+
30+
let(:headers) {
31+
{
32+
'Accept' => 'application/json',
33+
'Content-Type' => 'application/json',
34+
'Authorization' => "Bearer #{token}"
35+
}
36+
}
37+
3338
before do
3439
Rails.cache.write('forest.users', {'1' => { 'id' => 1, 'roleId' => 1, 'rendering_id' => '1' }})
3540
Rails.cache.write('forest.has_permission', true)
36-
allow_any_instance_of(ForestLiana::Ability::Fetch)
41+
allow_any_instance_of(ForestLiana::Ability::Permission)
3742
.to receive(:get_permissions)
3843
.and_return(
3944
{
@@ -45,6 +50,31 @@
4550
"aggregateFieldName" => nil,
4651
"sourceCollectionName" => "Owner"
4752
},
53+
{
54+
"type" => "Objective",
55+
"sourceCollectionName" => "Owner",
56+
"aggregateFieldName" => nil,
57+
"aggregator" => "Count",
58+
"objective" => 200,
59+
"filter" => nil,
60+
},
61+
{
62+
"type" => "Pie",
63+
"sourceCollectionName" => "Owner",
64+
"aggregateFieldName" => nil,
65+
"groupByFieldName" => "id",
66+
"aggregator" => "Count",
67+
"filter" => nil,
68+
},
69+
{
70+
"type" => "Line",
71+
"sourceCollectionName" => "Owner",
72+
"aggregateFieldName" => nil,
73+
"groupByFieldName" => "hired_at",
74+
"aggregator" => "Count",
75+
"timeRange" => "Week",
76+
"filter" => nil,
77+
},
4878
{
4979
"type" => "Value",
5080
"query" => "SELECT COUNT(*) AS value FROM products;"
@@ -53,13 +83,9 @@
5383
}
5484
)
5585

56-
ForestLiana::ScopeManager.class_variable_set(:@@scopes_cache, {
57-
'1' => {
58-
:fetched_at => Time.now,
59-
:scopes => {}
60-
}
61-
})
62-
86+
ForestLiana::ScopeManager.invalidate_scope_cache(rendering_id)
87+
allow(ForestLiana::ScopeManager).to receive(:fetch_scopes).and_return(scopes)
88+
6389
allow(ForestLiana).to receive(:apimap).and_return(schema)
6490
allow(ForestLiana::IpWhitelist).to receive(:retrieve) { true }
6591
allow(ForestLiana::IpWhitelist).to receive(:is_ip_whitelist_retrieved) { true }

0 commit comments

Comments
 (0)