itg 0.1.10 → 0.1.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe781750f5aa0333312d6a9fd50522d349b25d4c33459c82e9db8417c60e2ab1
4
- data.tar.gz: 112e6866a3e64dfa33ecc755d69c40d44c4f460e8b91a8bbf0a3a19e14daacf7
3
+ metadata.gz: 0afe075ee51223b1acb4a4e58f21089187f8b8ce1a60bf7bfd56370c9620a5c6
4
+ data.tar.gz: 94bcb279eaf33053677675b4f66339e95acbc17a1f7b35a719fbe9df22d7e46d
5
5
  SHA512:
6
- metadata.gz: 569b0ef8c9e406792bbe4491bf841ce1558d26b6cfa206395b4d62368170a2741048f527cde8406666f973cbf2ad9b262fbd4e4cee3d54f53d3a2f0d00c1746e
7
- data.tar.gz: 20df9342f243bb409fd467c97ef55a781abc3e1198142739488603c1625a81a485603da738131b684ea8c4bb388a49caa88665e72829b731763f79389cd7b4cb
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 '*** [GenericController.g_check_variables] ...'
189
- raise '[GenericController] @g_model_class is nil!' unless @g_model_class
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 '*** [GenericController.g_model_class] ...'
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 '*** [GenericController.g_parent_model_class] ...'
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 '*** [GenericController.g_search_field] ...'
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 '*** [GenericController.g_permitted_params] ...'
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 '*** [GenericController.g_only_show] ...'
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 '*** [GenericController.model_instance_params] ...'
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('/', '_').to_sym
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 == '' and !field.default_val.nil?
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 + '_id'
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?('owner_id')
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('Not allowed!', :forbidden)
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 == 'one'
302
- json_response('Not allowed!', :forbidden)
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
@@ -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.username if 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
@@ -22,7 +22,7 @@ module Itg
22
22
  validates_presence_of :context
23
23
 
24
24
  # belongs_to :owner, class_name: 'User'
25
- belongs_to :owner, class_name: User
25
+ belongs_to :owner, class_name: 'User'
26
26
 
27
27
  def to_s
28
28
  attrs['name'] || attrs['descr'] || attrs['code']
data/lib/itg/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Itg
4
- VERSION = "0.1.10"
5
- DATE = "21/3/2024"
4
+ VERSION = "0.1.11"
5
+ DATE = "28/3/2024"
6
6
 
7
7
  def self.version_info
8
8
  "Itg gem v.#{VERSION} #{DATE}"
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.10
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-21 00:00:00.000000000 Z
11
+ date: 2024-03-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: