Skip to content

Commit ef706ee

Browse files
fix(permission): fix chart permissions to work properly with multiple filter conditions (#666)
1 parent de19cdd commit ef706ee

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
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: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'json'
33

44
describe "Stats", type: :request do
5-
let(:rendering_id) { 13 }
5+
let(:rendering_id) { '13' }
66
let(:scopes) { {'scopes' => {}, 'team' => {'id' => '1', 'name' => 'Operations'}} }
77
let(:schema) {
88
[
@@ -23,7 +23,7 @@
2323
team: 'Operations',
2424
rendering_id: rendering_id,
2525
exp: Time.now.to_i + 2.weeks.to_i,
26-
permission_level: 'admin'
26+
permission_level: 'user'
2727
}, ForestLiana.auth_secret, 'HS256')
2828
}
2929

@@ -38,7 +38,7 @@
3838
before do
3939
Rails.cache.write('forest.users', {'1' => { 'id' => 1, 'roleId' => 1, 'rendering_id' => '1' }})
4040
Rails.cache.write('forest.has_permission', true)
41-
allow_any_instance_of(ForestLiana::Ability::Fetch)
41+
allow_any_instance_of(ForestLiana::Ability::Permission)
4242
.to receive(:get_permissions)
4343
.and_return(
4444
{
@@ -50,6 +50,31 @@
5050
"aggregateFieldName" => nil,
5151
"sourceCollectionName" => "Owner"
5252
},
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+
},
5378
{
5479
"type" => "Value",
5580
"query" => "SELECT COUNT(*) AS value FROM products;"

0 commit comments

Comments
 (0)