itg 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/itg/controllers/itg_controller_set_current_request_details.rb +3 -0
- data/lib/itg/controllers/itg_entities_controller_base.rb +2 -1
- data/lib/itg/controllers/itg_generic_controller_base.rb +24 -15
- data/lib/itg/itg_api_key_authenticatable.rb +2 -0
- data/lib/itg/itg_current_base.rb +5 -1
- data/lib/itg/models/itg_entity_model_base.rb +1 -1
- data/lib/itg/version.rb +2 -2
- 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: 0afe075ee51223b1acb4a4e58f21089187f8b8ce1a60bf7bfd56370c9620a5c6
|
4
|
+
data.tar.gz: 94bcb279eaf33053677675b4f66339e95acbc17a1f7b35a719fbe9df22d7e46d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05cc9c9e20d2a5bf4d434533acd2fa6e0c603f87f914800973ea89eaea0ce1da3ee26bd141405f7cfaf39f7cb22774b08b535740e9cb11feb5c8214b3780e0f7
|
7
|
+
data.tar.gz: c14f8d176f5615dc8a797e866f281f42899fb6171bf3aec7d728a8aadd23726718db1b0fdb13aeaf5382e0f510bad70fcb8fc35f0be0ebecf6c70ee1f5777803
|
@@ -8,6 +8,9 @@ module Itg
|
|
8
8
|
Current.user_agent = request.user_agent
|
9
9
|
Current.ip_address = request.ip
|
10
10
|
Current.host = request.host
|
11
|
+
Current.context = @context
|
12
|
+
puts ">>>> ControllerSetCurrentRequestDetails.before_action - params: #{params}"
|
13
|
+
puts ">>>> ControllerSetCurrentRequestDetails.before_action - Current: #{Current}"
|
11
14
|
end
|
12
15
|
end
|
13
16
|
|
@@ -20,7 +20,8 @@ module Itg
|
|
20
20
|
# @g_model_class = Entity
|
21
21
|
@g_model_class = self.class.model_class
|
22
22
|
@g_search_field = 'kind'
|
23
|
-
@g_permitted_params = {kind: nil, tags: nil, context: nil, attrs: {}}
|
23
|
+
# @g_permitted_params = {kind: nil, tags: nil, context: nil, attrs: {}}
|
24
|
+
@g_permitted_params = {kind: nil, tags: nil, attrs: {}}
|
24
25
|
end
|
25
26
|
|
26
27
|
def set_model_instance
|
@@ -95,8 +95,10 @@ module Itg
|
|
95
95
|
|
96
96
|
# @model_instance = collection.create!(model_instance_params(true))
|
97
97
|
# @model_instance = collection.create(model_instance_params(true))
|
98
|
+
puts ">>>>>> Entity.create - Current: #{Current.user.email}, #{Current.context}\n#{Current.to_string}"
|
98
99
|
@model_instance = collection.new(model_instance_params(true))
|
99
100
|
@model_instance.owner = @current_bearer if @model_instance.respond_to?(:owner)
|
101
|
+
@model_instance.context = Current.context if @model_instance.respond_to?(:context)
|
100
102
|
# puts ">>>> @model_instance: #{@model_instance}"
|
101
103
|
# json_response(@model_instance, :created)
|
102
104
|
# puts ">>>>>>> create...."
|
@@ -185,34 +187,34 @@ module Itg
|
|
185
187
|
end
|
186
188
|
|
187
189
|
def g_check_variables
|
188
|
-
ITG_LOGGER.info
|
189
|
-
raise
|
190
|
+
ITG_LOGGER.info "*** [GenericController.g_check_variables] ..."
|
191
|
+
raise "[GenericController] @g_model_class is nil!" unless @g_model_class
|
190
192
|
raise "[GenericController/#{@g_model_class}] @g_search_field is nil!" unless @g_search_field
|
191
193
|
raise "[GenericController/#{@g_model_class}] @g_permitted_params is nil!" unless @g_permitted_params
|
192
194
|
end
|
193
195
|
|
194
196
|
def g_model_class
|
195
|
-
ITG_LOGGER.info
|
197
|
+
ITG_LOGGER.info "*** [GenericController.g_model_class] ..."
|
196
198
|
@g_model_class ||= nil
|
197
199
|
end
|
198
200
|
|
199
201
|
def g_parent_model_class
|
200
|
-
ITG_LOGGER.info
|
202
|
+
ITG_LOGGER.info "*** [GenericController.g_parent_model_class] ..."
|
201
203
|
@g_parent_model_class ||= nil
|
202
204
|
end
|
203
205
|
|
204
206
|
def g_search_field
|
205
|
-
ITG_LOGGER.info
|
207
|
+
ITG_LOGGER.info "*** [GenericController.g_search_field] ..."
|
206
208
|
@g_search_field ||= nil
|
207
209
|
end
|
208
210
|
|
209
211
|
def g_permitted_params
|
210
|
-
ITG_LOGGER.info
|
212
|
+
ITG_LOGGER.info "*** [GenericController.g_permitted_params] ..."
|
211
213
|
@g_permitted_params ||= nil
|
212
214
|
end
|
213
215
|
|
214
216
|
def g_only_show
|
215
|
-
ITG_LOGGER.info
|
217
|
+
ITG_LOGGER.info "*** [GenericController.g_only_show] ..."
|
216
218
|
@g_only_show ||= false
|
217
219
|
end
|
218
220
|
|
@@ -225,11 +227,11 @@ module Itg
|
|
225
227
|
|
226
228
|
def model_instance_params(create = false)
|
227
229
|
# puts '>>>>>>> [GenericController.model_instance_params] ...'
|
228
|
-
ITG_LOGGER.info
|
230
|
+
ITG_LOGGER.info "*** [GenericController.model_instance_params] ..."
|
229
231
|
ITG_LOGGER.info ">>>>> params: #{params}"
|
230
232
|
ITG_LOGGER.info ">>>>> @g_model_class: #{@g_model_class}"
|
231
233
|
# params_model_sym = @g_model_class.name.parameterize.underscore.to_sym
|
232
|
-
params_model_sym = @g_model_class.name.underscore.gsub(
|
234
|
+
params_model_sym = @g_model_class.name.underscore.gsub("/", "_").to_sym
|
233
235
|
ITG_LOGGER.info ">>>>> params_model_sym: #{params_model_sym}"
|
234
236
|
ITG_LOGGER.info ">>>>> @g_permitted_params: #{@g_permitted_params}"
|
235
237
|
# ITG_LOGGER.info "*** [GenericController.model_instance_params] g_permitted_params:\n#{@g_permitted_params}"
|
@@ -254,9 +256,16 @@ module Itg
|
|
254
256
|
# ITG_LOGGER.info "*** [GenericController.model_instance_params] field: #{field.inspect}"
|
255
257
|
# ITG_LOGGER.info "*** [GenericController.model_instance_params] field.options: #{field.options.inspect}"
|
256
258
|
# ITG_LOGGER.info "*** [GenericController.model_instance_params] field.options[:type]: #{field.options[:type].inspect}, field.default_val: #{field.default_val.inspect}"
|
257
|
-
ret.delete(k) if v ==
|
259
|
+
ret.delete(k) if v == "" and !field.default_val.nil?
|
258
260
|
end
|
259
261
|
ITG_LOGGER.info "*** [GenericController.model_instance_params] (create) changed return:\n#{ret}"
|
262
|
+
|
263
|
+
# puts ">>>> ret: #{ret}"
|
264
|
+
# if ret.include?('context')
|
265
|
+
# if c = ret['context']
|
266
|
+
# ret.delete('context')
|
267
|
+
# ITG_LOGGER.info "*** [GenericController.model_instance_params] (create) changed return (context):\n#{ret}"
|
268
|
+
# end
|
260
269
|
end
|
261
270
|
ret
|
262
271
|
end
|
@@ -269,7 +278,7 @@ module Itg
|
|
269
278
|
ITG_LOGGER.info "*** [GenericController/#{@g_model_class}.index] With parent: #{@g_parent_model_class}"
|
270
279
|
# puts "*** [GenericController/#{@g_model_class}.index] With parent: #{@g_parent_model_class}"
|
271
280
|
collection_name = @g_model_class.to_s.parameterize.pluralize
|
272
|
-
parent_field_id = @g_parent_model_class.to_s.parameterize +
|
281
|
+
parent_field_id = @g_parent_model_class.to_s.parameterize + "_id"
|
273
282
|
parent_id = params[parent_field_id.to_sym]
|
274
283
|
raise "[GenericController/#{@g_model_class}.index] Parent id is empty!" if parent_id.nil? || parent_id.empty?
|
275
284
|
ITG_LOGGER.info "*** [GenericController/#{@g_model_class}.index] collection_name: #{collection_name}, parent_field_id: #{parent_field_id}, parent_id: #{parent_id}"
|
@@ -291,15 +300,15 @@ module Itg
|
|
291
300
|
end
|
292
301
|
|
293
302
|
def require_permission
|
294
|
-
if @g_model_class.attribute_names.include?(
|
303
|
+
if @g_model_class.attribute_names.include?("owner_id")
|
295
304
|
# puts "******** generic_controller#require_permission @model_instance.owner: #{@model_instance&.owner}, @model_instance: #{@model_instance}"
|
296
305
|
if @model_instance && @model_instance.owner_id != @current_bearer.id
|
297
|
-
json_response(
|
306
|
+
json_response("Not allowed!", :forbidden)
|
298
307
|
end
|
299
308
|
else
|
300
309
|
# puts "******** generic_controller#require_permission @current_bearer: #{@current_bearer.inspect}, @model_instance: #{@model_instance.inspect}"
|
301
|
-
unless @current_bearer.kind ==
|
302
|
-
json_response(
|
310
|
+
unless @current_bearer.kind == "one"
|
311
|
+
json_response("Not allowed!", :forbidden)
|
303
312
|
end
|
304
313
|
end
|
305
314
|
end
|
@@ -16,6 +16,8 @@ module Itg
|
|
16
16
|
def authenticate_with_api_key!
|
17
17
|
@current_bearer = authenticate_or_request_with_http_token(&method(:authenticator))
|
18
18
|
Current.user = @current_bearer
|
19
|
+
puts ">>>> authenticate_with_api_key! - params: #{params}"
|
20
|
+
# Current.context =
|
19
21
|
end
|
20
22
|
|
21
23
|
# Use this for optional API key authentication
|
data/lib/itg/itg_current_base.rb
CHANGED
@@ -8,9 +8,13 @@ module Itg
|
|
8
8
|
attribute :config
|
9
9
|
attribute :request_id, :user_agent, :ip_address, :host
|
10
10
|
|
11
|
+
end
|
12
|
+
|
13
|
+
class_methods do
|
11
14
|
def to_s
|
12
15
|
ret_hash = {}
|
13
|
-
ret_hash[:user] = user.
|
16
|
+
ret_hash[:user] = user.email if user
|
17
|
+
ret_hash[:context] = context if context
|
14
18
|
ret_hash[:request_id] = request_id if request_id
|
15
19
|
ret_hash[:user_agent] = user_agent if user_agent
|
16
20
|
ret_hash[:host] = host if host
|
data/lib/itg/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aAon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|