kanal-plugins-user_system 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8b808b891105793f573a9ad5761aafcfb63997d3d600bdd6ae157f7b6e326cf
4
- data.tar.gz: 8feaa7ed933bb5ae1f4669cc12b762e8afdbb33e97ec855f72628515d059c2eb
3
+ metadata.gz: 0f7c84fbbba995954788ddad3408e4db13073831f9c8e0350898d0280e1b394c
4
+ data.tar.gz: 8302c8a1a1fbb51ed2800dbbb41d52af9330e461ff8fc270e5b014fcb28f50ef
5
5
  SHA512:
6
- metadata.gz: d92b41aeae204aa4a496b77042ac44ca3e4159d36aaa4bed5315b409a3aa3f914cfb6599f0dd7841e80a223c2b22c14ca86844adf437a5fd44b8be3044e40049
7
- data.tar.gz: 9bc617ad85f52a023ca1bd8dc2a8dea3dd394c71bd07c517be9ea76f1d49be18a98271e9577d625f2a57196486bae045ba5353a405937fb6f100777f459ad3c2
6
+ metadata.gz: ac6957526d879c8f8974fc1269a6677b4a26e2a418c9edb1cbc4cd326d03d717886364044edbb22a9fb7e6027c6baa581f472be502550255d65e9c8139d5871f
7
+ data.tar.gz: bd74983833ede706717fee5ec15886542703ea38673a1b4537a07d0eb5955b9f753d0374ab0989555cdcffb1f80b5e900e1d16e99e8407f905f1c3c6c918d3c0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2023-04-12
4
+
5
+ - Auto creation of users. Now available for telegram
6
+
3
7
  ## [0.1.0] - 2022-11-14
4
8
 
5
9
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,25 +1,19 @@
1
- GIT
2
- remote: git@github.com:idchlife/kanal.git
3
- revision: 5dbc20a3480337192d1193b0e569dba9d665d4c9
4
- specs:
5
- kanal (0.3.0)
6
-
7
1
  PATH
8
2
  remote: .
9
3
  specs:
10
- kanal-plugins-user_system (0.2.0)
4
+ kanal-plugins-user_system (0.3.0)
11
5
  activerecord
12
6
  sqlite3
13
7
 
14
8
  GEM
15
9
  remote: https://rubygems.org/
16
10
  specs:
17
- activemodel (7.0.4.1)
18
- activesupport (= 7.0.4.1)
19
- activerecord (7.0.4.1)
20
- activemodel (= 7.0.4.1)
21
- activesupport (= 7.0.4.1)
22
- activesupport (7.0.4.1)
11
+ activemodel (7.0.4.3)
12
+ activesupport (= 7.0.4.3)
13
+ activerecord (7.0.4.3)
14
+ activemodel (= 7.0.4.3)
15
+ activesupport (= 7.0.4.3)
16
+ activesupport (7.0.4.3)
23
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
24
18
  i18n (>= 1.6, < 2)
25
19
  minitest (>= 5.1)
@@ -27,7 +21,7 @@ GEM
27
21
  ast (2.4.2)
28
22
  backport (1.2.0)
29
23
  benchmark (0.2.1)
30
- concurrent-ruby (1.2.0)
24
+ concurrent-ruby (1.2.2)
31
25
  diff-lcs (1.5.0)
32
26
  docile (1.4.0)
33
27
  e2mmap (0.1.0)
@@ -35,23 +29,23 @@ GEM
35
29
  concurrent-ruby (~> 1.0)
36
30
  jaro_winkler (1.5.4)
37
31
  json (2.6.3)
38
- kanal-plugins-active_record (0.2.0)
32
+ kanal (0.4.3)
33
+ kanal-plugins-active_record (0.2.1)
39
34
  activerecord
40
- kanal
41
35
  kramdown (2.4.0)
42
36
  rexml
43
37
  kramdown-parser-gfm (1.1.0)
44
38
  kramdown (~> 2.0)
45
- minitest (5.17.0)
46
- nokogiri (1.14.0-x86_64-darwin)
39
+ minitest (5.18.0)
40
+ nokogiri (1.14.2-x86_64-linux)
47
41
  racc (~> 1.4)
48
42
  parallel (1.22.1)
49
- parser (3.2.0.0)
43
+ parser (3.2.2.0)
50
44
  ast (~> 2.4.1)
51
45
  racc (1.6.2)
52
46
  rainbow (3.1.1)
53
47
  rake (13.0.6)
54
- regexp_parser (2.6.2)
48
+ regexp_parser (2.7.0)
55
49
  reverse_markdown (2.1.1)
56
50
  nokogiri
57
51
  rexml (3.2.5)
@@ -59,30 +53,30 @@ GEM
59
53
  rspec-core (~> 3.12.0)
60
54
  rspec-expectations (~> 3.12.0)
61
55
  rspec-mocks (~> 3.12.0)
62
- rspec-core (3.12.0)
56
+ rspec-core (3.12.1)
63
57
  rspec-support (~> 3.12.0)
64
58
  rspec-expectations (3.12.2)
65
59
  diff-lcs (>= 1.2.0, < 2.0)
66
60
  rspec-support (~> 3.12.0)
67
- rspec-mocks (3.12.3)
61
+ rspec-mocks (3.12.5)
68
62
  diff-lcs (>= 1.2.0, < 2.0)
69
63
  rspec-support (~> 3.12.0)
70
64
  rspec-support (3.12.0)
71
- rubocop (1.44.0)
65
+ rubocop (1.49.0)
72
66
  json (~> 2.3)
73
67
  parallel (~> 1.10)
74
68
  parser (>= 3.2.0.0)
75
69
  rainbow (>= 2.2.2, < 4.0)
76
70
  regexp_parser (>= 1.8, < 3.0)
77
71
  rexml (>= 3.2.5, < 4.0)
78
- rubocop-ast (>= 1.24.1, < 2.0)
72
+ rubocop-ast (>= 1.28.0, < 2.0)
79
73
  ruby-progressbar (~> 1.7)
80
74
  unicode-display_width (>= 2.4.0, < 3.0)
81
- rubocop-ast (1.24.1)
82
- parser (>= 3.1.1.0)
75
+ rubocop-ast (1.28.0)
76
+ parser (>= 3.2.1.0)
83
77
  ruby-debug-ide (0.7.3)
84
78
  rake (>= 0.8.1)
85
- ruby-progressbar (1.11.0)
79
+ ruby-progressbar (1.13.0)
86
80
  simplecov (0.22.0)
87
81
  docile (~> 1.1)
88
82
  simplecov-html (~> 0.11)
@@ -104,10 +98,10 @@ GEM
104
98
  thor (~> 1.0)
105
99
  tilt (~> 2.0)
106
100
  yard (~> 0.9, >= 0.9.24)
107
- sqlite3 (1.6.0-x86_64-darwin)
101
+ sqlite3 (1.6.2-x86_64-linux)
108
102
  thor (1.2.1)
109
- tilt (2.0.11)
110
- tzinfo (2.0.5)
103
+ tilt (2.1.0)
104
+ tzinfo (2.0.6)
111
105
  concurrent-ruby (~> 1.0)
112
106
  unicode-display_width (2.4.2)
113
107
  webrick (1.7.0)
@@ -115,10 +109,10 @@ GEM
115
109
  webrick (~> 1.7.0)
116
110
 
117
111
  PLATFORMS
118
- x86_64-darwin-21
112
+ x86_64-linux
119
113
 
120
114
  DEPENDENCIES
121
- kanal!
115
+ kanal
122
116
  kanal-plugins-active_record
123
117
  kanal-plugins-user_system!
124
118
  rake (~> 13.0)
@@ -130,4 +124,4 @@ DEPENDENCIES
130
124
  yard
131
125
 
132
126
  BUNDLED WITH
133
- 2.3.19
127
+ 2.4.5
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kanal
4
+ module Plugins
5
+ module UserSystem
6
+ module Helpers
7
+ #
8
+ # Serves as a configuration storage for UserSystem plugin to allow enabling of automatic creation of users
9
+ #
10
+ class AutoCreateEnabler
11
+ attr_reader :telegram_enabled
12
+
13
+ def initialize
14
+ @telegram_enabled = false
15
+ end
16
+
17
+ def enable_telegram
18
+ @telegram_enabled = true
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kanal
4
+ module Plugins
5
+ module UserSystem
6
+ module Helpers
7
+ #
8
+ # Serves as a storage of methods to enable automatic user creation used by UserSystem
9
+ #
10
+ module AutoCreator
11
+ #
12
+ # Enables automatic creation of telegram user with telegram_chat_id property during consuming of input by router
13
+ #
14
+ # @param [Kanal::Core::Core] core <description>
15
+ #
16
+ def self.enable_telegram(core)
17
+ core.hooks.attach :input_before_router do |input|
18
+ tg_chat_id = input.tg_chat_id
19
+
20
+ tg_chat_id_property = "telegram_chat_id"
21
+
22
+ return if tg_chat_id.nil?
23
+
24
+ user = KanalUser.find_all_by_property(property_name: tg_chat_id_property, property_value: tg_chat_id).first
25
+
26
+ unless user
27
+ username = input.tg_username
28
+
29
+ username ||= "TEMP_USERNAME_#{tg_chat_id}"
30
+
31
+ user = KanalUser.create(username: username)
32
+ user.create_or_update_property(tg_chat_id_property, tg_chat_id)
33
+ end
34
+
35
+ input.user = user
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "active_record"
4
4
 
5
- class CreateBaseModels < ActiveRecord::Migration[7.0]
5
+ class CreateBaseModels < ::ActiveRecord::Migration[7.0]
6
6
  def change
7
7
  create_table :kanal_users do |t|
8
8
  t.string :username, null: false, index: { unique: true, name: "kanal_unique_usernames" }
@@ -8,7 +8,7 @@ module Kanal
8
8
  module UserSystem
9
9
  module Models
10
10
  # Base user class for storing user properties
11
- class KanalUser < ActiveRecord::Base
11
+ class KanalUser < ::ActiveRecord::Base
12
12
  self.table_name = :kanal_users
13
13
 
14
14
  STATE_PROPERTY = "_state"
@@ -8,7 +8,7 @@ module Kanal
8
8
  module UserSystem
9
9
  module Models
10
10
  # Base user class for storing user properties
11
- class KanalUserProperty < ActiveRecord::Base
11
+ class KanalUserProperty < ::ActiveRecord::Base
12
12
  include Helpers::JsonValueConverterMixin
13
13
 
14
14
  self.table_name = :kanal_user_properties
@@ -2,6 +2,8 @@
2
2
 
3
3
  require "kanal/core/plugins/plugin"
4
4
  require_relative "./models/kanal_user"
5
+ require_relative "helpers/auto_creator"
6
+ require_relative "helpers/auto_create_enabler"
5
7
 
6
8
  module Kanal
7
9
  module Plugins
@@ -10,6 +12,14 @@ module Kanal
10
12
  # registration and removal system
11
13
  class UserSystemPlugin < Kanal::Core::Plugins::Plugin
12
14
  include Models
15
+ include Helpers
16
+
17
+ attr_reader :auto_create
18
+
19
+ def initialize
20
+ super
21
+ @auto_create = AutoCreateEnabler.new
22
+ end
13
23
 
14
24
  def name
15
25
  :user_system
@@ -31,6 +41,8 @@ module Kanal
31
41
 
32
42
  setup_user_storage core
33
43
  setup_user_state core
44
+
45
+ AutoCreator.enable_telegram(core) if @auto_create.telegram_enabled
34
46
  end
35
47
 
36
48
  def setup_user_state(core)
@@ -3,7 +3,7 @@
3
3
  module Kanal
4
4
  module Plugins
5
5
  module UserSystem
6
- VERSION = "0.2.0"
6
+ VERSION = "0.3.0"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kanal-plugins-user_system
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - idchlife
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-29 00:00:00.000000000 Z
11
+ date: 2023-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -56,9 +56,10 @@ files:
56
56
  - LICENSE.txt
57
57
  - README.md
58
58
  - Rakefile
59
- - kanal-plugins-user_system.gemspec
60
59
  - lib/kanal/plugins/user_system.rb
61
60
  - lib/kanal/plugins/user_system/database/database_connection.rb
61
+ - lib/kanal/plugins/user_system/helpers/auto_create_enabler.rb
62
+ - lib/kanal/plugins/user_system/helpers/auto_creator.rb
62
63
  - lib/kanal/plugins/user_system/helpers/json_value_converter_mixin.rb
63
64
  - lib/kanal/plugins/user_system/migrations/20221124150000_create_base_models.rb
64
65
  - lib/kanal/plugins/user_system/models/kanal_user.rb
@@ -74,7 +75,7 @@ metadata:
74
75
  homepage_uri: https://github.com/idchlife/kanal-plugins-user_system
75
76
  source_code_uri: https://github.com/idchlife/kanal-plugins-user_system
76
77
  changelog_uri: https://github.com/idchlife/kanal-plugins-user_system
77
- post_install_message:
78
+ post_install_message:
78
79
  rdoc_options: []
79
80
  require_paths:
80
81
  - lib
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
91
  version: '0'
91
92
  requirements: []
92
93
  rubygems_version: 3.1.6
93
- signing_key:
94
+ signing_key:
94
95
  specification_version: 4
95
96
  summary: User system plugin for kanal library, provides users, user properties, etc
96
97
  test_files: []
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/kanal/plugins/user_system/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "kanal-plugins-user_system"
7
- spec.version = Kanal::Plugins::UserSystem::VERSION
8
- spec.authors = ["idchlife"]
9
- spec.email = ["idchlife@gmail.com"]
10
-
11
- spec.summary = "User system plugin for kanal library, provides users, user properties, etc"
12
- spec.description = "Library that provides user feature, with saving users and their properties"
13
- spec.homepage = "https://github.com/idchlife/kanal-plugins-user_system"
14
- spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.7.6"
16
-
17
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
-
19
- spec.metadata["homepage_uri"] = spec.homepage
20
- spec.metadata["source_code_uri"] = "https://github.com/idchlife/kanal-plugins-user_system"
21
- spec.metadata["changelog_uri"] = "https://github.com/idchlife/kanal-plugins-user_system"
22
-
23
- spec.add_dependency "activerecord"
24
- # spec.add_dependency "kanal"
25
- spec.add_dependency "sqlite3"
26
-
27
- # Specify which files should be added to the gem when it is released.
28
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
- spec.files = Dir.chdir(__dir__) do
30
- `git ls-files -z`.split("\x0").reject do |f|
31
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
32
- end
33
- end
34
- spec.bindir = "exe"
35
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
36
- spec.require_paths = ["lib"]
37
-
38
- # Uncomment to register a new dependency of your gem
39
- # spec.add_dependency "example-gem", "~> 1.0"
40
-
41
- # For more information and examples about making a new gem, check out our
42
- # guide at: https://bundler.io/guides/creating_gem.html
43
- end