model_driven_api 3.19.0 → 3.20.0
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/README.md +1 -1
- data/lib/api/v2/request_json_attrs.rb +13 -1
- data/lib/model_driven_api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7ab2b6a7c7c7384c9decd7ab6491ba6daa6f31a0d3fbfc70c5aa65f61ee609d9
|
|
4
|
+
data.tar.gz: 2516e2a385ac48e62dff7e5a4c5d7f9863bbd8fb474ebcc3af98fae1b4d99d6c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5bdfab13321344419715fd92b297353803c527b7f99280c461280cf8f97cb25f6e263feda93c3ca40805874fb884d5805f40a55909971c7434424fcbf663c22e
|
|
7
|
+
data.tar.gz: a5f9525d01d41c1cec3353bbc651f014a3c4612108a8b27a15da8dc61a43b58a76c177c3a48713e4119f2b0031792d661341eed2e1204fb64b5db5a26c987529
|
data/README.md
CHANGED
|
@@ -195,7 +195,7 @@ Parameters work identically in query string (GET) and JSON body (POST search).
|
|
|
195
195
|
}
|
|
196
196
|
```
|
|
197
197
|
|
|
198
|
-
The client's options follow conventions (ADR 0006): `include` takes real associations only; secrets the model hides (a secret-named column left out of its default JSON, its `json_attrs[:except]` or `write_only_attributes`, e.g. Devise's `encrypted_password`) never come back, in v2, v3 or Ransack filters and sorts; `methods` serves what the model declares in `json_attrs[:methods]`, columns, associations, `<association>_ids`, and public methods written in the app or a thecore gem (not ending in `!`/`=`, no required arguments), which run read-only. Anything else is dropped from the response and logged; the response stays 200.
|
|
198
|
+
The client's options follow conventions (ADR 0006): `include` takes real associations only; secrets the model hides (a secret-named column left out of its default JSON, its `json_attrs[:except]` or `write_only_attributes`, e.g. Devise's `encrypted_password`) never come back, in v2, v3 or Ransack filters and sorts; `methods` serves what the model declares in `json_attrs[:methods]`, columns, associations, `<association>_ids`, and public methods written in the app or a thecore gem (not a model callback, not ending in `!`/`=`, no required arguments), which run read-only. Anything else is dropped from the response and logged; the response stays 200.
|
|
199
199
|
|
|
200
200
|
#### Ransack filtering (`q`)
|
|
201
201
|
|
|
@@ -9,7 +9,8 @@ module Api
|
|
|
9
9
|
# serializable_hash, e.g. Devise's encrypted_password, LdapServer#admin_password) never come back;
|
|
10
10
|
# - a `methods` name declared in the class's json_attrs[:methods] runs as before (a developer
|
|
11
11
|
# exposed it); a column or association reader (or `<assoc>_ids`) is a plain read; any other
|
|
12
|
-
# name must be public,
|
|
12
|
+
# name must be public, not a callback of the class (host Odoo #6314), end in neither `!` nor
|
|
13
|
+
# `=`, take no required argument and be written in
|
|
13
14
|
# the host or in a thecore gem (a gem named thecore* or depending on one), and it runs under
|
|
14
15
|
# the read-only guard: if it writes, or raises, only that field is dropped.
|
|
15
16
|
#
|
|
@@ -90,6 +91,7 @@ module Api
|
|
|
90
91
|
return :reader if reader?(klass, name)
|
|
91
92
|
return "ends in ! or =" if name.end_with?("!", "=")
|
|
92
93
|
return "not a public method" unless klass.public_method_defined?(name)
|
|
94
|
+
return "a callback" if callback?(klass, name)
|
|
93
95
|
|
|
94
96
|
method = klass.instance_method(name)
|
|
95
97
|
return "takes required arguments" if method.parameters.any? { |type, _| %i[req keyreq].include?(type) }
|
|
@@ -106,6 +108,16 @@ module Api
|
|
|
106
108
|
|
|
107
109
|
def active_record?(klass) = klass < ActiveRecord::Base
|
|
108
110
|
|
|
111
|
+
# Registered as a Symbol filter in any of the class's callback chains (validation, validate,
|
|
112
|
+
# save, create, update, destroy, commit, rollback, initialize, find, touch, and any custom
|
|
113
|
+
# chain). A callback belongs to the record's lifecycle, never to its API, and its side
|
|
114
|
+
# effects may live outside the database, where the read-only guard can't see them.
|
|
115
|
+
def callback?(klass, name)
|
|
116
|
+
return false unless klass.respond_to?(:__callbacks)
|
|
117
|
+
|
|
118
|
+
klass.__callbacks.each_value.any? { |chain| chain.any? { |cb| cb.filter.is_a?(Symbol) && cb.filter.to_s == name } }
|
|
119
|
+
end
|
|
120
|
+
|
|
109
121
|
def reader?(klass, name)
|
|
110
122
|
return false unless active_record?(klass)
|
|
111
123
|
return true if klass.column_names.include?(name)
|