authentication-zero 2.16.32 → 2.16.34

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: c282c63840e3d6072f86c899f4a477296f2d5145317b715c00e2a434a2c2a565
4
- data.tar.gz: 6f45065151e320e21a01c58a6daf2cf4101780428d6fd6d14341722aaec1bbd1
3
+ metadata.gz: a7a21585c929c9c8eee8d33a9709add052a69019db2d1cdec5dce194afc36c67
4
+ data.tar.gz: f4424c1a4166d1394fb1dc573edc0e8d90893d7e91347a9d6340de88d73f5d37
5
5
  SHA512:
6
- metadata.gz: 25ff1fc4f8822b6edaad54cd754b1b14ecfe89bfd6afb195942fce0974e3907852aea9a6fef643cffcd01351f992eaf3524bf0a92e773ff7ed97669de11ff0d6
7
- data.tar.gz: c1d3fa6bc16f41f0826edd2121910ead50c01137cdbf42a7140dd1625eaadab5606678986022d28a9972ca1aef0669e7bb4ab2f1fa5dacdf2b130365963cd6f2
6
+ metadata.gz: 45a0d2d68c6debd1c161a9c42d31263b0da1ac91ecf754f4675032e26abe208dc571f74a65b8a2a2109be3a6d66aa964a385ffd5d71c94de7c1d895b5a15e899
7
+ data.tar.gz: 131dbe9839a99f982cbb271474c93ac7b10f398f770bc4827a4deb22c1ec615d8a5d1869e8ef8eccad522a17b3736708d7fef3e907c98b1caaf8be27a966cebc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- authentication-zero (2.16.32)
4
+ authentication-zero (2.16.34)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -66,18 +66,18 @@ Use `before_action :require_sudo` in controllers with sensitive information, it
66
66
 
67
67
  ### Tenantable
68
68
 
69
- Some artifacts are generated in the application, which makes it possible to implement row-level multitenancy applications. You should follow some steps to make it work.
69
+ Some artifacts are generated in the application, which makes it possible to implement row-level multitenancy applications. The `Current.account` is set using the current user account.
70
70
 
71
- - Add `account_id` to each scoped table using `rails g migration add_account_to_projects account:references`.
71
+ You should follow some steps to make it work:
72
+
73
+ - Add `account_id` to each scoped table. ex: `rails g migration add_account_to_projects account:references`.
72
74
  - Add `include AccountScoped` to scoped models. It set up the account relationship and default scope using the current account.
73
- - The `Current.account` is set according to the url. `http://mywebsite.com/1234/projects`.
74
- - You should customize the authentication flow yourself, it means:
75
- - Add `account_id` to your users table using `rails g migration add_account_to_users account:references`.
76
- - Add `include AccountScoped` to your user model.
77
- - Use `joins(:user).find_by_id...` in the `authenticate` method.
78
- - Use `redirect_to "/#{user.account_id}"` after sign-in.
79
- - Override `Current#user=` to also set the account, `super; self.account = user.account`.
80
- - etc...
75
+
76
+ Set `Current.account` through the URL. `http://myapp.com/:account_id`. (optional)
77
+
78
+ - Add `require_relative "../lib/account_middleware"` to `config/application.rb`.
79
+ - Add `config.middleware.use AccountMiddleware` to your application class.
80
+ - More customization is required...
81
81
 
82
82
  ## Development
83
83
 
@@ -1,3 +1,3 @@
1
1
  module AuthenticationZero
2
- VERSION = "2.16.32"
2
+ VERSION = "2.16.34"
3
3
  end
@@ -54,11 +54,6 @@ class AuthenticationGenerator < Rails::Generators::Base
54
54
  application "config.action_mailer.default_url_options = { host: \"localhost\", port: 3000 }", env: "development"
55
55
  application "config.action_mailer.default_url_options = { host: \"localhost\", port: 3000 }", env: "test"
56
56
  environment ratelimit_block, env: "production" if options.ratelimit?
57
-
58
- if options.tenantable?
59
- prepend_to_file "config/application.rb", "require_relative \"../lib/account_middleware\"\n"
60
- application "config.middleware.use AccountMiddleware"
61
- end
62
57
  end
63
58
 
64
59
  def create_configuration_files
@@ -8,7 +8,7 @@ class AccountMiddleware
8
8
 
9
9
  _, account_id, request_path = request.path.split("/", 3)
10
10
 
11
- if identifier?(account_id)
11
+ if account_id !~ /\D/
12
12
  set_current_account(account_id)
13
13
 
14
14
  request.script_name = "/#{account_id}"
@@ -20,11 +20,7 @@ class AccountMiddleware
20
20
  end
21
21
 
22
22
  private
23
- def identifier?(value)
24
- Integer(value, exception: false) != nil
25
- end
26
-
27
23
  def set_current_account(account_id)
28
- Current.account = Account.find_by_id(account_id)
24
+ Current.account = Account.find(account_id)
29
25
  end
30
26
  end
@@ -16,6 +16,9 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Mi
16
16
  t.string :provider
17
17
  t.string :uid
18
18
  <%- end -%>
19
+ <%- if options.tenantable? %>
20
+ t.references :account, null: false, foreign_key: true
21
+ <%- end -%>
19
22
 
20
23
  t.timestamps
21
24
  end
@@ -1,2 +1,3 @@
1
1
  class Account < ApplicationRecord
2
+ has_one :user, dependent: :destroy
2
3
  end
@@ -8,4 +8,9 @@ class Current < ActiveSupport::CurrentAttributes
8
8
  def session=(session)
9
9
  super; self.user = session.user
10
10
  end
11
+ <%- if options.tenantable? %>
12
+ def user=(user)
13
+ super; self.account = user.account
14
+ end
15
+ <%- end -%>
11
16
  end
@@ -1,5 +1,8 @@
1
1
  class User < ApplicationRecord
2
2
  has_secure_password
3
+ <%- if options.tenantable? %>
4
+ belongs_to :account
5
+ <%- end -%>
3
6
 
4
7
  has_many :email_verification_tokens, dependent: :destroy
5
8
  has_many :password_reset_tokens, dependent: :destroy
@@ -31,15 +34,20 @@ class User < ApplicationRecord
31
34
  self.verified = false
32
35
  end
33
36
  <%- if two_factor? %>
34
- before_create do
37
+ before_validation on: :create do
35
38
  self.otp_secret = ROTP::Base32.random
36
39
  end
37
40
  <%- end -%>
38
41
  <%- if webauthn? %>
39
- before_create do
42
+ before_validation on: :create do
40
43
  self.webauthn_id = WebAuthn.generate_user_id
41
44
  end
42
45
  <%- end -%>
46
+ <%- if options.tenantable? %>
47
+ before_validation on: :create do
48
+ self.account = Account.new
49
+ end
50
+ <%- end -%>
43
51
 
44
52
  after_update if: :password_digest_previously_changed? do
45
53
  sessions.where.not(id: Current.session).delete_all
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authentication-zero
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.16.32
4
+ version: 2.16.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nixon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-02 00:00:00.000000000 Z
11
+ date: 2023-07-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: