fastapi 0.1.17 → 0.1.18
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/lib/fastapi.rb +18 -2
- data/lib/fastapi/active_record_extension.rb +4 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 914c5c91b0fd3b9f2b81b4da4d27554b05d254a5
|
4
|
+
data.tar.gz: ee22069497c8ba7c7704f60bbaf8a94af1df8ce2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 267c4b35d3474ac545f24683baa22e7e4d1012de69c4cfb7d7dad20213d59a6a0816d2c951ed9db18f80d96da1c6e192a8168dbbaf1d4870c3f82fa702040083
|
7
|
+
data.tar.gz: 57fbf90fa9d58518b669aa95acec4f9b3904199e3c24609c8e0a9b0bd02e45d2fe87b10b88281302fec53e9035fc9cf9f205d009e8a9128ee81eeadc674cedb7
|
data/lib/fastapi.rb
CHANGED
@@ -28,12 +28,24 @@ class FastAPI
|
|
28
28
|
@data = nil
|
29
29
|
@metadata = nil
|
30
30
|
@result_type = 0
|
31
|
+
@whitelist_fields = []
|
31
32
|
end
|
32
33
|
|
33
34
|
def inspect
|
34
35
|
"<#{self.class}: #{@model}>"
|
35
36
|
end
|
36
37
|
|
38
|
+
# Create and execute an optimized SQL query based on specified filters
|
39
|
+
#
|
40
|
+
# @param fields [Array] an array containing fields to whitelist for the SQL query
|
41
|
+
# @return [FastAPI] the current instance
|
42
|
+
def whitelist(fields = [])
|
43
|
+
|
44
|
+
@whitelist_fields.concat fields
|
45
|
+
|
46
|
+
self
|
47
|
+
|
48
|
+
end
|
37
49
|
|
38
50
|
# Create and execute an optimized SQL query based on specified filters
|
39
51
|
#
|
@@ -516,7 +528,7 @@ class FastAPI
|
|
516
528
|
filters.each do |key, value|
|
517
529
|
found_index = key.to_s.rindex('__')
|
518
530
|
key_root = found_index.nil? ? key : key.to_s[0...found_index].to_sym
|
519
|
-
if not [:__order, :__offset, :__count].include? key and not self_obj.
|
531
|
+
if not [:__order, :__offset, :__count].include? key and not self_obj.fastapi_filters_whitelist.include? key_root
|
520
532
|
raise 'Filter "' + key.to_s + '" not supported'
|
521
533
|
end
|
522
534
|
end
|
@@ -758,7 +770,11 @@ class FastAPI
|
|
758
770
|
|
759
771
|
model_lookup = {}
|
760
772
|
|
761
|
-
|
773
|
+
filter_fields = []
|
774
|
+
filter_fields.concat @model.fastapi_fields
|
775
|
+
filter_fields.concat @whitelist_fields
|
776
|
+
|
777
|
+
filter_fields.each do |field|
|
762
778
|
|
763
779
|
if (@model.reflect_on_all_associations(:belongs_to).map(&:name).include? field or
|
764
780
|
@model.reflect_on_all_associations(:has_one).map(&:name).include? field)
|
@@ -23,11 +23,12 @@ module FastAPIExtension
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# Set safe fields for FastAPIInstance.safe_filter
|
26
|
+
# These are the fields that can be actively filtered by
|
26
27
|
#
|
27
28
|
# @param fields [Array] a list of fields in the form of symbols
|
28
29
|
# @return [Array] the same array of fields
|
29
30
|
def fastapi_safe_fields(fields)
|
30
|
-
@
|
31
|
+
@fastapi_filters_whitelist = fields
|
31
32
|
end
|
32
33
|
|
33
34
|
# Used to set any default filters for the top level fastapi response
|
@@ -58,8 +59,8 @@ module FastAPIExtension
|
|
58
59
|
@fastapi_fields_sub or [:id]
|
59
60
|
end
|
60
61
|
|
61
|
-
def
|
62
|
-
@
|
62
|
+
def fastapi_filters_whitelist
|
63
|
+
@fastapi_filters_whitelist or @fastapi_fields or [:id]
|
63
64
|
end
|
64
65
|
|
65
66
|
def fastapi_filters
|