json2sql 1.0.15 → 1.0.17
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/json2sql/query_policy.rb +35 -15
- data/lib/json2sql/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: 93c1247f7047a25a4a0250cac5d5613c313ccbc81e08f7d3a80a86741ecadf99
|
|
4
|
+
data.tar.gz: eb70aef8f428ae377e19eb4e7d1b379583ce59f41cbaa899f6a94929a314e398
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b3c7751decd988513996816c794cfde5e956eeca54372814b4cb85b42f7a2108cc55bcfca433ae3c0f15c8c422050540fb2b7b5630626f9f3fd33697ce2f283b
|
|
7
|
+
data.tar.gz: 1ab3701997f7d51b7378a7865836e9acb420510b160d359365627baebb814c7c18aea1f9d0e111125bf4a1500e1dd517a7cdcfe79118fe21ec74937638eeff60
|
|
@@ -97,9 +97,9 @@ module Json2sql
|
|
|
97
97
|
|
|
98
98
|
return false unless params.is_a?(Hash)
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
columns = params["columns"]
|
|
101
101
|
|
|
102
|
-
(
|
|
102
|
+
(columns.is_a?(Array) || columns.is_a?(Hash)) && columns.empty?
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
def filter_tables(params, config)
|
|
@@ -115,7 +115,7 @@ module Json2sql
|
|
|
115
115
|
|
|
116
116
|
# Filters children/parents relations in :allow mode.
|
|
117
117
|
# Only relations present as keys in config[relation] pass through.
|
|
118
|
-
# If config[relation] is absent or not a Hash, relations are
|
|
118
|
+
# If config[relation] is absent or not a Hash, all relations are blocked.
|
|
119
119
|
# No-op in :deny mode.
|
|
120
120
|
|
|
121
121
|
def filter_relations(params, config, relation)
|
|
@@ -128,35 +128,55 @@ module Json2sql
|
|
|
128
128
|
|
|
129
129
|
config_tables = config[relation]
|
|
130
130
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
params[relation] = param_tables.select { |table, _| config_tables.key?(table) }
|
|
131
|
+
params[relation] = config_tables.is_a?(Hash) ? param_tables.select { |table, _| config_tables.key?(table) } : {}
|
|
134
132
|
end
|
|
135
133
|
|
|
136
134
|
# Filters "columns" using mode (:allow or :deny).
|
|
137
135
|
# Handles Array (SELECT) and Hash (INSERT/UPDATE) column formats.
|
|
138
136
|
# Hash entries (function columns) always pass through in :allow mode.
|
|
139
|
-
# If no column list is defined
|
|
137
|
+
# If no column list is defined: in :allow mode all columns are blocked;
|
|
138
|
+
# in :deny mode columns are untouched.
|
|
140
139
|
|
|
141
140
|
def filter_columns(params, config)
|
|
142
141
|
|
|
143
|
-
|
|
142
|
+
param_columns = params["columns"]
|
|
143
|
+
|
|
144
|
+
return unless param_columns.is_a?(Array) || param_columns.is_a?(Hash)
|
|
145
|
+
|
|
146
|
+
config_columns = config["columns"]
|
|
147
|
+
|
|
148
|
+
unless config_columns.is_a?(Array)
|
|
144
149
|
|
|
145
|
-
|
|
150
|
+
if @mode == :allow
|
|
146
151
|
|
|
147
|
-
|
|
152
|
+
params["columns"] = param_columns.is_a?(Array) ? [] : {}
|
|
153
|
+
end
|
|
148
154
|
|
|
149
|
-
|
|
155
|
+
return
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
if @mode == :deny
|
|
159
|
+
|
|
160
|
+
if param_columns.is_a?(Array)
|
|
150
161
|
|
|
151
|
-
|
|
162
|
+
params["columns"] = param_columns.reject { |c| config_columns.include?(c) }
|
|
152
163
|
|
|
153
|
-
|
|
164
|
+
return
|
|
165
|
+
end
|
|
154
166
|
|
|
155
|
-
|
|
167
|
+
params["columns"] = param_columns.reject { |k, _| config_columns.include?(k) }
|
|
156
168
|
|
|
157
|
-
|
|
169
|
+
return
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
if param_columns.is_a?(Array)
|
|
158
173
|
|
|
174
|
+
params["columns"] = param_columns.select { |c| c.is_a?(Hash) || config_columns.include?(c) }
|
|
175
|
+
|
|
176
|
+
return
|
|
159
177
|
end
|
|
178
|
+
|
|
179
|
+
params["columns"] = param_columns.select { |k, _| config_columns.include?(k) }
|
|
160
180
|
end
|
|
161
181
|
|
|
162
182
|
# Merges forced "and" conditions into params["and"].
|
data/lib/json2sql/version.rb
CHANGED