rest_framework 0.8.11 → 0.8.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rest_framework/controller_mixins/models.rb +3 -2
- data/lib/rest_framework/filters.rb +5 -7
- data/lib/rest_framework/utils.rb +5 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e6db6727ad85819540fc9d5977205f553523fe2f1f4431c985193ffd47f27bc
|
4
|
+
data.tar.gz: cddc4ff0d75aa6d2856d1c6bde681d38f955675a9c11b3853eef617e1abfad8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86384e43ffa97406feb6a9760cb9ca425cbc725cb41324fe21a688216cf075ccdf2e27b682231dd11d4d7507740a8645eb66c4076df165d69da4a56d87d11efd
|
7
|
+
data.tar.gz: 7b22d9730b039452065db1e27d580ee1db4105861f323bd2800906a8c5197ed4d8cf76bb532c193dd3ab3255d491faeb04cbf47a677acbb1dbb46bfc0b6f2fc3
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.13
|
@@ -91,9 +91,10 @@ module RESTFramework::BaseModelControllerMixin
|
|
91
91
|
|
92
92
|
# Get the available fields. Returning `nil` indicates that anything should be accepted. If
|
93
93
|
# `fallback` is true, then we should fallback to this controller's model columns, or an empty
|
94
|
-
# array.
|
94
|
+
# array. This should always return an array of strings, no symbols, and possibly `nil` (only if
|
95
|
+
# `fallback` is false).
|
95
96
|
def get_fields(input_fields: nil, fallback: true)
|
96
|
-
input_fields ||= self.fields if fallback
|
97
|
+
input_fields ||= self.fields&.map(&:to_s) if fallback
|
97
98
|
|
98
99
|
# If fields is a hash, then parse it.
|
99
100
|
if input_fields.is_a?(Hash)
|
@@ -14,14 +14,12 @@ class RESTFramework::ModelFilter < RESTFramework::BaseFilter
|
|
14
14
|
# Get a list of filterset fields for the current action. Fallback to columns because we don't want
|
15
15
|
# to try filtering by any query parameter because that could clash with other query parameters.
|
16
16
|
def _get_fields
|
17
|
-
return
|
18
|
-
|
19
|
-
).map(&:to_s)
|
17
|
+
# Always return a list of strings; `@controller.get_fields` already does this.
|
18
|
+
return @controller.class.filterset_fields&.map(&:to_s) || @controller.get_fields(fallback: true)
|
20
19
|
end
|
21
20
|
|
22
21
|
# Filter params for keys allowed by the current action's filterset_fields/fields config.
|
23
22
|
def _get_filter_params
|
24
|
-
# Map filterset fields to strings because query parameter keys are strings.
|
25
23
|
fields = self._get_fields
|
26
24
|
|
27
25
|
return @controller.request.query_parameters.select { |p, _|
|
@@ -69,7 +67,7 @@ class RESTFramework::ModelOrderingFilter < RESTFramework::BaseFilter
|
|
69
67
|
# Get a list of ordering fields for the current action. Do not fallback to columns in case the
|
70
68
|
# user wants to order by a virtual column.
|
71
69
|
def _get_fields
|
72
|
-
return
|
70
|
+
return @controller.class.ordering_fields&.map(&:to_s) || @controller.get_fields
|
73
71
|
end
|
74
72
|
|
75
73
|
# Convert ordering string to an ordering configuration.
|
@@ -119,10 +117,10 @@ class RESTFramework::ModelSearchFilter < RESTFramework::BaseFilter
|
|
119
117
|
# common string-like columns by default.
|
120
118
|
def _get_fields
|
121
119
|
if search_fields = @controller.class.search_fields
|
122
|
-
return search_fields
|
120
|
+
return search_fields&.map(&:to_s)
|
123
121
|
end
|
124
122
|
|
125
|
-
columns = @controller.class.get_model.
|
123
|
+
columns = @controller.class.get_model.column_names
|
126
124
|
return @controller.get_fields(fallback: true).select { |f|
|
127
125
|
f.in?(RESTFramework.config.search_columns) && f.in?(columns)
|
128
126
|
}
|
data/lib/rest_framework/utils.rb
CHANGED
@@ -121,7 +121,7 @@ module RESTFramework::Utils
|
|
121
121
|
}.sort_by { |r|
|
122
122
|
# Sort by levels first, so the routes matching closely with current request show first, then
|
123
123
|
# by the path, and finally by the HTTP verb.
|
124
|
-
[r[:_levels], r[:
|
124
|
+
[r[:_levels], r[:path], HTTP_METHOD_ORDERING.index(r[:verb]) || 99]
|
125
125
|
}.group_by { |r| r[:controller] }.sort_by { |c, _r|
|
126
126
|
# Sort the controller groups by current controller first, then alphanumerically.
|
127
127
|
[request.params[:controller] == c ? 0 : 1, c]
|
@@ -150,11 +150,13 @@ module RESTFramework::Utils
|
|
150
150
|
Rails.logger.warn("RRF: Unknown key in fields hash: #{k}")
|
151
151
|
end
|
152
152
|
|
153
|
-
return
|
153
|
+
# We should always return strings, not symbols.
|
154
|
+
return parsed_fields.map(&:to_s)
|
154
155
|
end
|
155
156
|
|
156
157
|
# Get the fields for a given model, including not just columns (which includes
|
157
|
-
# foreign keys), but also associations.
|
158
|
+
# foreign keys), but also associations. Note that we always return an array of
|
159
|
+
# strings, not symbols.
|
158
160
|
def self.fields_for(model, exclude_associations: nil)
|
159
161
|
foreign_keys = model.reflect_on_all_associations(:belongs_to).map(&:foreign_key)
|
160
162
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest_framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregory N. Schmit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02
|
11
|
+
date: 2023-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|