Skip to content

Commit 50663e9

Browse files
authored
fix: distribution charts using groupby on a relationship should not throws 403 Forbidden (#459)
* fix: charts should no longer throws 403 forbidden when not needed * fix: distribution charts using groupby on a relationship throws 403 Forbidden
1 parent fb0645e commit 50663e9

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

app/controllers/forest_liana/stats_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ def get_stat_parameter_request_info
8989
parameters.delete('controller');
9090
parameters.delete('action');
9191

92+
# NOTICE: Remove the field information from group_by_field => collection:id
93+
if parameters['group_by_field']
94+
parameters['group_by_field'] = parameters['group_by_field'].split(':').first
95+
end
96+
9297
return parameters;
9398
end
9499

app/services/forest_liana/permissions_checker.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,12 @@ def stat_with_parameters_allowed?
177177
return false unless pool_permissions
178178

179179
# NOTICE: equivalent to Object.values in js & removes nil values
180-
array_query_request_info = @query_request_info.values.filter_map{ |x| x unless x.nil? }
180+
array_permission_infos = @query_request_info.values.filter_map{ |x| x unless x.nil? }
181181

182-
# NOTICE: pool_permissions contains the @query_request_info
183-
# we use the intersection between statPermission and @query_request_info
182+
# NOTICE: Is there any pool_permissions containing the array_permission_infos
184183
return pool_permissions.any? {
185184
|statPermission|
186-
(array_query_request_info & statPermission.values) == array_query_request_info;
185+
(array_permission_infos.all? { |info| statPermission.values.include?(info) });
187186
}
188187
end
189188

spec/requests/stats_spec.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@
7272
expect(response.status).to eq(404)
7373
end
7474

75-
# it 'should respond 403 Forbidden' do
76-
# allow_any_instance_of(ForestLiana::PermissionsChecker).to receive(:is_authorized?) { false }
75+
it 'should respond 403 Forbidden' do
76+
allow_any_instance_of(ForestLiana::PermissionsChecker).to receive(:is_authorized?) { false }
77+
# NOTICE: bypass : find_resource error
78+
allow_any_instance_of(ForestLiana::StatsController).to receive(:find_resource) { true }
7779

78-
# post '/forest/stats/Products', params: JSON.dump(params), headers: headers
79-
# expect(response.status).to eq(403)
80-
# end
80+
post '/forest/stats/Products', params: JSON.dump(params), headers: headers
81+
expect(response.status).to eq(403)
82+
end
8183
end
8284

8385
describe 'POST /stats' do

0 commit comments

Comments
 (0)