itg 0.1.7 → 0.1.8

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: e1bd046d2cba513820497be3bb7a44105bbaee3d420ba96f22bb016d096c14ac
4
- data.tar.gz: 26615592add3b3bc1c68845962ef49425efc5ab47127548c8c0a73ce6ceaa09b
3
+ metadata.gz: 3d053cf4b8d8c39243e96253436bb4287d51c0f05c350e4974274547a3054ccd
4
+ data.tar.gz: ca430ed912df96c4d35439f78b40b4a041649430f3fdeecb13f29440a9e4a6f1
5
5
  SHA512:
6
- metadata.gz: 951fc43e0fcb89077b1e75c0f9bad2d5594b7bf51e0515c6b073214b215dbc07f0214f95c429abfa4007f5954eb4ff3c96af82c0a2ed8b50ae3d698751714ce2
7
- data.tar.gz: 6d17eaeab84070b5498cfd39791321ea5cffb360c32816f67a89d5acbe75b8728890d7642384d813ea1242e45a3407e21e07507aa31dbcf676dca3905f6d14c1
6
+ metadata.gz: be3e9fa71c749a1413158cdf1152d75bd2a6891bce296bb337ae86a005132df6d5b0113ced3750130e764006f3236e5f48f9cec41d0b6a73d0ec6958e05d9535
7
+ data.tar.gz: 9e59e76d5deea88cd5d5ce33a3538288411974623852ff8c0f45249a4e12bd9d15ff1df6114be98c6ffbf4891ff03c121d1169c81da3ccf5b1dc0ac66ee6845d
@@ -2,22 +2,9 @@
2
2
 
3
3
  # ItgApiKeyBase module
4
4
  module Itg
5
- module ApiKeyBase
5
+ module ApiKeyModelBase
6
6
  extend ActiveSupport::Concern
7
7
 
8
-
9
-
10
- # include Itg::MongoBase
11
- # include Itg::Sec
12
- # include Mongoid::Fields
13
- #
14
- # field :bearer_id, type: Integer
15
- # field :bearer_type, type: String
16
- # field :token_digest, type: String
17
- #
18
- # index({ bearer_id: 1, bearer_type: 1}, { name: "bearer_id_type_index" })
19
- # index({ token_digest: 1 }, { unique: true, name: "token_digest_index" })
20
-
21
8
  included do
22
9
  include Itg::MongoBase
23
10
  include Itg::Sec
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Itg
4
+ module ContextModelBase
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ include Itg::MongoBase
9
+ include Itg::Sec
10
+
11
+ field :code, type: String
12
+ field :name, type: String
13
+ field :descr, type: String
14
+ field :db, type: String
15
+
16
+ validates_presence_of(:code, :name)
17
+ validates_uniqueness_of :code
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Itg
4
+ module EntityModelBase
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ include Itg::MongoBase
9
+
10
+ store_in collection: 'entities'
11
+
12
+ # field :context, type: Array, default: [AppConfig::DEFAULT_CONTEXT_NAME] # MERGE_WITH_BACKEND
13
+ field :context, type: Array, default: [:default]
14
+ field :permissions, type: Object, default: {}
15
+ field :kind, type: String
16
+ field :attrs, type: Object
17
+ field :roles, type: Array, default: []
18
+ field :tags, type: Array, default: []
19
+
20
+ validates_presence_of :kind
21
+ validates_presence_of :attrs
22
+
23
+ belongs_to :owner, class_name: 'User'
24
+
25
+ def to_s
26
+ attrs['name'] || attrs['descr'] || attrs['code']
27
+ end
28
+
29
+ def itg_print(header: nil, prefix: '', allow_nested: true)
30
+ puts header if header
31
+ puts "#{prefix}#{[attrs['name'] || attrs['descr'] || attrs['code']]}"
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Itg
4
+ module UserModelBase
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ include Itg::MongoBase
9
+ include Itg::Sec
10
+
11
+ devise :database_authenticatable, :registerable, :recoverable, :rememberable,
12
+ :validatable, :confirmable, :lockable, :timeoutable, :trackable
13
+
14
+ ## Database authenticatable
15
+ field :encrypted_password, type: String, default: ''
16
+
17
+ ## Recoverable
18
+ field :reset_password_token, type: String
19
+ field :reset_password_sent_at, type: Time
20
+
21
+ ## Rememberable
22
+ field :remember_created_at, type: Time
23
+
24
+ ## Trackable
25
+ field :sign_in_count, type: Integer, default: 0
26
+ field :current_sign_in_at, type: Time
27
+ field :last_sign_in_at, type: Time
28
+ field :current_sign_in_ip, type: String
29
+ field :last_sign_in_ip, type: String
30
+
31
+ ## Confirmable
32
+ field :confirmation_token, type: String
33
+ field :confirmed_at, type: Time
34
+ field :confirmation_sent_at, type: Time
35
+ field :unconfirmed_email, type: String # Only if using reconfirmable
36
+
37
+ ## Lockable
38
+ field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
39
+ field :unlock_token, type: String # Only if unlock strategy is :email or :both
40
+ field :locked_at, type: Time
41
+
42
+
43
+ # include ActiveModel::SecurePassword
44
+
45
+ field :email, type: String
46
+ # field :password_digest, type: String
47
+ field :db, type: String
48
+ field :kind, type: String, default: 'user'
49
+ field :contexts, type: Object, default: {}
50
+
51
+ index({ email: 1 }, { unique: true, name: 'email_index' })
52
+
53
+ has_many :api_keys, as: :bearer
54
+ has_many :requests, dependent: :destroy
55
+
56
+ # has_secure_password
57
+
58
+ validates_presence_of(:email)
59
+ validates_uniqueness_of(:email)
60
+
61
+ def write_attribute(attr_name, value)
62
+ # puts "write_attribute - attr_name: #{attr_name}, value: #{value}"
63
+ if attr_name.to_s.downcase == 'kind'
64
+ value = value.to_s.strip.downcase
65
+ value = 'user' if ['', nil].include? value
66
+ end
67
+ super
68
+ end
69
+
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
+
81
+ def to_s
82
+ attributes.symbolize_keys.slice(:_id, :email, :db, :role).to_s
83
+ end
84
+
85
+ def itg_print(header: nil, prefix: '', allow_nested: true)
86
+ puts header if header
87
+ puts "#{prefix}#{to_s}"
88
+ end
89
+ end
90
+
91
+ class_methods do
92
+
93
+ end
94
+ end
95
+ end
data/lib/itg/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Itg
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.8"
5
5
  DATE = "18/2/2024"
6
6
 
7
7
  def self.version_info
data/lib/itg.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "itg/version"
4
- require_relative "itg/itg_model_base"
4
+ require_relative "itg/models/itg_model_base"
5
+ require_relative "itg/models/itg_api_key_model_base"
6
+ require_relative "itg/models/itg_user_model_base"
7
+ require_relative "itg/models/itg_context_model_base"
8
+ require_relative "itg/models/itg_entity_model_base"
5
9
  require_relative "itg/itg_mongo_base"
6
10
  require_relative "itg/itg_printable"
7
- # require_relative "itg/itg_sec"
8
- require_relative "itg/itg_api_key_base"
9
11
  require_relative "itg/itg_api_key_authenticatable"
10
12
  require_relative "itg/itg_response"
11
13
  require_relative "itg/itg_sec"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - aAon
@@ -30,12 +30,15 @@ files:
30
30
  - itg.gemspec
31
31
  - lib/itg.rb
32
32
  - lib/itg/itg_api_key_authenticatable.rb
33
- - lib/itg/itg_api_key_base.rb
34
- - lib/itg/itg_model_base.rb
35
33
  - lib/itg/itg_mongo_base.rb
36
34
  - lib/itg/itg_printable.rb
37
35
  - lib/itg/itg_response.rb
38
36
  - lib/itg/itg_sec.rb
37
+ - lib/itg/models/itg_api_key_model_base.rb
38
+ - lib/itg/models/itg_context_model_base.rb
39
+ - lib/itg/models/itg_entity_model_base.rb
40
+ - lib/itg/models/itg_model_base.rb
41
+ - lib/itg/models/itg_user_model_base.rb
39
42
  - lib/itg/version.rb
40
43
  - sig/itg.rbs
41
44
  homepage: https://aaon.aggate.gr