@@ -251,34 +251,41 @@ def parse_filters(filters)
251251 end
252252
253253 filters . each do |key , value |
254- filter_method , included_resource_name =
255- key . to_s . split ( '.' ) . map { |k | unformat_key ( k ) } . reverse
256254
257- if included_resource_name
258- relationship = resource_klass . _relationship ( included_resource_name || '' )
255+ unformatted_key = unformat_key ( key )
256+ if resource_klass . _allowed_filter? ( unformatted_key )
257+ @filters [ unformatted_key ] = value
258+ elsif unformatted_key . to_s . include? ( '.' )
259+ parse_relationship_filter ( unformatted_key , value )
260+ else
261+ return @errors . concat ( Exceptions ::FilterNotAllowed . new ( unformatted_key ) . errors )
262+ end
263+ end
264+ end
259265
260- unless relationship
261- return @errors . concat ( Exceptions :: FilterNotAllowed . new ( filter_method ) . errors )
262- end
266+ def parse_relationship_filter ( key , value )
267+ included_resource_name , filter_method = key . to_s . split ( '.' )
268+ filter_method = filter_method . to_sym if filter_method . present?
263269
264- unless relationship . resource_klass . _allowed_filter? ( filter_method )
265- return @errors . concat ( Exceptions ::FilterNotAllowed . new ( filter_method ) . errors )
266- end
270+ if included_resource_name
271+ relationship = resource_klass . _relationship ( included_resource_name || '' )
267272
268- unless @include_directives &. include_config ( relationship . name . to_sym ) . present?
269- return @errors . concat ( Exceptions ::FilterNotAllowed . new ( filter_method ) . errors )
270- end
273+ unless relationship
274+ return @errors . concat ( Exceptions ::FilterNotAllowed . new ( filter_method ) . errors )
275+ end
271276
272- verified_filter = relationship . resource_klass . verify_filters ( filter_method => value )
273- @include_directives . merge_filter ( relationship . name , verified_filter )
274- next
275- else
276- unless resource_klass . _allowed_filter? ( filter_method )
277- return @errors . concat ( Exceptions ::FilterNotAllowed . new ( filter_method ) . errors )
278- end
277+ unless relationship . resource_klass . _allowed_filter? ( filter_method )
278+ return @errors . concat ( Exceptions ::FilterNotAllowed . new ( filter_method ) . errors )
279+ end
279280
280- @filters [ filter_method ] = value
281+ unless @include_directives . try ( :include_config , relationship . name . to_sym ) . present?
282+ return @errors . concat ( Exceptions ::FilterNotAllowed . new ( filter_method ) . errors )
281283 end
284+
285+ verified_filter = relationship . resource_klass . verify_filters ( filter_method => value )
286+ @include_directives . merge_filter ( relationship . name , verified_filter )
287+ else
288+ return @errors . concat ( Exceptions ::FilterNotAllowed . new ( filter_method ) . errors )
282289 end
283290 end
284291
0 commit comments