itg 0.1.9 → 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/README.md +19 -1
- data/lib/itg/controllers/itg_controller_set_current_request_details.rb +21 -0
- data/lib/itg/controllers/itg_entities_controller_base.rb +3 -2
- data/lib/itg/controllers/itg_generic_controller_base.rb +64 -54
- data/lib/itg/itg_api_key_authenticatable.rb +4 -0
- data/lib/itg/itg_current_base.rb +31 -0
- data/lib/itg/itg_printable.rb +2 -1
- data/lib/itg/itg_sec.rb +3 -3
- data/lib/itg/models/itg_context_model_base.rb +11 -1
- data/lib/itg/models/itg_entity_model_base.rb +2 -0
- data/lib/itg/models/itg_user_model_base.rb +14 -13
- data/lib/itg/version.rb +2 -2
- data/lib/itg.rb +2 -0
- metadata +4 -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
|
data/README.md
CHANGED
@@ -1,4 +1,22 @@
|
|
1
|
-
# Itg
|
1
|
+
# Itg gem
|
2
|
+
|
3
|
+
### Context
|
4
|
+
|
5
|
+
The `Context` describes the isolated storage for the users data
|
6
|
+
|
7
|
+
Every time a user can see and manage only the data of a single `context` in which he has access
|
8
|
+
|
9
|
+
User has a list of contexts (memberships) where has access.
|
10
|
+
Each `context membership` has: `context`, `user`, `access` (`ro`, `rw`, `admin`)
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
2
20
|
|
3
21
|
TODO: Delete this and the text below, and describe your gem
|
4
22
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Itg
|
2
|
+
module ControllerSetCurrentRequestDetails
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
before_action do
|
7
|
+
Current.request_id = request.uuid
|
8
|
+
Current.user_agent = request.user_agent
|
9
|
+
Current.ip_address = request.ip
|
10
|
+
Current.host = request.host
|
11
|
+
Current.context = @context
|
12
|
+
puts ">>>> ControllerSetCurrentRequestDetails.before_action - params: #{params}"
|
13
|
+
puts ">>>> ControllerSetCurrentRequestDetails.before_action - Current: #{Current}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class_methods do
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -20,11 +20,12 @@ module Itg
|
|
20
20
|
# @g_model_class = Entity
|
21
21
|
@g_model_class = self.class.model_class
|
22
22
|
@g_search_field = 'kind'
|
23
|
-
@
|
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
|
27
|
-
puts '******** entities_controller#set_model_instance......'
|
28
|
+
# puts '******** entities_controller#set_model_instance......'
|
28
29
|
ITG_LOGGER.info '*** [Entities.set_model_instance] ...'
|
29
30
|
@model_instance = @g_model_class.find(params[:id])
|
30
31
|
end
|
@@ -7,21 +7,22 @@ module Itg
|
|
7
7
|
included do
|
8
8
|
include Itg::Response
|
9
9
|
|
10
|
-
before_action :g_model_class, :g_parent_model_class, :g_search_field, :
|
10
|
+
before_action :g_model_class, :g_parent_model_class, :g_search_field, :g_permitted_params
|
11
11
|
# before_action :set_model_instance, only: [:show, :update, :destroy]
|
12
12
|
before_action :require_permission
|
13
13
|
before_action :switch_database
|
14
14
|
after_action :reset_database
|
15
15
|
|
16
16
|
def curr_user_db
|
17
|
-
@current_bearer ? @current_bearer.db : 'mainaaa'
|
17
|
+
# @current_bearer ? @current_bearer.db : 'mainaaa'
|
18
|
+
# 'test'
|
18
19
|
end
|
19
20
|
|
20
21
|
def index
|
21
|
-
puts "[GenericController.index] current_bearer: #{@current_bearer}, current_api_key: #{@current_api_key}"
|
22
|
-
puts "[GenericController.index] current_bearer.db: #{@current_bearer.db}, current_bearer.kind: #{@current_bearer.kind}"
|
23
|
-
puts "[GenericController.index] curr_user_db: #{curr_user_db}, params[:filter]: #{params[:filter]}"
|
24
|
-
pp "*** Api::V1::Cultivation::Chamber.count: #{Api::V1::Cultivation::Chamber.count}"
|
22
|
+
# puts "[GenericController.index] current_bearer: #{@current_bearer}, current_api_key: #{@current_api_key}"
|
23
|
+
# puts "[GenericController.index] current_bearer.db: #{@current_bearer.db}, current_bearer.kind: #{@current_bearer.kind}"
|
24
|
+
# puts "[GenericController.index] curr_user_db: #{curr_user_db}, params[:filter]: #{params[:filter]}"
|
25
|
+
# pp "*** Api::V1::Cultivation::Chamber.count: #{Api::V1::Cultivation::Chamber.count}"
|
25
26
|
ITG_LOGGER.info "*** [GenericController/#{@g_model_class}.index] params: #{params}\n params[:filter]: #{params[:filter]}\n db: #{@g_model_class.database_name}\n=========================="
|
26
27
|
collection = get_collection
|
27
28
|
# data = if (filter = params[:filter])
|
@@ -33,13 +34,13 @@ module Itg
|
|
33
34
|
# collection.all
|
34
35
|
# end
|
35
36
|
data = if (filter = params[:filter])
|
36
|
-
puts '----- with filter'
|
37
|
+
# puts '----- with filter'
|
37
38
|
collection.where(@g_search_field => /.*#{filter}.*/i)
|
38
39
|
else
|
39
|
-
puts '----- all'
|
40
|
+
# puts '----- all'
|
40
41
|
# pp collection.with(curr_user_db).all.count
|
41
|
-
pp collection.all.count
|
42
|
-
pp "*** Api::V1::Cultivation::Chamber.count: #{Api::V1::Cultivation::Chamber.count}"
|
42
|
+
# pp collection.all.count
|
43
|
+
# pp "*** Api::V1::Cultivation::Chamber.count: #{Api::V1::Cultivation::Chamber.count}"
|
43
44
|
collection.all
|
44
45
|
# Api::V1::Link.with(database: curr_user_db) { |klass| klass.all.to_a }
|
45
46
|
# collection.with(database: curr_user_db) { |klass| klass.all.to_a }
|
@@ -48,7 +49,7 @@ module Itg
|
|
48
49
|
# klass.all
|
49
50
|
# end
|
50
51
|
end
|
51
|
-
puts ">>>> collection '#{collection}' data (#{data.count}): #{data}"
|
52
|
+
# puts ">>>> collection '#{collection}' data (#{data.count}): #{data}"
|
52
53
|
if (view_name = params[:view])
|
53
54
|
data = data.respond_to?(view_name) ? data.send(view_name) : "View '#{view_name}' does not exist for collection '#{collection}'"
|
54
55
|
end
|
@@ -62,21 +63,21 @@ module Itg
|
|
62
63
|
# data = params[:filter] ? collection.where(@g_search_field => /.*#{params[:filter]}.*/i) : collection.all
|
63
64
|
# ITG_LOGGER.info "*** [GenericController/#{@g_model_class}.index] data to return (#{data.count}):\n#{JSON.pretty_generate data}\n============================"
|
64
65
|
# render json: params[:filter] ? @g_model_class.where(@g_search_field => /.*#{params[:filter]}.*/i) : @g_model_class.all
|
65
|
-
puts '>>>>>>> [GenericController.index] ....'
|
66
|
-
puts ">>>>>>> [GenericController.index] data (#{data.count if data})"
|
67
|
-
pp data
|
68
|
-
pp data
|
66
|
+
# puts '>>>>>>> [GenericController.index] ....'
|
67
|
+
# puts ">>>>>>> [GenericController.index] data (#{data.count if data})"
|
68
|
+
# pp data
|
69
|
+
# pp data
|
69
70
|
render json: data
|
70
71
|
end
|
71
72
|
|
72
73
|
def show
|
73
|
-
puts '>>>>>>> [GenericController.show] ...'
|
74
|
+
# puts '>>>>>>> [GenericController.show] ...'
|
74
75
|
ITG_LOGGER.info "*** [GenericController/#{@g_model_class}.show] params: #{params}\n params[:id]: #{params[:id]}\n db: #{@g_model_class.database_name}\n========================="
|
75
76
|
collection = get_collection
|
76
77
|
data = collection.find(params[:id])
|
77
|
-
ITG_LOGGER.info "*** [GenericController/#{@g_model_class}.show] data to return:\n#{JSON.pretty_generate data}\n============================"
|
78
|
-
puts ">>>>>>> [GenericController.show] collection: #{collection}"
|
79
|
-
pp data
|
78
|
+
ITG_LOGGER.info "*** [GenericController/#{@g_model_class}.show] data to return:\n#{JSON.pretty_generate data.to_s}\n============================"
|
79
|
+
# puts ">>>>>>> [GenericController.show] collection: #{collection}"
|
80
|
+
# pp data
|
80
81
|
if data
|
81
82
|
render json: data
|
82
83
|
else
|
@@ -85,7 +86,7 @@ module Itg
|
|
85
86
|
end
|
86
87
|
|
87
88
|
def create
|
88
|
-
puts '>>>>>>> [GenericController.create] ...'
|
89
|
+
# puts '>>>>>>> [GenericController.create] ...'
|
89
90
|
ITG_LOGGER.info "*** [GenericController/#{@g_model_class}.create] params:\n#{JSON.pretty_generate params}\n db: #{@g_model_class.database_name}\n============================"
|
90
91
|
# g_check_variables
|
91
92
|
# # ITG_LOGGER.info "*** [GenericController/#{@g_model_class}.create] model_instance_params:\n#{JSON.pretty_generate model_instance_params}\n============================"
|
@@ -94,8 +95,10 @@ module Itg
|
|
94
95
|
|
95
96
|
# @model_instance = collection.create!(model_instance_params(true))
|
96
97
|
# @model_instance = collection.create(model_instance_params(true))
|
98
|
+
puts ">>>>>> Entity.create - Current: #{Current.user.email}, #{Current.context}\n#{Current.to_string}"
|
97
99
|
@model_instance = collection.new(model_instance_params(true))
|
98
100
|
@model_instance.owner = @current_bearer if @model_instance.respond_to?(:owner)
|
101
|
+
@model_instance.context = Current.context if @model_instance.respond_to?(:context)
|
99
102
|
# puts ">>>> @model_instance: #{@model_instance}"
|
100
103
|
# json_response(@model_instance, :created)
|
101
104
|
# puts ">>>>>>> create...."
|
@@ -128,7 +131,7 @@ module Itg
|
|
128
131
|
end
|
129
132
|
|
130
133
|
def update
|
131
|
-
puts '>>>>>>> [GenericController.update] ...'
|
134
|
+
# puts '>>>>>>> [GenericController.update] ...'
|
132
135
|
ITG_LOGGER.info "*** [GenericController/#{@g_model_class}.update] params:\n#{JSON.pretty_generate params}\n db: #{@g_model_class.database_name}\n============================"
|
133
136
|
g_check_variables
|
134
137
|
# @model_instance.update(model_instance_params)
|
@@ -155,7 +158,7 @@ module Itg
|
|
155
158
|
|
156
159
|
def destroy
|
157
160
|
g_check_variables
|
158
|
-
puts "*** [GenericController/#{@g_model_class}.destroy] params:\n#{JSON.pretty_generate params}\n db: #{@g_model_class.database_name}\n============================"
|
161
|
+
# puts "*** [GenericController/#{@g_model_class}.destroy] params:\n#{JSON.pretty_generate params}\n db: #{@g_model_class.database_name}\n============================"
|
159
162
|
ITG_LOGGER.info "*** [GenericController/#{@g_model_class}.destroy] params:\n#{JSON.pretty_generate params}\n db: #{@g_model_class.database_name}\n============================"
|
160
163
|
if @model_instance
|
161
164
|
@model_instance.destroy
|
@@ -168,7 +171,7 @@ module Itg
|
|
168
171
|
private
|
169
172
|
|
170
173
|
def switch_database
|
171
|
-
puts ">>> [GenericController.switch_database] curr_user_db: #{curr_user_db}"
|
174
|
+
# puts ">>> [GenericController.switch_database] curr_user_db: #{curr_user_db}"
|
172
175
|
# if params.has_key? 'test'
|
173
176
|
# # db_name = "md-test"
|
174
177
|
# db_name = 'itg_api_test'
|
@@ -184,34 +187,34 @@ module Itg
|
|
184
187
|
end
|
185
188
|
|
186
189
|
def g_check_variables
|
187
|
-
ITG_LOGGER.info
|
188
|
-
raise
|
190
|
+
ITG_LOGGER.info "*** [GenericController.g_check_variables] ..."
|
191
|
+
raise "[GenericController] @g_model_class is nil!" unless @g_model_class
|
189
192
|
raise "[GenericController/#{@g_model_class}] @g_search_field is nil!" unless @g_search_field
|
190
|
-
raise "[GenericController/#{@g_model_class}] @
|
193
|
+
raise "[GenericController/#{@g_model_class}] @g_permitted_params is nil!" unless @g_permitted_params
|
191
194
|
end
|
192
195
|
|
193
196
|
def g_model_class
|
194
|
-
ITG_LOGGER.info
|
197
|
+
ITG_LOGGER.info "*** [GenericController.g_model_class] ..."
|
195
198
|
@g_model_class ||= nil
|
196
199
|
end
|
197
200
|
|
198
201
|
def g_parent_model_class
|
199
|
-
ITG_LOGGER.info
|
202
|
+
ITG_LOGGER.info "*** [GenericController.g_parent_model_class] ..."
|
200
203
|
@g_parent_model_class ||= nil
|
201
204
|
end
|
202
205
|
|
203
206
|
def g_search_field
|
204
|
-
ITG_LOGGER.info
|
207
|
+
ITG_LOGGER.info "*** [GenericController.g_search_field] ..."
|
205
208
|
@g_search_field ||= nil
|
206
209
|
end
|
207
210
|
|
208
|
-
def
|
209
|
-
ITG_LOGGER.info
|
210
|
-
@
|
211
|
+
def g_permitted_params
|
212
|
+
ITG_LOGGER.info "*** [GenericController.g_permitted_params] ..."
|
213
|
+
@g_permitted_params ||= nil
|
211
214
|
end
|
212
215
|
|
213
216
|
def g_only_show
|
214
|
-
ITG_LOGGER.info
|
217
|
+
ITG_LOGGER.info "*** [GenericController.g_only_show] ..."
|
215
218
|
@g_only_show ||= false
|
216
219
|
end
|
217
220
|
|
@@ -223,24 +226,24 @@ module Itg
|
|
223
226
|
# end
|
224
227
|
|
225
228
|
def model_instance_params(create = false)
|
226
|
-
puts '>>>>>>> [GenericController.model_instance_params] ...'
|
227
|
-
ITG_LOGGER.info
|
229
|
+
# puts '>>>>>>> [GenericController.model_instance_params] ...'
|
230
|
+
ITG_LOGGER.info "*** [GenericController.model_instance_params] ..."
|
228
231
|
ITG_LOGGER.info ">>>>> params: #{params}"
|
229
232
|
ITG_LOGGER.info ">>>>> @g_model_class: #{@g_model_class}"
|
230
233
|
# params_model_sym = @g_model_class.name.parameterize.underscore.to_sym
|
231
|
-
params_model_sym = @g_model_class.name.underscore.gsub(
|
234
|
+
params_model_sym = @g_model_class.name.underscore.gsub("/", "_").to_sym
|
232
235
|
ITG_LOGGER.info ">>>>> params_model_sym: #{params_model_sym}"
|
233
|
-
ITG_LOGGER.info ">>>>> @
|
234
|
-
# ITG_LOGGER.info "*** [GenericController.model_instance_params]
|
235
|
-
# ret = params.require(@g_model_class.name.underscore.to_sym).permit(*@
|
236
|
+
ITG_LOGGER.info ">>>>> @g_permitted_params: #{@g_permitted_params}"
|
237
|
+
# ITG_LOGGER.info "*** [GenericController.model_instance_params] g_permitted_params:\n#{@g_permitted_params}"
|
238
|
+
# ret = params.require(@g_model_class.name.underscore.to_sym).permit(*@g_permitted_params)
|
236
239
|
|
237
|
-
case @
|
240
|
+
case @g_permitted_params
|
238
241
|
when Array
|
239
|
-
ret = params.require(params_model_sym).permit(*@
|
242
|
+
ret = params.require(params_model_sym).permit(*@g_permitted_params)
|
240
243
|
when Hash
|
241
|
-
ret = params.require(params_model_sym).permit(*@
|
244
|
+
ret = params.require(params_model_sym).permit(*@g_permitted_params, **@g_permitted_params)
|
242
245
|
else
|
243
|
-
raise "[GenericController.model_instance_params] unhandled @
|
246
|
+
raise "[GenericController.model_instance_params] unhandled @g_permitted_params: #{@g_permitted_params.inspect}"
|
244
247
|
end
|
245
248
|
|
246
249
|
ITG_LOGGER.info "*** [GenericController.model_instance_params] return:\n#{ret}"
|
@@ -253,22 +256,29 @@ module Itg
|
|
253
256
|
# ITG_LOGGER.info "*** [GenericController.model_instance_params] field: #{field.inspect}"
|
254
257
|
# ITG_LOGGER.info "*** [GenericController.model_instance_params] field.options: #{field.options.inspect}"
|
255
258
|
# ITG_LOGGER.info "*** [GenericController.model_instance_params] field.options[:type]: #{field.options[:type].inspect}, field.default_val: #{field.default_val.inspect}"
|
256
|
-
ret.delete(k) if v ==
|
259
|
+
ret.delete(k) if v == "" and !field.default_val.nil?
|
257
260
|
end
|
258
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
|
259
269
|
end
|
260
270
|
ret
|
261
271
|
end
|
262
272
|
|
263
273
|
def get_collection
|
264
|
-
puts "*** [GenericController/#{@g_model_class}.get_collection] params: #{params}"
|
274
|
+
# puts "*** [GenericController/#{@g_model_class}.get_collection] params: #{params}"
|
265
275
|
ITG_LOGGER.info "*** [GenericController/#{@g_model_class}.get_collection] params: #{params}"
|
266
276
|
g_check_variables
|
267
277
|
if @g_parent_model_class
|
268
278
|
ITG_LOGGER.info "*** [GenericController/#{@g_model_class}.index] With parent: #{@g_parent_model_class}"
|
269
|
-
puts "*** [GenericController/#{@g_model_class}.index] With parent: #{@g_parent_model_class}"
|
279
|
+
# puts "*** [GenericController/#{@g_model_class}.index] With parent: #{@g_parent_model_class}"
|
270
280
|
collection_name = @g_model_class.to_s.parameterize.pluralize
|
271
|
-
parent_field_id = @g_parent_model_class.to_s.parameterize +
|
281
|
+
parent_field_id = @g_parent_model_class.to_s.parameterize + "_id"
|
272
282
|
parent_id = params[parent_field_id.to_sym]
|
273
283
|
raise "[GenericController/#{@g_model_class}.index] Parent id is empty!" if parent_id.nil? || parent_id.empty?
|
274
284
|
ITG_LOGGER.info "*** [GenericController/#{@g_model_class}.index] collection_name: #{collection_name}, parent_field_id: #{parent_field_id}, parent_id: #{parent_id}"
|
@@ -282,7 +292,7 @@ module Itg
|
|
282
292
|
end
|
283
293
|
else
|
284
294
|
ITG_LOGGER.info "*** [GenericController/#{@g_model_class}.index] NO parent...."
|
285
|
-
puts "*** [GenericController/#{@g_model_class}.index] NO parent...."
|
295
|
+
# puts "*** [GenericController/#{@g_model_class}.index] NO parent...."
|
286
296
|
collection = @g_model_class
|
287
297
|
# data = params[:filter] ? @g_model_class.where(@g_search_field => /.*#{params[:filter]}.*/i) : @g_model_class.all
|
288
298
|
end
|
@@ -290,15 +300,15 @@ module Itg
|
|
290
300
|
end
|
291
301
|
|
292
302
|
def require_permission
|
293
|
-
if @g_model_class.attribute_names.include?(
|
294
|
-
puts "******** generic_controller#require_permission @model_instance.owner: #{@model_instance&.owner}, @model_instance: #{@model_instance}"
|
303
|
+
if @g_model_class.attribute_names.include?("owner_id")
|
304
|
+
# puts "******** generic_controller#require_permission @model_instance.owner: #{@model_instance&.owner}, @model_instance: #{@model_instance}"
|
295
305
|
if @model_instance && @model_instance.owner_id != @current_bearer.id
|
296
|
-
json_response(
|
306
|
+
json_response("Not allowed!", :forbidden)
|
297
307
|
end
|
298
308
|
else
|
299
|
-
puts "******** generic_controller#require_permission @current_bearer: #{@current_bearer.inspect}, @model_instance: #{@model_instance.inspect}"
|
300
|
-
unless @current_bearer.kind ==
|
301
|
-
json_response(
|
309
|
+
# puts "******** generic_controller#require_permission @current_bearer: #{@current_bearer.inspect}, @model_instance: #{@model_instance.inspect}"
|
310
|
+
unless @current_bearer.kind == "one"
|
311
|
+
json_response("Not allowed!", :forbidden)
|
302
312
|
end
|
303
313
|
end
|
304
314
|
end
|
@@ -15,11 +15,15 @@ module Itg
|
|
15
15
|
# code when API key authentication fails
|
16
16
|
def authenticate_with_api_key!
|
17
17
|
@current_bearer = authenticate_or_request_with_http_token(&method(:authenticator))
|
18
|
+
Current.user = @current_bearer
|
19
|
+
puts ">>>> authenticate_with_api_key! - params: #{params}"
|
20
|
+
# Current.context =
|
18
21
|
end
|
19
22
|
|
20
23
|
# Use this for optional API key authentication
|
21
24
|
def authenticate_with_api_key
|
22
25
|
@current_bearer = authenticate_with_http_token(&method(:authenticator))
|
26
|
+
Current.user = @current_bearer
|
23
27
|
end
|
24
28
|
|
25
29
|
private
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Itg
|
2
|
+
module CurrentBase
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attribute :user
|
7
|
+
attribute :context
|
8
|
+
attribute :config
|
9
|
+
attribute :request_id, :user_agent, :ip_address, :host
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
class_methods do
|
14
|
+
def to_s
|
15
|
+
ret_hash = {}
|
16
|
+
ret_hash[:user] = user.email if user
|
17
|
+
ret_hash[:context] = context if context
|
18
|
+
ret_hash[:request_id] = request_id if request_id
|
19
|
+
ret_hash[:user_agent] = user_agent if user_agent
|
20
|
+
ret_hash[:host] = host if host
|
21
|
+
ret_hash[:ip_address] = ip_address if ip_address
|
22
|
+
if ret_hash.empty?
|
23
|
+
"Current singleton is empty"
|
24
|
+
else
|
25
|
+
# ret_hash.to_a.join(', ')
|
26
|
+
"Current is #{ret_hash.inspect}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/itg/itg_printable.rb
CHANGED
data/lib/itg/itg_sec.rb
CHANGED
@@ -19,12 +19,12 @@ module Itg
|
|
19
19
|
|
20
20
|
included do
|
21
21
|
begin
|
22
|
-
puts ">>>>>> itg_sec - include it....."
|
22
|
+
# puts ">>>>>> itg_sec - include it....."
|
23
23
|
unless Rails.env.test?
|
24
24
|
store_in database: DB_NAME, client: CLIENT_NAME
|
25
|
-
puts "[itg_sec] set db details: #{DB_NAME}, #{CLIENT_NAME}"
|
25
|
+
# puts "[itg_sec] set db details: #{DB_NAME}, #{CLIENT_NAME}"
|
26
26
|
end
|
27
|
-
self.itg_print_db_info
|
27
|
+
# self.itg_print_db_info
|
28
28
|
rescue NameError => e
|
29
29
|
# Ignored - Used only because the gem does not have the Rails initialized!
|
30
30
|
raise if e.message != "uninitialized constant Itg::Sec::Rails"
|
@@ -11,10 +11,20 @@ module Itg
|
|
11
11
|
field :code, type: String
|
12
12
|
field :name, type: String
|
13
13
|
field :descr, type: String
|
14
|
-
field :
|
14
|
+
field :db_name, type: String
|
15
|
+
field :db_client, type: String, default: "default"
|
15
16
|
|
16
17
|
validates_presence_of(:code, :name)
|
17
18
|
validates_uniqueness_of :code
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
[code, name, descr]
|
22
|
+
end
|
23
|
+
|
24
|
+
# def itg_print(header: nil, prefix: '', allow_nested: true)
|
25
|
+
# puts header if header
|
26
|
+
# puts "#{prefix}#{[attrs['name'] || attrs['descr'] || attrs['code']]}"
|
27
|
+
# end
|
18
28
|
end
|
19
29
|
end
|
20
30
|
end
|
@@ -44,9 +44,9 @@ module Itg
|
|
44
44
|
|
45
45
|
field :email, type: String
|
46
46
|
# field :password_digest, type: String
|
47
|
-
field :db, type: String
|
47
|
+
# field :db, type: String
|
48
48
|
field :kind, type: String, default: 'user'
|
49
|
-
field :contexts, type: Object, default: {}
|
49
|
+
# field :contexts, type: Object, default: {}
|
50
50
|
|
51
51
|
index({ email: 1 }, { unique: true, name: 'email_index' })
|
52
52
|
|
@@ -67,19 +67,20 @@ module Itg
|
|
67
67
|
super
|
68
68
|
end
|
69
69
|
|
70
|
-
def add_context(context, role: :user)
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
70
|
+
# def add_context(context, role: :user)
|
71
|
+
# if context.persisted?
|
72
|
+
# unless contexts.keys.include?(context.code.to_sym)
|
73
|
+
# contexts[context.code.to_sym] = {role: role.to_sym}
|
74
|
+
# contexts[context.code.to_sym][:name] = context[:name] if context[:name]
|
75
|
+
# contexts[context.code.to_sym][:descr] = context[:descr] if context[:descr]
|
76
|
+
# contexts[context.code.to_sym][:db] = context[:db] if context[:db]
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
# end
|
80
80
|
|
81
81
|
def to_s
|
82
|
-
attributes.symbolize_keys.slice(:_id, :email, :db, :role).to_s
|
82
|
+
# attributes.symbolize_keys.slice(:_id, :email, :db, :role).to_s
|
83
|
+
attributes.symbolize_keys.slice(:_id, :email, :role).to_s
|
83
84
|
end
|
84
85
|
|
85
86
|
def itg_print(header: nil, prefix: '', allow_nested: true)
|
data/lib/itg/version.rb
CHANGED
data/lib/itg.rb
CHANGED
@@ -10,9 +10,11 @@ require_relative "itg/itg_mongo_base"
|
|
10
10
|
require_relative "itg/itg_printable"
|
11
11
|
require_relative "itg/itg_api_key_authenticatable"
|
12
12
|
require_relative "itg/itg_response"
|
13
|
+
require_relative "itg/itg_current_base"
|
13
14
|
require_relative "itg/controllers/itg_generic_controller_base"
|
14
15
|
require_relative "itg/controllers/itg_api_keys_controller_base"
|
15
16
|
require_relative "itg/controllers/itg_entities_controller_base"
|
17
|
+
require_relative "itg/controllers/itg_controller_set_current_request_details"
|
16
18
|
require_relative "itg/itg_sec"
|
17
19
|
|
18
20
|
module Itg
|
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-
|
11
|
+
date: 2024-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -30,9 +30,11 @@ files:
|
|
30
30
|
- itg.gemspec
|
31
31
|
- lib/itg.rb
|
32
32
|
- lib/itg/controllers/itg_api_keys_controller_base.rb
|
33
|
+
- lib/itg/controllers/itg_controller_set_current_request_details.rb
|
33
34
|
- lib/itg/controllers/itg_entities_controller_base.rb
|
34
35
|
- lib/itg/controllers/itg_generic_controller_base.rb
|
35
36
|
- lib/itg/itg_api_key_authenticatable.rb
|
37
|
+
- lib/itg/itg_current_base.rb
|
36
38
|
- lib/itg/itg_mongo_base.rb
|
37
39
|
- lib/itg/itg_printable.rb
|
38
40
|
- lib/itg/itg_response.rb
|